From 107892fb247967d302f68f40ff83ba2824d04bb2 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 7 Oct 2020 12:50:23 +0200 Subject: [PATCH] Hopefully finish preparation, minor optimizations --- .../us/myles/ViaVersion/AbstractViaConfig.java | 10 +++++----- .../myles/ViaVersion/api/ViaVersionConfig.java | 4 ++-- .../api/protocol/ProtocolVersion.java | 4 ++++ .../ViaVersion/protocols/base/BaseProtocol.java | 6 +++++- .../protocols/base/BaseProtocol1_7.java | 17 ++++++++--------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java index a2d9e06e5..f56acb691 100644 --- a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java @@ -1,11 +1,11 @@ package us.myles.ViaVersion; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.util.Config; import java.io.File; -import java.util.HashSet; -import java.util.Set; public abstract class AbstractViaConfig extends Config implements ViaVersionConfig { @@ -35,7 +35,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf private boolean autoTeam; private boolean forceJsonTransform; private boolean nbtArrayFix; - private Set blockedProtocols; + private IntSet blockedProtocols; private String blockedDisconnectMessage; private String reloadDisconnectMessage; private boolean suppressConversionWarnings; @@ -93,7 +93,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf autoTeam = getBoolean("auto-team", true); forceJsonTransform = getBoolean("force-json-transform", false); nbtArrayFix = getBoolean("chat-nbt-fix", true); - blockedProtocols = new HashSet<>(getIntegerList("block-protocols")); + blockedProtocols = new IntOpenHashSet(getIntegerList("block-protocols")); blockedDisconnectMessage = getString("block-disconnect-msg", "You are using an unsupported Minecraft version!"); reloadDisconnectMessage = getString("reload-disconnect-msg", "Server reload, please rejoin!"); minimizeCooldown = getBoolean("minimize-cooldown", true); @@ -257,7 +257,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf } @Override - public Set getBlockedProtocols() { + public IntSet getBlockedProtocols() { return blockedProtocols; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index d4983d9d8..de31982b8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -1,6 +1,6 @@ package us.myles.ViaVersion.api; -import java.util.Set; +import it.unimi.dsi.fastutil.ints.IntSet; public interface ViaVersionConfig { @@ -213,7 +213,7 @@ public interface ViaVersionConfig { * * @return An Integer list */ - Set getBlockedProtocols(); + IntSet getBlockedProtocols(); /** * Get the custom disconnect message diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 3ef25550d..b14c95f3d 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -161,6 +161,10 @@ public class ProtocolVersion { return id; } + public int getOriginalId() { + return snapshotId == -1 ? id : ((1 << 30) | snapshotId); + } + /** * @return snapshot protocol version without the snapshot indicator bit, -1 if not a snapshot */ diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java index c7cb191eb..dc98204a2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java @@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; @@ -57,7 +58,10 @@ public class BaseProtocol extends SimpleProtocol { // Ensure mapping data has already been loaded ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass()); } - wrapper.set(Type.VAR_INT, 0, serverProtocol); + + // Set the original snapshot version if present + ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocol); + wrapper.set(Type.VAR_INT, 0, protocol.getOriginalId()); } // Add Base Protocol diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java index 3a60bc781..f87dec0ce 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java @@ -52,14 +52,12 @@ public class BaseProtocol1_7 extends SimpleProtocol { protocolVersion = ((Long) version.get("protocol").getAsLong()).intValue(); } } else { - version = new JsonObject(); - json.getAsJsonObject().add("version", version); + json.getAsJsonObject().add("version", version = new JsonObject()); } } else { // Format properly json = new JsonObject(); - version = new JsonObject(); - json.getAsJsonObject().add("version", version); + json.getAsJsonObject().add("version", version = new JsonObject()); } if (Via.getConfig().isSendSupportedVersions()) { // Send supported versions @@ -71,12 +69,13 @@ public class BaseProtocol1_7 extends SimpleProtocol { } // Ensure the server has a version provider - if (Via.getManager().getProviders().get(VersionProvider.class) == null) { + VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class); + if (versionProvider == null) { wrapper.user().setActive(false); return; } - int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); + int protocol = versionProvider.getServerProtocol(wrapper.user()); List> protocols = null; // Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) @@ -85,9 +84,9 @@ public class BaseProtocol1_7 extends SimpleProtocol { } if (protocols != null) { - if (protocolVersion == protocol || protocolVersion == 0) { - //Fix ServerListPlus - version.addProperty("protocol", info.getProtocolVersion()); + if (protocolVersion == protocol || protocolVersion == 0) { // Fix ServerListPlus + ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion()); + version.addProperty("protocol", prot.getOriginalId()); } } else { // not compatible :(, *plays very sad violin*