diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index c4769f0b5..993742098 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/bukkit/pom.xml b/bukkit/pom.xml index e259abe70..83047b604 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index d649993e3..29683271d 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 17638b0f5..c2896a4d6 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index 92653a1bc..f8fdc70c7 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -83,7 +83,7 @@ public class ViaManager { public void onServerLoaded() { // Load Server Protocol try { - ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion(); + ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getId(); } catch (Exception e) { platform.getLogger().severe("ViaVersion failed to get the server protocol!"); e.printStackTrace(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 00672524e..40172daa7 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -32,6 +32,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_16_1to1_16.Protocol1_16_1To1_16; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import us.myles.ViaVersion.protocols.protocol1_16_3to1_16_2.Protocol1_16_3To1_16_2; +import us.myles.ViaVersion.protocols.protocol1_16_4to1_16_3.Protocol1_16_4To1_16_3; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; @@ -116,6 +117,7 @@ public class ProtocolRegistry { registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16); registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1); registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_2); + registerProtocol(new Protocol1_16_4To1_16_3(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_16_3); } public static void init() { 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 09f547580..3ef25550d 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 @@ -1,11 +1,15 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class ProtocolVersion { - private static final Map versions = new HashMap<>(); + private static final Int2ObjectMap versions = new Int2ObjectOpenHashMap<>(); private static final List versionList = new ArrayList<>(); public static final ProtocolVersion v1_4_6; @@ -43,11 +47,9 @@ public class ProtocolVersion { public static final ProtocolVersion v1_16_1; public static final ProtocolVersion v1_16_2; public static final ProtocolVersion v1_16_3; + public static final ProtocolVersion v1_16_4; public static final ProtocolVersion unknown; - private final int id; - private final String name; - static { // Before netty rewrite register(v1_4_6 = new ProtocolVersion(51, "1.4.6")); @@ -87,18 +89,17 @@ public class ProtocolVersion { register(v1_16_1 = new ProtocolVersion(736, "1.16.1")); register(v1_16_2 = new ProtocolVersion(751, "1.16.2")); register(v1_16_3 = new ProtocolVersion(753, "1.16.3")); + register(v1_16_4 = new ProtocolVersion(754, 1, "1.16.4")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } - public ProtocolVersion(int id, String name) { - this.id = id; - this.name = name; - } - public static void register(ProtocolVersion protocol) { Preconditions.checkNotNull(protocol); - versions.put(protocol.getId(), protocol); + versions.put(protocol.id, protocol); + if (protocol.isSnapshot()) { + versions.put(protocol.getFullSnapshotId(), protocol); + } versionList.add(protocol); } @@ -125,30 +126,67 @@ public class ProtocolVersion { public static ProtocolVersion getClosest(String protocol) { for (ProtocolVersion version : versions.values()) { - if (version.getName().equals(protocol)) + String name = version.name; + if (name.equals(protocol) || name.equals(protocol + ".x")) { return version; - if (version.getName().equals(protocol + ".x")) - return version; - String[] parts = version.getName().split("-"); - for (String part : parts) { - if (part.equalsIgnoreCase(protocol)) { - return version; + } + + if (version.isRange()) { + String[] parts = name.split("-"); + for (String part : parts) { + if (part.equalsIgnoreCase(protocol) || part.equals(protocol + ".x")) { + return version; + } } - if (part.equals(protocol + ".x")) - return version; } } return null; } + private final int id; + private final int snapshotId; + private final String name; + + public ProtocolVersion(int id, String name) { + this(id, -1, name); + } + + public ProtocolVersion(int id, int snapshotId, String name) { + this.id = id; + this.snapshotId = snapshotId; + this.name = name; + } + public int getId() { return id; } + /** + * @return snapshot protocol version without the snapshot indicator bit, -1 if not a snapshot + */ + public int getSnapshotId() { + return snapshotId; + } + + /** + * @return snapshot protocol version with the hight bit indicating its snapshot status, -1 if not a snapshot + */ + public int getFullSnapshotId() { + return id == -1 ? -1 : (1 << 30) | snapshotId; // Bit indicating snapshot versions + } + public String getName() { return name; } + public boolean isSnapshot() { + return snapshotId != -1; + } + + public boolean isRange() { + return name.indexOf('-') != -1; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -165,6 +203,6 @@ public class ProtocolVersion { @Override public String toString() { - return String.format("%s(%d)", this.getName(), this.getId()); + return String.format("%s(%d)", this.name, this.id); } } 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 48d0db63a..c7cb191eb 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 @@ -27,26 +27,27 @@ public class BaseProtocol extends SimpleProtocol { @Override public void registerMap() { handler(wrapper -> { - int protVer = wrapper.passthrough(Type.VAR_INT); + int protocolVersion = wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.STRING); // Server Address wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port int state = wrapper.passthrough(Type.VAR_INT); ProtocolInfo info = wrapper.user().getProtocolInfo(); - info.setProtocolVersion(protVer); + info.setProtocolVersion(protocolVersion); // Ensure the server has a version provider if (Via.getManager().getProviders().get(VersionProvider.class) == null) { wrapper.user().setActive(false); return; } + // Choose the pipe - int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); - info.setServerProtocolVersion(protocol); + int serverProtocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); + info.setServerProtocolVersion(serverProtocol); List> protocols = null; // Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) - if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) { - protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol); + if (info.getProtocolVersion() >= serverProtocol || Via.getPlatform().isOldClientsAllowed()) { + protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), serverProtocol); } ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline(); @@ -56,11 +57,11 @@ public class BaseProtocol extends SimpleProtocol { // Ensure mapping data has already been loaded ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass()); } - wrapper.set(Type.VAR_INT, 0, protocol); + wrapper.set(Type.VAR_INT, 0, serverProtocol); } // Add Base Protocol - pipeline.add(ProtocolRegistry.getBaseProtocol(protocol)); + pipeline.add(ProtocolRegistry.getBaseProtocol(serverProtocol)); // Change state if (state == 1) { 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 09e2b0f1d..3a60bc781 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 @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.protocol.Protocol; 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.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -60,16 +61,21 @@ public class BaseProtocol1_7 extends SimpleProtocol { version = new JsonObject(); json.getAsJsonObject().add("version", version); } - if (Via.getConfig().isSendSupportedVersions()) //Send supported versions - version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions())); - if (ProtocolRegistry.SERVER_PROTOCOL == -1) // Set the Server protocol if the detection on startup failed - ProtocolRegistry.SERVER_PROTOCOL = protocolVersion; + if (Via.getConfig().isSendSupportedVersions()) { // Send supported versions + version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions())); + } + + if (ProtocolRegistry.SERVER_PROTOCOL == -1) { // Set the Server protocol if the detection on startup failed + ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getId(); + } + // Ensure the server has a version provider if (Via.getManager().getProviders().get(VersionProvider.class) == null) { wrapper.user().setActive(false); return; } + int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); List> protocols = null; @@ -88,8 +94,9 @@ public class BaseProtocol1_7 extends SimpleProtocol { wrapper.user().setActive(false); } - if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion())) + if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion())) { version.addProperty("protocol", -1); // Show blocked versions as outdated + } wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json)); // Update value } catch (JsonParseException e) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java index a2827538c..9e7ebeb32 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.base; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolPipeline; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.packets.State; import java.util.UUID; @@ -32,7 +33,9 @@ public class ProtocolInfo extends StoredObject { } public void setProtocolVersion(int protocolVersion) { - this.protocolVersion = protocolVersion; + // Map snapshot versions to the higher/orderer release version + ProtocolVersion protocol = ProtocolVersion.getProtocol(protocolVersion); + this.protocolVersion = protocol.getId(); } public int getServerProtocolVersion() { @@ -40,7 +43,8 @@ public class ProtocolInfo extends StoredObject { } public void setServerProtocolVersion(int serverProtocolVersion) { - this.serverProtocolVersion = serverProtocolVersion; + ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion); + this.serverProtocolVersion = protocol.getId(); } public String getUsername() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_4to1_16_3/Protocol1_16_4To1_16_3.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_4to1_16_3/Protocol1_16_4To1_16_3.java new file mode 100644 index 000000000..008e2572f --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_4to1_16_3/Protocol1_16_4To1_16_3.java @@ -0,0 +1,13 @@ +package us.myles.ViaVersion.protocols.protocol1_16_4to1_16_3; + +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; +import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2; + +public class Protocol1_16_4To1_16_3 extends Protocol { + + @Override + protected void registerPackets() { + + } +} diff --git a/fabric/pom.xml b/fabric/pom.xml index 9f83ddeca..c3c0d1c2a 100644 --- a/fabric/pom.xml +++ b/fabric/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/jar/pom.xml b/jar/pom.xml index b38fafd8b..8a847c01e 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index 4cfeb4caa..cdcd8d0d1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index 10e34b5d9..7323e6dbe 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index 0d3b60523..97c6e6858 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/velocity/pom.xml b/velocity/pom.xml index df84eff02..89b3dff24 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 3.2.0-SNAPSHOT + 3.2.0-1.16.4-pre1 4.0.0 diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/service/ProtocolDetectorService.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/service/ProtocolDetectorService.java index e7f68e798..a916363ff 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/service/ProtocolDetectorService.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/service/ProtocolDetectorService.java @@ -37,7 +37,7 @@ public class ProtocolDetectorService implements Runnable { } // Step 4: Use bungee lowest supported... *cries* try { - return Via.getManager().getInjector().getServerProtocolVersion(); + return ProtocolVersion.getProtocol(Via.getManager().getInjector().getServerProtocolVersion()).getId(); } catch (Exception e) { e.printStackTrace(); return ProtocolVersion.v1_8.getId();