diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..a22d1715 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Java CI with Gradle + +on: [push, pull_request] + +jobs: + build: + # Only run on PRs if the source branch is on someone else's repo + if: "${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}" + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + # See https://github.com/actions/checkout/commits + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac + + - name: Validate Gradle wrapper + # See https://github.com/gradle/wrapper-validation-action/commits + uses: gradle/wrapper-validation-action@342dbebe7272035434f9baccc29a816ec6dd2c7b + + - name: Set up JDK 17 + # See https://github.com/actions/setup-java/commits + uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 + with: + java-version: 17 + distribution: temurin + + - name: Build + # See https://github.com/gradle/gradle-build-action/commits + uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232 + with: + arguments: build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6edcee22..222183f5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,6 +15,10 @@ jobs: # See https://github.com/actions/checkout/commits uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac + - name: Validate Gradle wrapper + # See https://github.com/gradle/wrapper-validation-action/commits + uses: gradle/wrapper-validation-action@342dbebe7272035434f9baccc29a816ec6dd2c7b + - name: Set up JDK 17 # See https://github.com/actions/setup-java/commits uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 @@ -22,13 +26,11 @@ jobs: java-version: 17 distribution: temurin - - uses: s4u/maven-settings-action@60912582505985be4cc55d2b890eb32767f8de5f - # See https://github.com/s4u/maven-settings-action/commits - with: - servers: '[{"id": "opencollab-release-repo", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}"},{"id": "opencollab-snapshot-repo", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}"}]' - - - name: Deploy with Maven - run: mvn deploy -B -P deploy + - name: Publish to Maven Repository + if: ${{ success() && github.repository == 'GeyserMC/MCProtocolLib' && github.ref_name == 'master' }} + uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232 env: - MAVEN_USERNAME: ${{ vars.DEPLOY_USER }} - MAVEN_PASSWORD: ${{ secrets.DEPLOY_PASS }} + OPENCOLLAB_USERNAME: ${{ vars.DEPLOY_USER }} + OPENCOLLAB_PASSWORD: ${{ secrets.DEPLOY_PASS }} + with: + arguments: publish diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 41cc6fd9..00000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Java CI - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - # See https://github.com/actions/checkout/commits - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac - - - name: Set up JDK 17 - # See https://github.com/actions/setup-java/commits - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 - with: - java-version: 17 - distribution: temurin - - - name: Build with Maven - run: mvn package -B diff --git a/.gitignore b/.gitignore index 91cac5b1..256dd51d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,31 @@ -bin -lib -target -testing +# Compiled plugin files +target/ -.settings +# IDE files +.idea/ +.vscode/* +.settings/* +*.iml +*.iws +*.ipr .classpath .project -.directory +.factorypath -*.iml -.idea +# UML +*.plantuml +# Gradle +.gradle +**/build/ +!src/**/build/ +**/run/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache diff --git a/Jenkinsfile b/Jenkinsfile index 9dafd163..78f18818 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,6 @@ pipeline { agent any tools { - maven 'Maven 3' jdk 'Java 17' } options { @@ -10,7 +9,7 @@ pipeline { stages { stage ('Build') { steps { - sh 'mvn clean package' + sh './gradlew clean build' } } @@ -20,8 +19,8 @@ pipeline { } steps { - sh 'mvn javadoc:javadoc' - step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false]) + sh './gradlew javadoc' + step([$class: 'JavadocArchiver', javadocDir: 'build/docs/javadoc', keepAll: false]) } } } diff --git a/README.md b/README.md index 4f34fde2..d130e395 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ dependencies { To use snapshot builds, switch the URL to `https://repo.opencollab.dev/maven-snapshots/`. +### Javadocs + +You can find the Javadocs for MCProtocolLib [on opencollab](https://ci.opencollab.dev/job/GeyserMC/job/MCProtocolLib/job/master/javadoc/overview-summary.html). + ## Building the Source MCProtocolLib uses Maven to manage dependencies. To build the source code, run `mvn clean install` in the project root directory. diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..56e2308b --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,112 @@ +plugins { + idea + `java-library` + `maven-publish` + alias(libs.plugins.indra) + alias(libs.plugins.indra.git) + alias(libs.plugins.indra.publishing) + alias(libs.plugins.lombok) +} + +indra { + github("GeyserMC", "MCProtocolLib") + + mitLicense() + publishReleasesTo("opencollab-release-repo", "https://repo.opencollab.dev/maven-releases/") + publishSnapshotsTo("opencollab-snapshot-repo", "https://repo.opencollab.dev/maven-snapshots/") + + configurePublications { + pom { + name = "MCProtocolLib" + url = "https://github.com/GeyserMC/MCProtocolLib/" + organization { + name = "GeyserMC" + url = "https://github.com/GeyserMC" + } + developers { + developer { + id = "steveice10" + name = "Steveice10" + email = "Steveice10@gmail.com" + } + developer { + id = "GeyserMC" + name = "GeyserMC" + url = "https://geysermc.org/" + } + } + } + + versionMapping { + usage(Usage.JAVA_API) { fromResolutionOf(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) } + usage(Usage.JAVA_RUNTIME) { fromResolutionResult() } + } + } + + javaVersions { + target(17) + strictVersions() + testWith(17) + minimumToolchain(17) + } +} + +val repoName = if (version.toString().endsWith("SNAPSHOT")) "maven-snapshots" else "maven-releases" +publishing { + repositories { + maven("https://repo.opencollab.dev/${repoName}/") { + credentials.username = System.getenv("OPENCOLLAB_USERNAME") + credentials.password = System.getenv("OPENCOLLAB_PASSWORD") + name = "opencollab" + } + } +} + +dependencies { + // Minecraft related libraries + api(libs.opennbt) + api(libs.mcauthlib) + + // Kyori adventure + api(libs.bundles.adventure) + + // Math utilities + api(libs.bundles.math) + + // Stripped down fastutil + api(libs.bundles.fastutil) + + // Netty + api(libs.bundles.netty) + + // Test dependencies + testImplementation(libs.junit.jupiter) +} + +lombok { + version = libs.versions.lombok.version.get() +} + +group = "com.github.steveice10" +version = "1.20.4-2-SNAPSHOT" +description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers." + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + withSourcesJar() + withJavadocJar() +} + +tasks.withType { + options.encoding = "UTF-8" + options.compilerArgs.add("-Xlint:all,-processing") +} + +tasks.withType { + title = "MCProtocolLib Javadocs" + val options = options as StandardJavadocDocletOptions + options.encoding = "UTF-8" + options.addStringOption("Xdoclint:all,-missing", "-quiet") +} + diff --git a/example/build.gradle.kts b/example/build.gradle.kts new file mode 100644 index 00000000..9af6c3cc --- /dev/null +++ b/example/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + java +} + +dependencies { + implementation(rootProject) +} + +tasks.javadoc { + onlyIf { false } +} diff --git a/example/src/main/java/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java b/example/src/main/java/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java index a28c03b4..df06fffa 100644 --- a/example/src/main/java/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java +++ b/example/src/main/java/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java @@ -21,8 +21,6 @@ import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandl import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket; -import com.github.steveice10.opennbt.NBTIO; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.packetlib.ProxyInfo; import com.github.steveice10.packetlib.Server; import com.github.steveice10.packetlib.Session; @@ -39,16 +37,11 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; import java.net.Proxy; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; -import java.util.zip.GZIPInputStream; public class MinecraftProtocolTest { private static final boolean SPAWN_SERVER = true; diff --git a/example/com/github/steveice10/packetlib/test/ClientSessionListener.java b/example/src/main/java/com/github/steveice10/packetlib/test/ClientSessionListener.java similarity index 100% rename from example/com/github/steveice10/packetlib/test/ClientSessionListener.java rename to example/src/main/java/com/github/steveice10/packetlib/test/ClientSessionListener.java diff --git a/example/com/github/steveice10/packetlib/test/PingPacket.java b/example/src/main/java/com/github/steveice10/packetlib/test/PingPacket.java similarity index 63% rename from example/com/github/steveice10/packetlib/test/PingPacket.java rename to example/src/main/java/com/github/steveice10/packetlib/test/PingPacket.java index 6c0d7e16..a91e5a75 100644 --- a/example/com/github/steveice10/packetlib/test/PingPacket.java +++ b/example/src/main/java/com/github/steveice10/packetlib/test/PingPacket.java @@ -2,13 +2,12 @@ package com.github.steveice10.packetlib.test; import com.github.steveice10.packetlib.codec.PacketCodecHelper; import com.github.steveice10.packetlib.packet.Packet; - -import java.io.IOException; +import io.netty.buffer.ByteBuf; public class PingPacket implements Packet { private final String id; - public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException { + public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) { this.id = codecHelper.readString(buf); } @@ -19,14 +18,4 @@ public class PingPacket implements Packet { public String getPingId() { return this.id; } - - @Override - public void write(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException { - codecHelper.writeString(buf, this.id); - } - - @Override - public boolean isPriority() { - return false; - } } diff --git a/example/com/github/steveice10/packetlib/test/PingServerTest.java b/example/src/main/java/com/github/steveice10/packetlib/test/PingServerTest.java similarity index 100% rename from example/com/github/steveice10/packetlib/test/PingServerTest.java rename to example/src/main/java/com/github/steveice10/packetlib/test/PingServerTest.java diff --git a/example/com/github/steveice10/packetlib/test/ServerListener.java b/example/src/main/java/com/github/steveice10/packetlib/test/ServerListener.java similarity index 98% rename from example/com/github/steveice10/packetlib/test/ServerListener.java rename to example/src/main/java/com/github/steveice10/packetlib/test/ServerListener.java index 34911bfc..afd39752 100644 --- a/example/com/github/steveice10/packetlib/test/ServerListener.java +++ b/example/src/main/java/com/github/steveice10/packetlib/test/ServerListener.java @@ -10,7 +10,7 @@ import com.github.steveice10.packetlib.event.server.SessionRemovedEvent; import javax.crypto.SecretKey; public class ServerListener extends ServerAdapter { - private SecretKey key; + private final SecretKey key; public ServerListener(SecretKey key) { this.key = key; diff --git a/example/com/github/steveice10/packetlib/test/ServerSessionListener.java b/example/src/main/java/com/github/steveice10/packetlib/test/ServerSessionListener.java similarity index 100% rename from example/com/github/steveice10/packetlib/test/ServerSessionListener.java rename to example/src/main/java/com/github/steveice10/packetlib/test/ServerSessionListener.java diff --git a/example/com/github/steveice10/packetlib/test/TestProtocol.java b/example/src/main/java/com/github/steveice10/packetlib/test/TestProtocol.java similarity index 65% rename from example/com/github/steveice10/packetlib/test/TestProtocol.java rename to example/src/main/java/com/github/steveice10/packetlib/test/TestProtocol.java index ff7e8cbb..e59fae53 100644 --- a/example/com/github/steveice10/packetlib/test/TestProtocol.java +++ b/example/src/main/java/com/github/steveice10/packetlib/test/TestProtocol.java @@ -2,11 +2,16 @@ package com.github.steveice10.packetlib.test; import com.github.steveice10.packetlib.Server; import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.codec.BasePacketCodecHelper; +import com.github.steveice10.packetlib.codec.PacketCodecHelper; +import com.github.steveice10.packetlib.codec.PacketDefinition; +import com.github.steveice10.packetlib.codec.PacketSerializer; import com.github.steveice10.packetlib.crypt.AESEncryption; import com.github.steveice10.packetlib.crypt.PacketEncryption; import com.github.steveice10.packetlib.packet.DefaultPacketHeader; import com.github.steveice10.packetlib.packet.PacketHeader; import com.github.steveice10.packetlib.packet.PacketProtocol; +import io.netty.buffer.ByteBuf; import javax.crypto.SecretKey; import java.security.GeneralSecurityException; @@ -28,10 +33,21 @@ public class TestProtocol extends PacketProtocol { } public void setSecretKey(SecretKey key) { - this.register(0, PingPacket.class, PingPacket::new); + this.register(0, PingPacket.class, new PacketSerializer<>() { + @Override + public void serialize(ByteBuf buf, PacketCodecHelper helper, PingPacket packet) { + helper.writeString(buf, packet.getPingId()); + } + + @Override + public PingPacket deserialize(ByteBuf buf, PacketCodecHelper helper, PacketDefinition definition) { + return new PingPacket(buf, helper); + } + }); + try { this.encrypt = new AESEncryption(key); - } catch(GeneralSecurityException e) { + } catch (GeneralSecurityException e) { e.printStackTrace(); } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..eb37d097 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,48 @@ +metadata.format.version = "1.1" + +[versions] + +indra = "3.1.3" +lombok-version = "1.18.30" +lombok-plugin = "8.4" +adventure = "4.15.0" +opennbt = "1.6" +mcauthlib = "6621fd0" +math = "2.0" +fastutil-maps = "8.5.3" +netty = "4.1.103.Final" +netty-io_uring = "0.0.24.Final" +junit = "5.8.2" + +[libraries] + +adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure" } +adventure-text-serializer-json-legacy-impl = { module = "net.kyori:adventure-text-serializer-json-legacy-impl", version.ref = "adventure" } + +opennbt = { module = "com.github.steveice10:opennbt", version.ref = "opennbt" } +mcauthlib = { module = "com.github.GeyserMC:mcauthlib", version.ref = "mcauthlib" } + +math-api = { module = "org.cloudburstmc.math:api", version.ref = "math" } +math-immutable = { module = "org.cloudburstmc.math:immutable", version.ref = "math" } + +fastutil-object2int-maps = { module = "com.nukkitx.fastutil:fastutil-object-int-maps", version.ref = "fastutil-maps" } +fastutil-int2object-maps = { module = "com.nukkitx.fastutil:fastutil-int-object-maps", version.ref = "fastutil-maps" } + +netty-all = { module = "io.netty:netty-all", version.ref = "netty" } +netty-incubator-transport-native-io_uring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version.ref = "netty-io_uring" } + +junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } + +[plugins] + +indra = { id = "net.kyori.indra", version.ref = "indra" } +indra-git = { id = "net.kyori.indra.git", version.ref = "indra" } +indra-publishing = { id = "net.kyori.indra.publishing", version.ref = "indra" } +lombok = { id = "io.freefair.lombok", version.ref = "lombok-plugin" } + +[bundles] + +adventure = ["adventure-text-serializer-gson", "adventure-text-serializer-json-legacy-impl"] +math = ["math-api", "math-immutable"] +fastutil = ["fastutil-object2int-maps", "fastutil-int2object-maps"] +netty = ["netty-all", "netty-incubator-transport-native-io_uring"] diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..033e24c4 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..1af9e093 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..fcb6fca1 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..6689b85b --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 53503528..00000000 --- a/pom.xml +++ /dev/null @@ -1,274 +0,0 @@ - - - 4.0.0 - - com.github.steveice10 - mcprotocollib - 1.20.4-2-SNAPSHOT - jar - - MCProtocolLib - MCProtocolLib is a simple library for communicating with Minecraft clients and servers. - https://github.com/GeyserMC/MCProtocolLib/ - - - scm:git:git@github.com:GeyserMC/MCProtocolLib.git - scm:git:git@github.com:GeyserMC/MCProtocolLib.git - git@github.com:GeyserMC/MCProtocolLib/ - - - - UTF-8 - 17 - 17 - 4.15.0-20231207.074016-23 - - - - - - MIT - https://opensource.org/license/mit/ - repo - - - - - - steveice10 - Steveice10 - Steveice10@gmail.com - - - GeyserMC - GeyserMC - https://geysermc.org/ - GeyserMC - https://github.com/GeyserMC - - - - - GitHub - https://github.com/GeyserMC/MCProtocolLib/issues - - - - - opencollab-release-repo - https://repo.opencollab.dev/maven-releases/ - - true - - - false - - - - opencollab-snapshot-repo - https://repo.opencollab.dev/maven-snapshots/ - - false - - - true - - - - jitpack.io - https://jitpack.io - - - - sonatype-oss-snapshots1 - https://s01.oss.sonatype.org/content/repositories/snapshots/ - - - - - - - com.github.steveice10 - opennbt - 1.6 - compile - - - com.github.GeyserMC - mcauthlib - 6621fd081c - compile - - - - net.kyori - adventure-text-serializer-gson - ${adventure.version} - compile - - - net.kyori - adventure-text-serializer-json-legacy-impl - ${adventure.version} - compile - - - - org.projectlombok - lombok - 1.18.30 - provided - - - com.github.spotbugs - spotbugs-annotations - 4.7.3 - provided - - - - org.cloudburstmc.math - api - 2.0 - compile - - - org.cloudburstmc.math - immutable - 2.0 - compile - - - - com.nukkitx.fastutil - fastutil-object-int-maps - 8.5.3 - compile - - - com.nukkitx.fastutil - fastutil-int-object-maps - 8.5.3 - compile - - - - io.netty - netty-all - 4.1.99.Final - compile - - - io.netty - netty-codec-haproxy - 4.1.99.Final - compile - true - - - io.netty.incubator - netty-incubator-transport-native-io_uring - 0.0.23.Final - linux-x86_64 - - - - org.junit.jupiter - junit-jupiter - 5.8.2 - test - - - - - clean install - - - org.apache.maven.plugins - maven-clean-plugin - 3.3.1 - - - org.apache.maven.plugins - maven-resources-plugin - 3.3.1 - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.6.0 - - - attach-javadocs - - aggregate - jar - - - - - public - false - - - - org.apache.maven.plugins - maven-source-plugin - 3.3.0 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-install-plugin - 3.1.1 - - - org.apache.maven.plugins - maven-deploy-plugin - 3.1.1 - - - - - - - deploy - - true - - - - opencollab-release-repo - https://repo.opencollab.dev/maven-releases/ - - - opencollab-snapshot-repo - https://repo.opencollab.dev/maven-snapshots/ - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..4bf6ec6a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,22 @@ +dependencyResolutionManagement { + repositories { + maven("https://repo.opencollab.dev/maven-releases/") { + name = "opencollab-releases" + } + maven("https://repo.opencollab.dev/maven-snapshots/") { + name = "opencollab-snapshots" + } + // fixme: remove when adventure 4.15.0 releases + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") { + name = "sonatype-snapshots" + } + maven("https://jitpack.io") { + name = "jitpack" + } + mavenCentral() + } +} + +rootProject.name = "mcprotocollib" + +include("example") diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedKeyException.java b/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedKeyException.java deleted file mode 100644 index 5e0c420c..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedKeyException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.steveice10.mc.protocol.data; - -import lombok.Getter; - -@Getter -public class UnmappedKeyException extends IllegalArgumentException { - private Enum key; - private Class valueType; - - public UnmappedKeyException(Object key, Class valueType) { - super("Key " + key + " has no mapping for value class " + valueType.getName() + "."); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedValueException.java b/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedValueException.java deleted file mode 100644 index e4bb5dbe..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/UnmappedValueException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.steveice10.mc.protocol.data; - -import lombok.Getter; - -@Getter -public class UnmappedValueException extends IllegalArgumentException { - private Object value; - private Class keyType; - - public UnmappedValueException(Object value, Class keyType) { - super("Value " + value + " has no mapping for key class " + keyType.getName() + "."); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/block/value/BellValueType.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/block/value/BellValueType.java index c02b03b5..a425c7e7 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/block/value/BellValueType.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/block/value/BellValueType.java @@ -1,7 +1,5 @@ package com.github.steveice10.mc.protocol.data.game.level.block.value; -import com.github.steveice10.mc.protocol.data.UnmappedValueException; - public enum BellValueType implements BlockValueType { SHAKE_DIRECTION; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundLevelEventPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundLevelEventPacket.java index 7ca407bf..1983566f 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundLevelEventPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundLevelEventPacket.java @@ -11,7 +11,6 @@ import lombok.NonNull; import lombok.With; import org.cloudburstmc.math.vector.Vector3i; -import javax.annotation.Nonnull; import java.io.IOException; @Data @@ -20,7 +19,7 @@ import java.io.IOException; public class ClientboundLevelEventPacket implements MinecraftPacket { private final @NonNull LevelEvent event; private final @NonNull Vector3i position; - private final @Nonnull LevelEventData data; + private final @NonNull LevelEventData data; private final boolean broadcast; public ClientboundLevelEventPacket(@NonNull LevelEvent event, @NonNull Vector3i position, @NonNull LevelEventData data) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java index a9cc1198..bee4c378 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java @@ -9,8 +9,8 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import io.netty.buffer.ByteBuf; import lombok.*; import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.io.IOException; import java.util.Arrays; diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java index 9a4672ec..a15d370e 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java @@ -17,8 +17,8 @@ import io.netty.handler.timeout.WriteTimeoutException; import io.netty.handler.timeout.WriteTimeoutHandler; import io.netty.util.concurrent.DefaultThreadFactory; import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.net.ConnectException; import java.net.SocketAddress; import java.util.Collections;