mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Prepare hackery for 1.16.4
This commit is contained in:
parent
03ba058a9b
commit
6371b77b94
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
@ -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<Integer, ProtocolVersion> versions = new HashMap<>();
|
||||
private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
|
||||
private static final List<ProtocolVersion> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Pair<Integer, Protocol>> 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) {
|
||||
|
@ -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<Pair<Integer, Protocol>> 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) {
|
||||
|
@ -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() {
|
||||
|
@ -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<ClientboundPackets1_16_2, ClientboundPackets1_16_2, ServerboundPackets1_16_2, ServerboundPackets1_16_2> {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>viaversion-jar</name>
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>viaversion-parent</name>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<version>3.2.0-1.16.4-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user