From e089fb5584e5bfe44ea1a341a1f6b9badb972182 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sat, 29 Jan 2022 20:38:34 +0200 Subject: [PATCH 1/5] Set custom log level after server started --- src/main/java/ru/nanit/limbo/server/LimboServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/nanit/limbo/server/LimboServer.java b/src/main/java/ru/nanit/limbo/server/LimboServer.java index bacbdae..8cd38f7 100644 --- a/src/main/java/ru/nanit/limbo/server/LimboServer.java +++ b/src/main/java/ru/nanit/limbo/server/LimboServer.java @@ -67,8 +67,6 @@ public final class LimboServer { config = new LimboConfig(Paths.get("./")); config.load(); - Logger.setLevel(config.getDebugLevel()); - dimensionRegistry = new DimensionRegistry(this); dimensionRegistry.load(config.getDimensionType()); connections = new Connections(); @@ -82,6 +80,8 @@ public final class LimboServer { Runtime.getRuntime().addShutdownHook(new Thread(this::stop, "NanoLimbo shutdown thread")); Logger.info("Server started on %s", config.getAddress()); + + Logger.setLevel(config.getDebugLevel()); } private void startBootstrap() { From 188d2de0dfb1e5067ad46edb219d25e75f4ac8fa Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sat, 29 Jan 2022 21:34:28 +0200 Subject: [PATCH 2/5] Add configuration for declare commands and player list --- .../limbo/configuration/LimboConfig.java | 23 ++++++++++++++++- .../limbo/connection/ClientConnection.java | 25 +++++++++++++------ src/main/resources/settings.yml | 9 +++++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index c55daed..fa256f0 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -33,6 +33,7 @@ import java.net.SocketAddress; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; public final class LimboConfig { @@ -50,10 +51,13 @@ public final class LimboConfig { private boolean useJoinMessage; private boolean useBossBar; private boolean useTitle; + private boolean useDeclareCommands; + private boolean usePlayerList; private String brandName; private String joinMessage; private BossBar bossBar; private Title title; + private List declareCommands; private InfoForwarding infoForwarding; private long readTimeout; @@ -86,8 +90,10 @@ public final class LimboConfig { useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); useBossBar = conf.node("bossBar", "enable").getBoolean(); useTitle = conf.node("title", "enable").getBoolean(); + useDeclareCommands = conf.node("declareCommands", "enable").getBoolean(); + usePlayerList = conf.node("playerList").getBoolean(); - if(useBrandName) + if (useBrandName) brandName = conf.node("brandName", "content").getString(); if (useJoinMessage) @@ -99,6 +105,9 @@ public final class LimboConfig { if (useTitle) title = conf.node("title").get(Title.class); + if (useDeclareCommands) + declareCommands = conf.node("declareCommands", "commands").getList(String.class); + infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class); readTimeout = conf.node("readTimeout").getLong(); debugLevel = conf.node("debugLevel").getInt(); @@ -187,6 +196,14 @@ public final class LimboConfig { return useTitle; } + public boolean isUseDeclareCommands() { + return useDeclareCommands; + } + + public boolean isUsePlayerList() { + return usePlayerList; + } + public String getBrandName() { return brandName; } @@ -203,6 +220,10 @@ public final class LimboConfig { return title; } + public List getDeclareCommands() { + return declareCommands; + } + public boolean isUseEpoll() { return useEpoll; } diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index ea9eb1e..04a742d 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -50,7 +50,6 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.security.InvalidKeyException; import java.security.MessageDigest; -import java.util.Collections; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -239,10 +238,14 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { writePacket(PACKET_JOIN_GAME); writePacket(PACKET_PLAYER_ABILITIES); writePacket(PACKET_PLAYER_POS); - writePacket(PACKET_PLAYER_INFO); + if (PACKET_PLAYER_INFO != null) { + writePacket(PACKET_PLAYER_INFO); + } if (clientVersion.moreOrEqual(Version.V1_13)){ - writePacket(PACKET_DECLARE_COMMANDS); + if (PACKET_DECLARE_COMMANDS != null) + writePacket(PACKET_DECLARE_COMMANDS); + if (PACKET_PLUGIN_MESSAGE != null) writePacket(PACKET_PLUGIN_MESSAGE); @@ -426,15 +429,21 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { info.setGameMode(server.getConfig().getGameMode()); info.setUuid(uuid); - PacketDeclareCommands declareCommands = new PacketDeclareCommands(); - declareCommands.setCommands(Collections.emptyList()); - PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess); PACKET_JOIN_GAME = PacketSnapshot.of(joinGame); PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities); PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook); - PACKET_PLAYER_INFO = PacketSnapshot.of(info); - PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); + + if (server.getConfig().isUsePlayerList()) { + PACKET_PLAYER_INFO = PacketSnapshot.of(info); + } + + if (server.getConfig().isUseDeclareCommands()) { + PacketDeclareCommands declareCommands = new PacketDeclareCommands(); + declareCommands.setCommands(server.getConfig().getDeclareCommands()); + + PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); + } if (server.getConfig().isUseBrandName()){ PacketPluginMessage pluginMessage = new PacketPluginMessage(); diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index e47477d..e33899a 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -19,6 +19,15 @@ ping: # Available dimensions: OVERWORLD, NETHER, THE_END dimension: THE_END +# Sending prepared tabcomplete commands to the player +declareCommands: + enable: true + commands: + - 'NanoLimbo' + +# Whether to display the player in the player list +playerList: true + # Spawn position in the world spawnPosition: x: 0.0 From 5e1bf15fe1f0858f74920442aa4bcd63df2bba68 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sun, 30 Jan 2022 12:17:20 +0200 Subject: [PATCH 3/5] Set declare commands empty --- .../ru/nanit/limbo/configuration/LimboConfig.java | 15 --------------- .../nanit/limbo/connection/ClientConnection.java | 14 ++++++-------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index fa256f0..aac08c6 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -33,7 +33,6 @@ import java.net.SocketAddress; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; public final class LimboConfig { @@ -51,13 +50,11 @@ public final class LimboConfig { private boolean useJoinMessage; private boolean useBossBar; private boolean useTitle; - private boolean useDeclareCommands; private boolean usePlayerList; private String brandName; private String joinMessage; private BossBar bossBar; private Title title; - private List declareCommands; private InfoForwarding infoForwarding; private long readTimeout; @@ -90,7 +87,6 @@ public final class LimboConfig { useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); useBossBar = conf.node("bossBar", "enable").getBoolean(); useTitle = conf.node("title", "enable").getBoolean(); - useDeclareCommands = conf.node("declareCommands", "enable").getBoolean(); usePlayerList = conf.node("playerList").getBoolean(); if (useBrandName) @@ -105,9 +101,6 @@ public final class LimboConfig { if (useTitle) title = conf.node("title").get(Title.class); - if (useDeclareCommands) - declareCommands = conf.node("declareCommands", "commands").getList(String.class); - infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class); readTimeout = conf.node("readTimeout").getLong(); debugLevel = conf.node("debugLevel").getInt(); @@ -196,10 +189,6 @@ public final class LimboConfig { return useTitle; } - public boolean isUseDeclareCommands() { - return useDeclareCommands; - } - public boolean isUsePlayerList() { return usePlayerList; } @@ -220,10 +209,6 @@ public final class LimboConfig { return title; } - public List getDeclareCommands() { - return declareCommands; - } - public boolean isUseEpoll() { return useEpoll; } diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index 04a742d..e0750b1 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -50,6 +50,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.security.InvalidKeyException; import java.security.MessageDigest; +import java.util.Collections; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -243,8 +244,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { } if (clientVersion.moreOrEqual(Version.V1_13)){ - if (PACKET_DECLARE_COMMANDS != null) - writePacket(PACKET_DECLARE_COMMANDS); + writePacket(PACKET_DECLARE_COMMANDS); if (PACKET_PLUGIN_MESSAGE != null) @@ -429,6 +429,9 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { info.setGameMode(server.getConfig().getGameMode()); info.setUuid(uuid); + PacketDeclareCommands declareCommands = new PacketDeclareCommands(); + declareCommands.setCommands(Collections.emptyList()); + PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess); PACKET_JOIN_GAME = PacketSnapshot.of(joinGame); PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities); @@ -438,12 +441,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { PACKET_PLAYER_INFO = PacketSnapshot.of(info); } - if (server.getConfig().isUseDeclareCommands()) { - PacketDeclareCommands declareCommands = new PacketDeclareCommands(); - declareCommands.setCommands(server.getConfig().getDeclareCommands()); - - PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); - } + PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); if (server.getConfig().isUseBrandName()){ PacketPluginMessage pluginMessage = new PacketPluginMessage(); From ba0292eb07926dd42dcdce2a8cbbe4d4ca2bfb64 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sun, 30 Jan 2022 12:17:54 +0200 Subject: [PATCH 4/5] Remove declare commands from config --- src/main/resources/settings.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index e33899a..4ef7cb8 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -19,12 +19,6 @@ ping: # Available dimensions: OVERWORLD, NETHER, THE_END dimension: THE_END -# Sending prepared tabcomplete commands to the player -declareCommands: - enable: true - commands: - - 'NanoLimbo' - # Whether to display the player in the player list playerList: true From 04c6e1b037b537b2d73c21c9f78d2e2d784f7d52 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sun, 30 Jan 2022 12:36:06 +0200 Subject: [PATCH 5/5] Always send packet PlayerInfo for <1.17 versions --- .../ru/nanit/limbo/connection/ClientConnection.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index e0750b1..affc76c 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -239,7 +239,13 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { writePacket(PACKET_JOIN_GAME); writePacket(PACKET_PLAYER_ABILITIES); writePacket(PACKET_PLAYER_POS); - if (PACKET_PLAYER_INFO != null) { + + if (clientVersion.moreOrEqual(Version.V1_17)) { + if (server.getConfig().isUsePlayerList()) { + writePacket(PACKET_PLAYER_INFO); + } + } + else { writePacket(PACKET_PLAYER_INFO); } @@ -437,9 +443,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities); PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook); - if (server.getConfig().isUsePlayerList()) { - PACKET_PLAYER_INFO = PacketSnapshot.of(info); - } + PACKET_PLAYER_INFO = PacketSnapshot.of(info); PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands);