From 189b244a3a1b77be04f0c54b6af507a06ccee15c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 30 Jun 2022 10:41:54 +0200 Subject: [PATCH] Delay ack by a tick, update warning for bad dimension registry --- .../providers/BukkitAckSequenceProvider.java | 2 +- .../packets/EntityPackets.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitAckSequenceProvider.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitAckSequenceProvider.java index 64965e488..5e3f4fc3b 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitAckSequenceProvider.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitAckSequenceProvider.java @@ -36,7 +36,7 @@ public final class BukkitAckSequenceProvider extends AckSequenceProvider { final SequenceStorage sequenceStorage = connection.get(SequenceStorage.class); final int previousSequence = sequenceStorage.setSequenceId(sequence); if (previousSequence == -1) { - plugin.getServer().getScheduler().runTask(plugin, new AckSequenceTask(connection, sequenceStorage)); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new AckSequenceTask(connection, sequenceStorage), 1); } } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index c7f219fe1..e8e857994 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -309,17 +309,19 @@ public final class EntityPackets extends EntityRewriter { final CompoundTag currentDimension = wrapper.read(Type.NBT); String dimensionKey = registryStorage.dimensionKey(currentDimension); if (dimensionKey == null) { - Via.getPlatform().getLogger().severe("The server tried to send dimension data from a dimension the client wasn't told about on join. " + - "Plugins and mods have to make sure they are not creating new dimension types while players are online, and proxies need to make sure they don't scramble dimension data." + - " Received dimension: " + currentDimension + ". Known dimensions: " + registryStorage.dimensions()); + if (!Via.getConfig().isSuppressConversionWarnings()) { + Via.getPlatform().getLogger().warning("The server tried to send dimension data from a dimension the client wasn't told about on join. " + + "Plugins and mods have to make sure they are not creating new dimension types while players are online, and proxies need to make sure they don't scramble dimension data." + + " Received dimension: " + currentDimension + ". Known dimensions: " + registryStorage.dimensions()); + } + // Try to find the most similar dimension dimensionKey = registryStorage.dimensions().entrySet().stream() .map(it -> new Pair<>(it, Maps.difference(currentDimension.getValue(), it.getKey().getValue()).entriesInCommon())) - .filter(it -> it.value().containsKey("min_y")) - .filter(it -> it.value().containsKey("height")) - .map(it -> new Pair<>(it.key(), it.value().size())) - .max(Comparator.comparingInt(Pair::value)) - .get().key().getValue(); + .filter(it -> it.value().containsKey("min_y") && it.value().containsKey("height")) + .max(Comparator.comparingInt(it -> it.value().size())) + .orElseThrow(() -> new IllegalArgumentException("Dimension not found in registry data from join packet: " + currentDimension)) + .key().getValue(); } wrapper.write(Type.STRING, dimensionKey);