Merge pull request #31 from BBaoVanC/update-gradle

Update Gradle version to latest (7.4.2)
This commit is contained in:
Max 2022-07-07 04:09:34 -05:00 committed by GitHub
commit 59d264d9b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 4962 additions and 273 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
ko_fi: nanit

View File

@ -32,13 +32,19 @@ Symbol `X` means all minor versions.
- [x] 1.15.X
- [x] 1.16.X
- [x] 1.17.X
- [x] 1.18
- [x] 1.18.X
- [x] 1.19
The server **doesn't** support snapshots.
### Commands
There are no commands. To close server just run `Ctrl+C` in the terminal. It will be closed correctly.
* `help` - Show help message
* `conn` - Display amount of connections
* `mem` - Display memory usage stats
* `stop` - Stop the server
Note, that it also will be closed correctly if you just press `Ctrl+C`.
### Installation

View File

@ -4,7 +4,16 @@ plugins {
}
group 'ru.nanit'
version '1.3.4'
version '1.4'
compileJava {
options.encoding = "UTF-8"
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
@ -15,8 +24,8 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'org.spongepowered:configurate-yaml:4.1.2'
implementation 'io.netty:netty-all:4.1.73.Final'
implementation 'net.kyori:adventure-nbt:4.9.2'
implementation 'io.netty:netty-all:4.1.77.Final'
implementation 'net.kyori:adventure-nbt:4.10.1'
implementation 'com.grack:nanojson:1.7'
}

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

269
gradlew vendored Normal file → Executable file
View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh
#!/bin/sh
#
# Copyright 2015 the original author or authors.
# 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.
@ -17,67 +17,101 @@
#
##############################################################################
##
## Gradle start up script for UN*X
##
#
# 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/master/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
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
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
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
APP_BASE_NAME=${0##*/}
# 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"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
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
;;
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
@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
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"
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD="$JAVA_HOME/bin/java"
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
JAVACMD=java
which java >/dev/null 2>&1 || 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
@ -106,80 +140,95 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# 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.
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# 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
# 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 \
"$@"
# 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" "$@"

View File

@ -87,6 +87,12 @@ public final class LimboConfig {
maxPlayers = conf.node("maxPlayers").getInt();
pingData = conf.node("ping").get(PingData.class);
dimensionType = conf.node("dimension").getString();
if (dimensionType.equalsIgnoreCase("nether")) {
dimensionType = "the_nether";
}
if (dimensionType.equalsIgnoreCase("end")) {
dimensionType = "the_end";
}
spawnPosition = conf.node("spawnPosition").get(Location.class);
gameMode = conf.node("gameMode").getInt();
useBrandName = conf.node("brandName", "enable").getBoolean();

View File

@ -25,6 +25,7 @@ import ru.nanit.limbo.protocol.packets.login.PacketLoginPluginResponse;
import ru.nanit.limbo.protocol.packets.login.PacketLoginStart;
import ru.nanit.limbo.protocol.packets.status.PacketStatusPing;
import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.Logger;
import ru.nanit.limbo.util.UuidUtil;
@ -63,7 +64,7 @@ public class PacketHandler {
}
public void handle(ClientConnection conn, PacketStatusRequest packet) {
conn.sendPacket(PacketSnapshots.PACKET_STATUS_RESPONSE);
conn.sendPacket(new PacketStatusResponse(server));
}
public void handle(ClientConnection conn, PacketStatusPing packet) {

View File

@ -21,7 +21,6 @@ import ru.nanit.limbo.LimboConstants;
import ru.nanit.limbo.protocol.PacketSnapshot;
import ru.nanit.limbo.protocol.packets.login.PacketLoginSuccess;
import ru.nanit.limbo.protocol.packets.play.*;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.data.Title;
import ru.nanit.limbo.util.UuidUtil;
@ -32,7 +31,6 @@ import java.util.concurrent.ThreadLocalRandom;
public final class PacketSnapshots {
public static PacketSnapshot PACKET_STATUS_RESPONSE;
public static PacketSnapshot PACKET_LOGIN_SUCCESS;
public static PacketSnapshot PACKET_JOIN_GAME;
public static PacketSnapshot PACKET_PLUGIN_MESSAGE;
@ -52,6 +50,7 @@ public final class PacketSnapshots {
public static PacketSnapshot PACKET_TITLE_LEGACY_SUBTITLE;
public static PacketSnapshot PACKET_TITLE_LEGACY_TIMES;
private PacketSnapshots() { }
public static void initPackets(LimboServer server) {
@ -73,8 +72,9 @@ public final class PacketSnapshots {
joinGame.setReducedDebugInfo(true);
joinGame.setDebug(false);
joinGame.setViewDistance(0);
joinGame.setWorldName("minecraft:world");
joinGame.setWorldNames("minecraft:world");
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setWorldName(worldName);
joinGame.setWorldNames(worldName);
joinGame.setHashedSeed(0);
joinGame.setDimensionRegistry(server.getDimensionRegistry());
@ -99,7 +99,6 @@ public final class PacketSnapshots {
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);
PACKET_STATUS_RESPONSE = PacketSnapshot.of(new PacketStatusResponse(server));
PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess);
PACKET_JOIN_GAME = PacketSnapshot.of(joinGame);
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
@ -125,7 +124,7 @@ public final class PacketSnapshots {
if (server.getConfig().isUseJoinMessage()) {
PacketChatMessage joinMessage = new PacketChatMessage();
joinMessage.setJsonData(server.getConfig().getJoinMessage());
joinMessage.setPosition(PacketChatMessage.Position.CHAT);
joinMessage.setPosition(PacketChatMessage.PositionLegacy.SYSTEM_MESSAGE);
joinMessage.setSender(UUID.randomUUID());
PACKET_JOIN_MESSAGE = PacketSnapshot.of(joinMessage);
}

View File

@ -47,7 +47,7 @@ public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {
Packet packet = mappings.getPacket(packetId);
if (packet != null) {
Logger.debug("Received packet %s", packet.toString());
Logger.debug("Received packet %s[0x%s]", packet.toString(), Integer.toHexString(packetId));
try {
packet.decode(msg, version);
} catch (Exception e) {

View File

@ -51,7 +51,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
}
if (packetId == -1) {
Logger.warning("Undefined packet class: %s", packet.getClass().getName());
Logger.warning("Undefined packet class: %s[0x%s]", packet.getClass().getName(), Integer.toHexString(packetId));
return;
}
@ -60,8 +60,8 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
try {
packet.encode(msg, version);
if (Logger.getLevel() >= 3) {
Logger.debug("Sending %s packet (%d bytes)", packet.toString(), msg.readableBytes());
if (Logger.getLevel() >= Logger.Level.DEBUG.getIndex()) {
Logger.debug("Sending %s[0x%s] packet (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
}
} catch (Exception e) {
Logger.error("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());

View File

@ -166,7 +166,8 @@ public class ByteMessage extends ByteBuf {
for (CompoundBinaryTag tag : compoundTags) {
BinaryTagIO.writer().write(tag, (OutputStream) stream);
}
} catch (IOException e) {
}
catch (IOException e) {
throw new EncoderException("Cannot write NBT CompoundTag");
}
}
@ -174,7 +175,8 @@ public class ByteMessage extends ByteBuf {
public CompoundBinaryTag readCompoundTag() {
try (ByteBufInputStream stream = new ByteBufInputStream(buf)) {
return BinaryTagIO.reader().read((InputStream) stream);
} catch (IOException thrown) {
}
catch (IOException thrown) {
throw new DecoderException("Cannot read NBT CompoundTag");
}
}
@ -182,7 +184,8 @@ public class ByteMessage extends ByteBuf {
public void writeCompoundTag(CompoundBinaryTag compoundTag) {
try (ByteBufOutputStream stream = new ByteBufOutputStream(buf)) {
BinaryTagIO.writer().write(compoundTag, (OutputStream) stream);
} catch (IOException e) {
}
catch (IOException e) {
throw new EncoderException("Cannot write NBT CompoundTag");
}
}

View File

@ -23,9 +23,8 @@ import java.util.HashMap;
import java.util.Map;
/**
* PacketSnapshot encodes packet to byt array for each MC version.
* Some versions have same snapshot, so there are mappings
* to avoid storing same bytes array for different versions
* PacketSnapshot encodes packet to byte array for each MC version.
* Some versions have same snapshot, so there are mappings to avoid data copying
*/
public class PacketSnapshot implements PacketOut {

View File

@ -44,6 +44,9 @@ public class PacketLoginSuccess implements PacketOut {
msg.writeString(uuid.toString());
}
msg.writeString(username);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeVarInt(0);
}
}
@Override

View File

@ -26,14 +26,14 @@ import java.util.UUID;
public class PacketChatMessage implements PacketOut {
private String jsonData;
private Position position;
private PositionLegacy position;
private UUID sender;
public void setJsonData(String jsonData) {
this.jsonData = jsonData;
}
public void setPosition(Position position) {
public void setPosition(PositionLegacy position) {
this.position = position;
}
@ -44,13 +44,18 @@ public class PacketChatMessage implements PacketOut {
@Override
public void encode(ByteMessage msg, Version version) {
msg.writeString(jsonData);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeVarInt(position.index);
}
else {
msg.writeByte(position.index);
}
if (version.moreOrEqual(Version.V1_16))
if (version.moreOrEqual(Version.V1_16) && version.less(Version.V1_19))
msg.writeUuid(sender);
}
public enum Position {
public enum PositionLegacy {
CHAT(0),
SYSTEM_MESSAGE(1),
@ -58,7 +63,7 @@ public class PacketChatMessage implements PacketOut {
private final int index;
Position(int index) {
PositionLegacy(int index) {
this.index = index;
}

View File

@ -101,7 +101,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
msg.writeByte(gameMode);
msg.writeByte(dimensionRegistry.getDefaultDimension().getId());
msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -110,7 +110,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_9_2, Version.V1_13_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -119,7 +119,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
msg.writeVarInt(viewDistance);
@ -128,7 +128,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -142,7 +142,7 @@ public class PacketJoinGame implements PacketOut {
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getOldCodec());
msg.writeString(dimensionRegistry.getDefaultDimension().getName());
msg.writeString(dimensionRegistry.getDefaultDimension_1_16().getName());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
@ -158,8 +158,8 @@ public class PacketJoinGame implements PacketOut {
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
@ -170,13 +170,18 @@ public class PacketJoinGame implements PacketOut {
msg.writeBoolean(isFlat);
}
if (version.moreOrEqual(Version.V1_18)) {
if (version.fromTo(Version.V1_18, Version.V1_18_2)) {
msg.writeBoolean(isHardcore);
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
if (version.moreOrEqual(Version.V1_18_2)) {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_18_2());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_18_2().getData());
} else {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
}
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
@ -187,6 +192,25 @@ public class PacketJoinGame implements PacketOut {
msg.writeBoolean(isDebug);
msg.writeBoolean(isFlat);
}
if (version.moreOrEqual(Version.V1_19)) {
msg.writeBoolean(isHardcore);
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec_1_19());
msg.writeString(worldName); // World type
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
msg.writeVarInt(viewDistance);
msg.writeVarInt(viewDistance); // Simulation Distance
msg.writeBoolean(reducedDebugInfo);
msg.writeBoolean(enableRespawnScreen);
msg.writeBoolean(isDebug);
msg.writeBoolean(isFlat);
msg.writeBoolean(false);
}
}
}

View File

@ -54,6 +54,9 @@ public class PacketPlayerInfo implements PacketOut {
msg.writeVarInt(gameMode);
msg.writeVarInt(60);
msg.writeBoolean(false);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeBoolean(false);
}
}
}

View File

@ -84,7 +84,8 @@ public enum State {
map(0x0E, V1_13, V1_13_2),
map(0x0F, V1_14, V1_15_2),
map(0x10, V1_16, V1_16_4),
map(0x0F, V1_17, V1_18)
map(0x0F, V1_17, V1_18_2),
map(0x11, V1_19, V1_19)
);
clientBound.register(PacketDeclareCommands::new,
@ -92,7 +93,8 @@ public enum State {
map(0x12, V1_15, V1_15_2),
map(0x11, V1_16, V1_16_1),
map(0x10, V1_16_2, V1_16_4),
map(0x12, V1_17, V1_18)
map(0x12, V1_17, V1_18_2),
map(0x0F, V1_19, V1_19)
);
clientBound.register(PacketJoinGame::new,
map(0x01, V1_8, V1_8),
@ -101,7 +103,8 @@ public enum State {
map(0x26, V1_15, V1_15_2),
map(0x25, V1_16, V1_16_1),
map(0x24, V1_16_2, V1_16_4),
map(0x26, V1_17, V1_18)
map(0x26, V1_17, V1_18_2),
map(0x23, V1_19, V1_19)
);
clientBound.register(PacketPluginMessage::new,
map(0x19, V1_13, V1_13_2),
@ -109,7 +112,8 @@ public enum State {
map(0x19, V1_15, V1_15_2),
map(0x18, V1_16, V1_16_1),
map(0x17, V1_16_2, V1_16_4),
map(0x18, V1_17, V1_18)
map(0x18, V1_17, V1_18_2),
map(0x15, V1_19, V1_19)
);
clientBound.register(PacketPlayerAbilities::new,
map(0x39, V1_8, V1_8),
@ -120,7 +124,8 @@ public enum State {
map(0x32, V1_15, V1_15_2),
map(0x31, V1_16, V1_16_1),
map(0x30, V1_16_2, V1_16_4),
map(0x32, V1_17, V1_18)
map(0x32, V1_17, V1_18_2),
map(0x2F, V1_19, V1_19)
);
clientBound.register(PacketPlayerPositionAndLook::new,
map(0x08, V1_8, V1_8),
@ -131,7 +136,8 @@ public enum State {
map(0x36, V1_15, V1_15_2),
map(0x35, V1_16, V1_16_1),
map(0x34, V1_16_2, V1_16_4),
map(0x38, V1_17, V1_18)
map(0x38, V1_17, V1_18_2),
map(0x36, V1_19, V1_19)
);
clientBound.register(PacketKeepAlive::new,
map(0x00, V1_8, V1_8),
@ -141,7 +147,8 @@ public enum State {
map(0x21, V1_15, V1_15_2),
map(0x20, V1_16, V1_16_1),
map(0x1F, V1_16_2, V1_16_4),
map(0x21, V1_17, V1_18)
map(0x21, V1_17, V1_18_2),
map(0x1E, V1_19, V1_19)
);
clientBound.register(PacketChatMessage::new,
map(0x02, V1_8, V1_8),
@ -149,13 +156,15 @@ public enum State {
map(0x0E, V1_13, V1_14_4),
map(0x0F, V1_15, V1_15_2),
map(0x0E, V1_16, V1_16_4),
map(0x0F, V1_17, V1_18)
map(0x0F, V1_17, V1_18_2),
map(0x5F, V1_19, V1_19)
);
clientBound.register(PacketBossBar::new,
map(0x0C, V1_9, V1_14_4),
map(0x0D, V1_15, V1_15_2),
map(0x0C, V1_16, V1_16_4),
map(0x0D, V1_17, V1_18)
map(0x0D, V1_17, V1_18_2),
map(0x0A, V1_19, V1_19)
);
clientBound.register(PacketPlayerInfo::new,
map(0x38, V1_8, V1_8),
@ -166,7 +175,8 @@ public enum State {
map(0x34, V1_15, V1_15_2),
map(0x33, V1_16, V1_16_1),
map(0x32, V1_16_2, V1_16_4),
map(0x36, V1_17, V1_18)
map(0x36, V1_17, V1_18_2),
map(0x34, V1_19, V1_19)
);
clientBound.register(PacketTitleLegacy::new,
map(0x45, V1_8, V1_11_1),
@ -179,15 +189,15 @@ public enum State {
);
clientBound.register(PacketTitleSetTitle::new,
map(0x59, V1_17, V1_17_1),
map(0x5A, V1_18, V1_18)
map(0x5A, V1_18, V1_19)
);
clientBound.register(PacketTitleSetSubTitle::new,
map(0x57, V1_17, V1_17_1),
map(0x58, V1_18, V1_18)
map(0x58, V1_18, V1_19)
);
clientBound.register(PacketTitleTimes::new,
map(0x5A, V1_17, V1_17_1),
map(0x5B, V1_18, V1_18)
map(0x5B, V1_18, V1_19)
);
clientBound.register(PacketPlayerListHeader::new,
map(0x47, V1_8, V1_8),
@ -200,7 +210,8 @@ public enum State {
map(0x54, V1_15, V1_15_2),
map(0x53, V1_16, V1_16_4),
map(0x5E, V1_17, V1_17_1),
map(0x5F, V1_18, V1_18)
map(0x5F, V1_18, V1_18_2),
map(0x60, V1_19, V1_19)
);
}
};

View File

@ -56,8 +56,10 @@ public enum Version {
// 1.16.5 has same protocol number
V1_17(755),
V1_17_1(756),
V1_18(757);
V1_18(757),
// 1.18.1 has same protocol number
V1_18_2(758),
V1_19(759);
private static final Map<Integer, Version> VERSION_MAP;
private static final Version MAX;

View File

@ -0,0 +1,9 @@
package ru.nanit.limbo.server;
public interface Command {
void execute();
String description();
}

View File

@ -0,0 +1,59 @@
package ru.nanit.limbo.server;
import ru.nanit.limbo.server.commands.CmdConn;
import ru.nanit.limbo.server.commands.CmdHelp;
import ru.nanit.limbo.server.commands.CmdMem;
import ru.nanit.limbo.server.commands.CmdStop;
import java.util.*;
public final class CommandManager extends Thread {
private final Map<String, Command> commands = new HashMap<>();
public Map<String, Command> getCommands() {
return Collections.unmodifiableMap(commands);
}
public Command getCommand(String name) {
return commands.get(name.toLowerCase());
}
public void register(String name, Command cmd) {
commands.put(name.toLowerCase(), cmd);
}
@Override
public void run() {
Scanner scanner = new Scanner(System.in);
String command;
while (true) {
try {
command = scanner.nextLine().trim();
} catch (NoSuchElementException e) {
break;
}
Command handler = getCommand(command);
if (handler != null) {
try {
handler.execute();
} catch (Throwable t) {
Logger.error("Cannot execute command:", t);
}
continue;
}
Logger.info("Unknown command. Type \"help\" to get commands list");
}
}
public void registerAll(LimboServer server) {
register("help", new CmdHelp(server));
register("conn", new CmdConn(server));
register("mem", new CmdMem());
register("stop", new CmdStop());
}
}

View File

@ -49,6 +49,8 @@ public final class LimboServer {
private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;
private CommandManager commandManager;
public LimboConfig getConfig() {
return config;
}
@ -65,6 +67,10 @@ public final class LimboServer {
return dimensionRegistry;
}
public CommandManager getCommandManager() {
return commandManager;
}
public void start() throws Exception {
Logger.info("Starting server...");
@ -89,6 +95,12 @@ public final class LimboServer {
Logger.info("Server started on %s", config.getAddress());
Logger.setLevel(config.getDebugLevel());
commandManager = new CommandManager();
commandManager.registerAll(this);
commandManager.start();
System.gc();
}
private void startBootstrap() {
@ -120,6 +132,8 @@ public final class LimboServer {
}
private void stop() {
Logger.info("Stopping server...");
if (keepAliveTask != null) {
keepAliveTask.cancel(true);
}
@ -131,6 +145,8 @@ public final class LimboServer {
if (workerGroup != null) {
workerGroup.shutdownGracefully();
}
Logger.info("Server stopped, Goodbye!");
}
}

View File

@ -0,0 +1,24 @@
package ru.nanit.limbo.server.commands;
import ru.nanit.limbo.server.Command;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.Logger;
public class CmdConn implements Command {
private final LimboServer server;
public CmdConn(LimboServer server) {
this.server = server;
}
@Override
public void execute() {
Logger.info("Connections: %d", server.getConnections().getCount());
}
@Override
public String description() {
return "Display connections count";
}
}

View File

@ -0,0 +1,32 @@
package ru.nanit.limbo.server.commands;
import ru.nanit.limbo.server.Command;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.Logger;
import java.util.Map;
public class CmdHelp implements Command {
private final LimboServer server;
public CmdHelp(LimboServer server) {
this.server = server;
}
@Override
public void execute() {
Map<String, Command> commands = server.getCommandManager().getCommands();
Logger.info("Available commands:");
for (Map.Entry<String, Command> entry : commands.entrySet()) {
Logger.info("%s - %s", entry.getKey(), entry.getValue().description());
}
}
@Override
public String description() {
return "Show this message";
}
}

View File

@ -0,0 +1,28 @@
package ru.nanit.limbo.server.commands;
import ru.nanit.limbo.server.Command;
import ru.nanit.limbo.server.Logger;
public class CmdMem implements Command {
@Override
public void execute() {
Runtime runtime = Runtime.getRuntime();
long mb = 1024 * 1024;
long used = (runtime.totalMemory() - runtime.freeMemory()) / mb;
long total = runtime.totalMemory() / mb;
long free = runtime.freeMemory() / mb;
long max = runtime.maxMemory() / mb;
Logger.info("Memory usage:");
Logger.info("Used: %d MB", used);
Logger.info("Total: %d MB", total);
Logger.info("Free: %d MB", free);
Logger.info("Max: %d MB", max);
}
@Override
public String description() {
return "Display memory usage";
}
}

View File

@ -0,0 +1,16 @@
package ru.nanit.limbo.server.commands;
import ru.nanit.limbo.server.Command;
public class CmdStop implements Command {
@Override
public void execute() {
System.exit(0);
}
@Override
public String description() {
return "Stop the server";
}
}

View File

@ -20,9 +20,10 @@ package ru.nanit.limbo.util;
public final class Colors {
private static final char CHAR_FROM = '&';
private static final char CHAR_TO = '§';
private static final char CHAR_TO = '\u00a7';
private Colors() {}
private Colors() {
}
public static String of(String text) {
if (text == null) return null;

View File

@ -31,33 +31,55 @@ public final class DimensionRegistry {
private final LimboServer server;
private Dimension defaultDimension;
private Dimension defaultDimension_1_16;
private Dimension defaultDimension_1_18_2;
private CompoundBinaryTag codec;
private CompoundBinaryTag codec_1_16;
private CompoundBinaryTag codec_1_18_2;
private CompoundBinaryTag codec_1_19;
private CompoundBinaryTag oldCodec;
public DimensionRegistry(LimboServer server) {
this.server = server;
}
public CompoundBinaryTag getCodec() {
return codec;
public CompoundBinaryTag getCodec_1_16() {
return codec_1_16;
}
public CompoundBinaryTag getCodec_1_18_2() {
return codec_1_18_2;
}
public CompoundBinaryTag getCodec_1_19() {
return codec_1_19;
}
public CompoundBinaryTag getOldCodec() {
return oldCodec;
}
public Dimension getDefaultDimension() {
return defaultDimension;
public Dimension getDefaultDimension_1_16() {
return defaultDimension_1_16;
}
public Dimension getDefaultDimension_1_18_2() {
return defaultDimension_1_18_2;
}
public void load(String def) throws IOException {
codec = readCodecFile("/dimension/codec_new.snbt");
codec_1_16 = readCodecFile("/dimension/codec_1_16.snbt");
codec_1_18_2 = readCodecFile("/dimension/codec_1_18_2.snbt");
codec_1_19 = readCodecFile("/dimension/codec_1_19.snbt");
// On 1.16-1.16.1 different codec format
oldCodec = readCodecFile("/dimension/codec_old.snbt");
ListBinaryTag dimensions = codec.getCompound("minecraft:dimension_type").getList("value");
defaultDimension_1_16 = getDefaultDimension(def, codec_1_16);
defaultDimension_1_18_2 = getDefaultDimension(def, codec_1_18_2);
}
private Dimension getDefaultDimension(String def, CompoundBinaryTag tag) {
ListBinaryTag dimensions = tag.getCompound("minecraft:dimension_type").getList("value");
CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
CompoundBinaryTag nether = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(2)).get("element");
@ -65,18 +87,14 @@ public final class DimensionRegistry {
switch (def.toLowerCase()) {
case "overworld":
defaultDimension = new Dimension(0, "minecraft:overworld", overWorld);
break;
case "nether":
defaultDimension = new Dimension(-1, "minecraft:nether", nether);
break;
return new Dimension(0, "minecraft:overworld", overWorld);
case "the_nether":
return new Dimension(-1, "minecraft:nether", nether);
case "the_end":
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
default:
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@ headerAndFooter:
# Spawn position in the world
spawnPosition:
x: 0.0
y: 64.0
y: 400.0
z: 0.0
yaw: 0.0
pitch: 0.0