Fix disconnect message formatting

This commit is contained in:
Camotoy 2021-09-21 14:34:17 -04:00
parent 22b962731c
commit e0ae4c1b85
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
5 changed files with 25 additions and 15 deletions

View file

@ -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<TeleportCache> 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;
}

View file

@ -31,4 +31,11 @@ public abstract class PacketTranslator<T> {
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;
}
}

View file

@ -90,7 +90,7 @@ public class PacketTranslatorRegistry<T> {
PacketTranslator<P> translator = (PacketTranslator<P>) 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));

View file

@ -38,4 +38,9 @@ public class JavaDisconnectPacket extends PacketTranslator<ServerDisconnectPacke
public void translate(GeyserSession session, ServerDisconnectPacket packet) {
session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.getLocale()));
}
@Override
public boolean shouldExecuteInEventLoop() {
return false;
}
}

View file

@ -39,4 +39,9 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator<LoginDisconn
// The client doesn't manually get disconnected so we have to do it ourselves
session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.getLocale()));
}
@Override
public boolean shouldExecuteInEventLoop() {
return false;
}
}