Delay ack by a tick, update warning for bad dimension registry

This commit is contained in:
Nassim Jahnke 2022-06-30 10:41:54 +02:00
parent 12d538fe0d
commit 189b244a3a
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 11 additions and 9 deletions

View File

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

View File

@ -309,17 +309,19 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
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);