3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-08 17:40:04 +01:00

Attempt to support ViaVersion on the proxy by looking up player version from the data version

Dieser Commit ist enthalten in:
Moulberry 2024-05-10 02:34:28 +08:00
Ursprung 37788e2703
Commit cd8b5c5346
3 geänderte Dateien mit 36 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,6 @@ import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.packet.*; import com.moulberry.axiom.packet.*;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.papermc.paper.event.player.PlayerFailMoveEvent; import io.papermc.paper.event.player.PlayerFailMoveEvent;
@ -17,13 +16,11 @@ import io.papermc.paper.event.world.WorldGameRuleChangeEvent;
import io.papermc.paper.network.ChannelInitializeListener; import io.papermc.paper.network.ChannelInitializeListener;
import io.papermc.paper.network.ChannelInitializeListenerHolder; import io.papermc.paper.network.ChannelInitializeListenerHolder;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.IdMapper; import net.minecraft.core.IdMapper;
import net.minecraft.network.*; import net.minecraft.network.*;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.common.custom.DiscardedPayload; import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.network.protocol.game.GameProtocols; import net.minecraft.network.protocol.game.GameProtocols;
import net.minecraft.network.protocol.game.ServerGamePacketListener; import net.minecraft.network.protocol.game.ServerGamePacketListener;
@ -45,7 +42,6 @@ import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.PaperCommandManager; import org.incendo.cloud.paper.PaperCommandManager;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -60,7 +56,7 @@ public class AxiomPaper extends JavaPlugin implements Listener {
public final Map<UUID, RateLimiter> playerBlockBufferRateLimiters = new ConcurrentHashMap<>(); public final Map<UUID, RateLimiter> playerBlockBufferRateLimiters = new ConcurrentHashMap<>();
public final Map<UUID, Restrictions> playerRestrictions = new ConcurrentHashMap<>(); public final Map<UUID, Restrictions> playerRestrictions = new ConcurrentHashMap<>();
public final Map<UUID, IdMapper<BlockState>> playerBlockRegistry = new ConcurrentHashMap<>(); public final Map<UUID, IdMapper<BlockState>> playerBlockRegistry = new ConcurrentHashMap<>();
public final Set<UUID> mismatchedDataVersionUsingViaVersion = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Map<UUID, Integer> playerProtocolVersion = new ConcurrentHashMap<>();
public Configuration configuration; public Configuration configuration;
public IdMapper<BlockState> allowedBlockRegistry = null; public IdMapper<BlockState> allowedBlockRegistry = null;
@ -273,7 +269,7 @@ public class AxiomPaper extends JavaPlugin implements Listener {
playerBlockBufferRateLimiters.keySet().retainAll(stillActiveAxiomPlayers); playerBlockBufferRateLimiters.keySet().retainAll(stillActiveAxiomPlayers);
playerRestrictions.keySet().retainAll(stillActiveAxiomPlayers); playerRestrictions.keySet().retainAll(stillActiveAxiomPlayers);
playerBlockRegistry.keySet().retainAll(stillActiveAxiomPlayers); playerBlockRegistry.keySet().retainAll(stillActiveAxiomPlayers);
mismatchedDataVersionUsingViaVersion.retainAll(stillActiveAxiomPlayers); playerProtocolVersion.keySet().retainAll(stillActiveAxiomPlayers);
}, 20, 20); }, 20, 20);
boolean sendMarkers = configuration.getBoolean("send-markers"); boolean sendMarkers = configuration.getBoolean("send-markers");
@ -317,7 +313,11 @@ public class AxiomPaper extends JavaPlugin implements Listener {
} }
public boolean isMismatchedDataVersion(UUID uuid) { 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<BlockState> getBlockRegistry(UUID uuid) { public IdMapper<BlockState> getBlockRegistry(UUID uuid) {

Datei anzeigen

@ -9,18 +9,12 @@ import com.moulberry.axiom.persistence.UUIDDataType;
import com.moulberry.axiom.viaversion.ViaVersionHelper; import com.moulberry.axiom.viaversion.ViaVersionHelper;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.*;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.ByteBufReader;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.core.IdMapper; import net.minecraft.core.IdMapper;
import net.minecraft.nbt.NbtIo;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -38,7 +32,6 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class HelloPacketListener implements PluginMessageListener { public class HelloPacketListener implements PluginMessageListener {
@ -73,19 +66,39 @@ public class HelloPacketListener implements PluginMessageListener {
String incompatibleDataVersion = plugin.configuration.getString("incompatible-data-version"); String incompatibleDataVersion = plugin.configuration.getString("incompatible-data-version");
if (incompatibleDataVersion == null) incompatibleDataVersion = "warn"; if (incompatibleDataVersion == null) incompatibleDataVersion = "warn";
if (!Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) { Component incompatibleWarning = Component.text("Axiom: Incompatible data version detected (client " + dataVersion +
Component text = Component.text("Axiom: Incompatible data version detected (client " + dataVersion + ", server " + serverDataVersion + ")");
", server " + serverDataVersion + ")");
if (!Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) {
if (incompatibleDataVersion.equals("warn")) { if (incompatibleDataVersion.equals("warn")) {
player.sendMessage(text.color(NamedTextColor.RED)); player.sendMessage(incompatibleWarning.color(NamedTextColor.RED));
return; return;
} else if (!incompatibleDataVersion.equals("ignore")) { } else if (!incompatibleDataVersion.equals("ignore")) {
player.kick(text); player.kick(incompatibleWarning);
return; return;
} }
} else { } else {
int playerVersion = Via.getAPI().getPlayerVersion(player.getUniqueId()); 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<BlockState> mapper; IdMapper<BlockState> mapper;
try { try {
@ -105,7 +118,7 @@ public class HelloPacketListener implements PluginMessageListener {
} }
this.plugin.playerBlockRegistry.put(player.getUniqueId(), mapper); 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. " + 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"); "Axiom will try to use ViaVersion conversions, but this process may cause problems");

Datei anzeigen

@ -96,7 +96,7 @@ public class ViaVersionHelper {
private static final int UNNAMED_COMPOUND_TAG_CHANGE_VERSION = 764; // 1.20.2 private static final int UNNAMED_COMPOUND_TAG_CHANGE_VERSION = 764; // 1.20.2
public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception { 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 { public static void skipTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception {
@ -104,7 +104,7 @@ public class ViaVersionHelper {
} }
public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, Player player) throws Exception { 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 { public static CompoundTag readTagViaVersion(FriendlyByteBuf friendlyByteBuf, int playerVersion) throws Exception {