From e0ae4c1b85dbf46adff3161e933f927e8d0fa2c1 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 21 Sep 2021 14:34:17 -0400 Subject: [PATCH] Fix disconnect message formatting --- .../network/session/GeyserSession.java | 21 +++++++------------ .../network/translators/PacketTranslator.java | 7 +++++++ .../translators/PacketTranslatorRegistry.java | 2 +- .../java/JavaDisconnectPacket.java | 5 +++++ .../java/JavaLoginDisconnectTranslator.java | 5 +++++ 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index df152da6a..c9c42e756 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -140,17 +140,17 @@ public class GeyserSession implements CommandSender { private final SessionPlayerEntity playerEntity; - private AdvancementsCache advancementsCache; - private BookEditCache bookEditCache; - private ChunkCache chunkCache; - private EntityCache entityCache; - private EntityEffectCache effectCache; + private final AdvancementsCache advancementsCache; + private final BookEditCache bookEditCache; + private final ChunkCache chunkCache; + private final EntityCache entityCache; + private final EntityEffectCache effectCache; private final FormCache formCache; private final LodestoneCache lodestoneCache; private final PistonCache pistonCache; private final PreferencesCache preferencesCache; private final TagCache tagCache; - private WorldCache worldCache; + private final WorldCache worldCache; private final Int2ObjectMap teleportMap = new Int2ObjectOpenHashMap<>(); @@ -884,16 +884,9 @@ public class GeyserSession implements CommandSender { } if (tickThread != null) { - tickThread.cancel(true); + tickThread.cancel(false); } - this.advancementsCache = null; - this.bookEditCache = null; - this.chunkCache = null; - this.entityCache = null; - this.effectCache = null; - this.worldCache = null; - closed = true; } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslator.java index f59f747d2..b0b1aab5e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslator.java @@ -31,4 +31,11 @@ public abstract class PacketTranslator { public abstract void translate(GeyserSession session, T packet); + /** + * Determines if this packet should be handled in the session's event loop. This should generally be true - + * only when the packet has to be executed immediately should it be false. + */ + public boolean shouldExecuteInEventLoop() { + return true; + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslatorRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslatorRegistry.java index 49f299d59..56735f98d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslatorRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/PacketTranslatorRegistry.java @@ -90,7 +90,7 @@ public class PacketTranslatorRegistry { PacketTranslator

translator = (PacketTranslator

) translators.get(clazz); if (translator != null) { EventLoop eventLoop = session.getEventLoop(); - if (eventLoop.inEventLoop()) { + if (!translator.shouldExecuteInEventLoop() || eventLoop.inEventLoop()) { translate0(session, translator, packet); } else { eventLoop.execute(() -> translate0(session, translator, packet)); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDisconnectPacket.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDisconnectPacket.java index 3a9ca3787..b5b2e83a3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDisconnectPacket.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDisconnectPacket.java @@ -38,4 +38,9 @@ public class JavaDisconnectPacket extends PacketTranslator