diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 69b8a23..12bc7f9 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -17,6 +17,7 @@ import io.papermc.paper.event.world.WorldGameRuleChangeEvent; import io.papermc.paper.network.ChannelInitializeListener; import io.papermc.paper.network.ChannelInitializeListenerHolder; import net.kyori.adventure.key.Key; +import net.minecraft.SharedConstants; import net.minecraft.core.BlockPos; import net.minecraft.core.IdMapper; import net.minecraft.network.Connection; @@ -42,7 +43,6 @@ import org.incendo.cloud.execution.ExecutionCoordinator; import org.incendo.cloud.paper.LegacyPaperCommandManager; import org.jetbrains.annotations.Nullable; -import java.io.FileReader; import java.io.IOException; import java.lang.ref.WeakReference; import java.nio.file.Files; @@ -58,7 +58,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { public final Map playerBlockBufferRateLimiters = new ConcurrentHashMap<>(); public final Map playerRestrictions = new ConcurrentHashMap<>(); public final Map> playerBlockRegistry = new ConcurrentHashMap<>(); - public final Set mismatchedDataVersionUsingViaVersion = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public final Map playerProtocolVersion = new ConcurrentHashMap<>(); public Configuration configuration; public IdMapper allowedBlockRegistry = null; @@ -273,7 +273,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { playerBlockBufferRateLimiters.keySet().retainAll(stillActiveAxiomPlayers); playerRestrictions.keySet().retainAll(stillActiveAxiomPlayers); playerBlockRegistry.keySet().retainAll(stillActiveAxiomPlayers); - mismatchedDataVersionUsingViaVersion.retainAll(stillActiveAxiomPlayers); + playerProtocolVersion.keySet().retainAll(stillActiveAxiomPlayers); }, 20, 20); boolean sendMarkers = configuration.getBoolean("send-markers"); @@ -336,7 +336,11 @@ public class AxiomPaper extends JavaPlugin implements Listener { } public boolean isMismatchedDataVersion(UUID uuid) { - return this.mismatchedDataVersionUsingViaVersion.contains(uuid); + return this.playerProtocolVersion.containsKey(uuid); + } + + public int getProtocolVersionFor(UUID uuid) { + return this.playerProtocolVersion.getOrDefault(uuid, SharedConstants.getProtocolVersion()); } public IdMapper getBlockRegistry(UUID uuid) { diff --git a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java index 7a7b62d..fa18e11 100644 --- a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java @@ -64,19 +64,39 @@ public class HelloPacketListener implements PluginMessageListener { String incompatibleDataVersion = plugin.configuration.getString("incompatible-data-version"); if (incompatibleDataVersion == null) incompatibleDataVersion = "warn"; - if (!Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) { - Component text = Component.text("Axiom: Incompatible data version detected (client " + dataVersion + - ", server " + serverDataVersion + ")"); + Component incompatibleWarning = Component.text("Axiom: Incompatible data version detected (client " + dataVersion + + ", server " + serverDataVersion + ")"); + if (!Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) { if (incompatibleDataVersion.equals("warn")) { - player.sendMessage(text.color(NamedTextColor.RED)); + player.sendMessage(incompatibleWarning.color(NamedTextColor.RED)); return; } else if (!incompatibleDataVersion.equals("ignore")) { - player.kick(text); + player.kick(incompatibleWarning); return; } } else { int playerVersion = Via.getAPI().getPlayerVersion(player.getUniqueId()); + if (playerVersion == SharedConstants.getProtocolVersion()) { + // Likely using via on the proxy, try to get protocol version from data version + if (dataVersion < 3337) { + player.sendMessage(incompatibleWarning.color(NamedTextColor.RED)); + return; + } else if (dataVersion == 3337) { + playerVersion = 762; // 1.19.4 + } else if (dataVersion <= 3465) { + playerVersion = 763; // 1.20.1 + } else if (dataVersion <= 3578) { + playerVersion = 764; // 1.20.2 + } else if (dataVersion <= 3700) { + playerVersion = 765; // 1.20.3 / 1.20.4 + } else if (dataVersion <= 3837) { + playerVersion = 766; // 1.20.3 / 1.20.4 + } else { + player.sendMessage(incompatibleWarning.color(NamedTextColor.RED)); + return; + } + } IdMapper mapper; try { @@ -96,7 +116,7 @@ public class HelloPacketListener implements PluginMessageListener { } this.plugin.playerBlockRegistry.put(player.getUniqueId(), mapper); - this.plugin.mismatchedDataVersionUsingViaVersion.add(player.getUniqueId()); + this.plugin.playerProtocolVersion.put(player.getUniqueId(), playerVersion); Component text = Component.text("Axiom: Warning, client and server versions don't match. " + "Axiom will try to use ViaVersion conversions, but this process may cause problems"); diff --git a/src/main/java/com/moulberry/axiom/viaversion/ViaVersionHelper.java b/src/main/java/com/moulberry/axiom/viaversion/ViaVersionHelper.java index 156eb56..f874de7 100644 --- a/src/main/java/com/moulberry/axiom/viaversion/ViaVersionHelper.java +++ b/src/main/java/com/moulberry/axiom/viaversion/ViaVersionHelper.java @@ -97,7 +97,7 @@ public class ViaVersionHelper { private static final int UNNAMED_COMPOUND_TAG_CHANGE_VERSION = 764; // 1.20.2 public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception { - skipTagViaVersion(friendlyByteBuf, Via.getAPI().getPlayerVersion(player.getUniqueId())); + skipTagViaVersion(friendlyByteBuf, AxiomPaper.PLUGIN.getProtocolVersionFor(player.getUniqueId())); } public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception { @@ -105,7 +105,7 @@ public class ViaVersionHelper { } public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception { - return readTagViaVersion(friendlyByteBuf, Via.getAPI().getPlayerVersion(player.getUniqueId())); + return readTagViaVersion(friendlyByteBuf, AxiomPaper.PLUGIN.getProtocolVersionFor(player.getUniqueId())); } public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception {