Migrate to gradle, fix examples (#769)

This commit is contained in:
Alex 2023-12-19 19:01:53 +01:00 committed by GitHub
parent 2a76b379ce
commit ff317f1a9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 640 additions and 373 deletions

32
.github/workflows/build.yml vendored Normal file
View file

@ -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

View file

@ -15,6 +15,10 @@ jobs:
# See https://github.com/actions/checkout/commits # See https://github.com/actions/checkout/commits
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac 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 - name: Set up JDK 17
# See https://github.com/actions/setup-java/commits # See https://github.com/actions/setup-java/commits
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
@ -22,13 +26,11 @@ jobs:
java-version: 17 java-version: 17
distribution: temurin distribution: temurin
- uses: s4u/maven-settings-action@60912582505985be4cc55d2b890eb32767f8de5f - name: Publish to Maven Repository
# See https://github.com/s4u/maven-settings-action/commits if: ${{ success() && github.repository == 'GeyserMC/MCProtocolLib' && github.ref_name == 'master' }}
with: uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232
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
env: env:
MAVEN_USERNAME: ${{ vars.DEPLOY_USER }} OPENCOLLAB_USERNAME: ${{ vars.DEPLOY_USER }}
MAVEN_PASSWORD: ${{ secrets.DEPLOY_PASS }} OPENCOLLAB_PASSWORD: ${{ secrets.DEPLOY_PASS }}
with:
arguments: publish

View file

@ -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

34
.gitignore vendored
View file

@ -1,13 +1,31 @@
bin # Compiled plugin files
lib target/
target
testing
.settings # IDE files
.idea/
.vscode/*
.settings/*
*.iml
*.iws
*.ipr
.classpath .classpath
.project .project
.directory .factorypath
*.iml # UML
.idea *.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

7
Jenkinsfile vendored
View file

@ -1,7 +1,6 @@
pipeline { pipeline {
agent any agent any
tools { tools {
maven 'Maven 3'
jdk 'Java 17' jdk 'Java 17'
} }
options { options {
@ -10,7 +9,7 @@ pipeline {
stages { stages {
stage ('Build') { stage ('Build') {
steps { steps {
sh 'mvn clean package' sh './gradlew clean build'
} }
} }
@ -20,8 +19,8 @@ pipeline {
} }
steps { steps {
sh 'mvn javadoc:javadoc' sh './gradlew javadoc'
step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false]) step([$class: 'JavadocArchiver', javadocDir: 'build/docs/javadoc', keepAll: false])
} }
} }
} }

View file

@ -45,6 +45,10 @@ dependencies {
To use snapshot builds, switch the URL to `https://repo.opencollab.dev/maven-snapshots/`. 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 ## Building the Source
MCProtocolLib uses Maven to manage dependencies. To build the source code, run `mvn clean install` in the project root directory. MCProtocolLib uses Maven to manage dependencies. To build the source code, run `mvn clean install` in the project root directory.

112
build.gradle.kts Normal file
View file

@ -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<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:all,-processing")
}
tasks.withType<Javadoc> {
title = "MCProtocolLib Javadocs"
val options = options as StandardJavadocDocletOptions
options.encoding = "UTF-8"
options.addStringOption("Xdoclint:all,-missing", "-quiet")
}

11
example/build.gradle.kts Normal file
View file

@ -0,0 +1,11 @@
plugins {
java
}
dependencies {
implementation(rootProject)
}
tasks.javadoc {
onlyIf { false }
}

View file

@ -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.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket; 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.ProxyInfo;
import com.github.steveice10.packetlib.Server; import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session; 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.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration; 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.net.Proxy;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.zip.GZIPInputStream;
public class MinecraftProtocolTest { public class MinecraftProtocolTest {
private static final boolean SPAWN_SERVER = true; private static final boolean SPAWN_SERVER = true;

View file

@ -2,13 +2,12 @@ package com.github.steveice10.packetlib.test;
import com.github.steveice10.packetlib.codec.PacketCodecHelper; import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class PingPacket implements Packet { public class PingPacket implements Packet {
private final String id; private final String id;
public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException { public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) {
this.id = codecHelper.readString(buf); this.id = codecHelper.readString(buf);
} }
@ -19,14 +18,4 @@ public class PingPacket implements Packet {
public String getPingId() { public String getPingId() {
return this.id; return this.id;
} }
@Override
public void write(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
codecHelper.writeString(buf, this.id);
}
@Override
public boolean isPriority() {
return false;
}
} }

View file

@ -10,7 +10,7 @@ import com.github.steveice10.packetlib.event.server.SessionRemovedEvent;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
public class ServerListener extends ServerAdapter { public class ServerListener extends ServerAdapter {
private SecretKey key; private final SecretKey key;
public ServerListener(SecretKey key) { public ServerListener(SecretKey key) {
this.key = key; this.key = key;

View file

@ -2,11 +2,16 @@ package com.github.steveice10.packetlib.test;
import com.github.steveice10.packetlib.Server; import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session; 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.AESEncryption;
import com.github.steveice10.packetlib.crypt.PacketEncryption; import com.github.steveice10.packetlib.crypt.PacketEncryption;
import com.github.steveice10.packetlib.packet.DefaultPacketHeader; import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
import com.github.steveice10.packetlib.packet.PacketHeader; import com.github.steveice10.packetlib.packet.PacketHeader;
import com.github.steveice10.packetlib.packet.PacketProtocol; import com.github.steveice10.packetlib.packet.PacketProtocol;
import io.netty.buffer.ByteBuf;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@ -28,10 +33,21 @@ public class TestProtocol extends PacketProtocol {
} }
public void setSecretKey(SecretKey key) { 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<PingPacket, PacketCodecHelper> definition) {
return new PingPacket(buf, helper);
}
});
try { try {
this.encrypt = new AESEncryption(key); this.encrypt = new AESEncryption(key);
} catch(GeneralSecurityException e) { } catch (GeneralSecurityException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

48
gradle/libs.versions.toml Normal file
View file

@ -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"]

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -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

248
gradlew vendored Executable file
View file

@ -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" "$@"

92
gradlew.bat vendored Normal file
View file

@ -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

274
pom.xml
View file

@ -1,274 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>1.20.4-2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MCProtocolLib</name>
<description>MCProtocolLib is a simple library for communicating with Minecraft clients and servers.</description>
<url>https://github.com/GeyserMC/MCProtocolLib/</url>
<scm>
<connection>scm:git:git@github.com:GeyserMC/MCProtocolLib.git</connection>
<developerConnection>scm:git:git@github.com:GeyserMC/MCProtocolLib.git</developerConnection>
<url>git@github.com:GeyserMC/MCProtocolLib/</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<adventure.version>4.15.0-20231207.074016-23</adventure.version>
<!-- fixme: update to 4.15.0 when it releases -->
</properties>
<licenses>
<license>
<name>MIT</name>
<url>https://opensource.org/license/mit/</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>steveice10</id>
<name>Steveice10</name>
<email>Steveice10@gmail.com</email>
</developer>
<developer>
<id>GeyserMC</id>
<name>GeyserMC</name>
<url>https://geysermc.org/</url>
<organization>GeyserMC</organization>
<organizationUrl>https://github.com/GeyserMC</organizationUrl>
</developer>
</developers>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/GeyserMC/MCProtocolLib/issues</url>
</issueManagement>
<repositories>
<repository>
<id>opencollab-release-repo</id>
<url>https://repo.opencollab.dev/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>opencollab-snapshot-repo</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<!-- fixme: remove when adventure 4.15.0 releases -->
<id>sonatype-oss-snapshots1</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!-- Minecraft related libraries -->
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>opennbt</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.GeyserMC</groupId>
<artifactId>mcauthlib</artifactId>
<version>6621fd081c</version>
<scope>compile</scope>
</dependency>
<!-- Kyori adventure -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>${adventure.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-json-legacy-impl</artifactId>
<version>${adventure.version}</version>
<scope>compile</scope>
</dependency>
<!-- Lombok and annotations -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.7.3</version>
<scope>provided</scope>
</dependency>
<!-- Math utilities -->
<dependency>
<groupId>org.cloudburstmc.math</groupId>
<artifactId>api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.cloudburstmc.math</groupId>
<artifactId>immutable</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<!-- Stripped down fastutil -->
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-object-int-maps</artifactId>
<version>8.5.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-int-object-maps</artifactId>
<version>8.5.3</version>
<scope>compile</scope>
</dependency>
<!-- Netty -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.99.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-haproxy</artifactId>
<version>4.1.99.Final</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.netty.incubator</groupId>
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
<version>0.0.23.Final</version>
<classifier>linux-x86_64</classifier>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>aggregate</goal>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<show>public</show>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<distributionManagement>
<repository>
<id>opencollab-release-repo</id>
<url>https://repo.opencollab.dev/maven-releases/</url>
</repository>
<snapshotRepository>
<id>opencollab-snapshot-repo</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
</project>

22
settings.gradle.kts Normal file
View file

@ -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")

View file

@ -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() + ".");
}
}

View file

@ -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() + ".");
}
}

View file

@ -1,7 +1,5 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value; package com.github.steveice10.mc.protocol.data.game.level.block.value;
import com.github.steveice10.mc.protocol.data.UnmappedValueException;
public enum BellValueType implements BlockValueType { public enum BellValueType implements BlockValueType {
SHAKE_DIRECTION; SHAKE_DIRECTION;

View file

@ -11,7 +11,6 @@ import lombok.NonNull;
import lombok.With; import lombok.With;
import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.math.vector.Vector3i;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
@Data @Data
@ -20,7 +19,7 @@ import java.io.IOException;
public class ClientboundLevelEventPacket implements MinecraftPacket { public class ClientboundLevelEventPacket implements MinecraftPacket {
private final @NonNull LevelEvent event; private final @NonNull LevelEvent event;
private final @NonNull Vector3i position; private final @NonNull Vector3i position;
private final @Nonnull LevelEventData data; private final @NonNull LevelEventData data;
private final boolean broadcast; private final boolean broadcast;
public ClientboundLevelEventPacket(@NonNull LevelEvent event, @NonNull Vector3i position, @NonNull LevelEventData data) { public ClientboundLevelEventPacket(@NonNull LevelEvent event, @NonNull Vector3i position, @NonNull LevelEventData data) {

View file

@ -9,8 +9,8 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.*; import lombok.*;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;

View file

@ -17,8 +17,8 @@ import io.netty.handler.timeout.WriteTimeoutException;
import io.netty.handler.timeout.WriteTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.Collections; import java.util.Collections;