diff --git a/api/src/main/java/com/viaversion/viaversion/api/connection/ConnectionManager.java b/api/src/main/java/com/viaversion/viaversion/api/connection/ConnectionManager.java index 7a1418baa..0a1faf523 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/connection/ConnectionManager.java +++ b/api/src/main/java/com/viaversion/viaversion/api/connection/ConnectionManager.java @@ -44,6 +44,8 @@ public interface ConnectionManager { /** * Frontend connections will have the UUID stored. Override this if your platform isn't always frontend. * UUIDs can't be duplicate between frontend connections. + * + * @return true if the user is a frontend connection */ boolean isFrontEnd(UserConnection connection); @@ -55,6 +57,8 @@ public interface ConnectionManager { *

* Note that connections are removed as soon as their channel is closed, * so avoid using this method during player quits for example. + * + * @return frontend UserConnection of the player connected to this proxy server */ @Nullable UserConnection getConnectedClient(UUID clientIdentifier); @@ -66,6 +70,8 @@ public interface ConnectionManager { *

* Note that connections are removed as soon as their channel is closed, * so avoid using this method during player quits for example. + * + * @return UUID of the frontend connection to this proxy server */ @Nullable UUID getConnectedClientId(UserConnection connection); @@ -75,6 +81,8 @@ public interface ConnectionManager { * May contain frontend, backend and/or client-sided connections. * When ViaVersion is reloaded, this method may not return some players. * May not contain ProtocolSupport players. + * + * @return connected UserConnections */ Set getConnections(); @@ -83,6 +91,8 @@ public interface ConnectionManager { * Returns empty list when there isn't a server * When ViaVersion is reloaded, this method may not return some players. * May not contain ProtocolSupport players. + * + * @return map containing the UUIDs and frontend UserConnections from players connected to this proxy server */ Map getConnectedClients(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java index b33a6cb6c..8efc828d2 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java +++ b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java @@ -186,9 +186,7 @@ public interface UserConnection { * * @return info containing the current protocol state and userdata */ - @Nullable ProtocolInfo getProtocolInfo(); - - void setProtocolInfo(@Nullable ProtocolInfo protocolInfo); + ProtocolInfo getProtocolInfo(); /** * Returns a map of stored objects. diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java index 75b7dc80e..60319fbf9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java @@ -139,11 +139,11 @@ public class MappingDataLoader { } } - public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { + public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { MappingDataLoader.mapIdentifiers(output, oldIdentifiers, newIdentifiers, null); } - public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) { + public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) { Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers); for (Map.Entry entry : oldIdentifiers.entrySet()) { int value = mapIdentifierEntry(entry, newIdentifierMap, diffIdentifiers); @@ -173,11 +173,11 @@ public class MappingDataLoader { return value; } - public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, boolean warnOnMissing) { + public static void mapIdentifiers(int[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, boolean warnOnMissing) { mapIdentifiers(output, oldIdentifiers, newIdentifiers, null, warnOnMissing); } - public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) { + public static void mapIdentifiers(int[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) { Object2IntMap newIdentifierMap = MappingDataLoader.arrayToMap(newIdentifiers); for (int i = 0; i < oldIdentifiers.size(); i++) { JsonElement oldIdentifier = oldIdentifiers.get(i); diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java index c669b4187..e5699f6e4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java @@ -29,9 +29,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Arrays; public class Mappings { - protected final short[] oldToNew; + protected final int[] oldToNew; - public Mappings(short[] oldToNew) { + public Mappings(int[] oldToNew) { this.oldToNew = oldToNew; } @@ -45,8 +45,8 @@ public class Mappings { * @param diffMapping extra mappings that will be used/scanned when an entry cannot be found */ public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) { - oldToNew = new short[size]; - Arrays.fill(oldToNew, (short) -1); + oldToNew = new int[size]; + Arrays.fill(oldToNew, -1); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping); } @@ -62,8 +62,8 @@ public class Mappings { * @param newMapping mappings to map to */ public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) { - oldToNew = new short[size]; - Arrays.fill(oldToNew, (short) -1); + oldToNew = new int[size]; + Arrays.fill(oldToNew, -1); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping); } @@ -81,8 +81,8 @@ public class Mappings { * @param warnOnMissing should "No key for x" be printed if there is no matching identifier */ public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) { - oldToNew = new short[size]; - Arrays.fill(oldToNew, (short) -1); + oldToNew = new int[size]; + Arrays.fill(oldToNew, -1); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing); } @@ -110,7 +110,7 @@ public class Mappings { return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; } - public short[] getOldToNew() { + public int[] getOldToNew() { return oldToNew; } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolPipeline.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolPipeline.java index 988445450..fa05b6b73 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolPipeline.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolPipeline.java @@ -76,6 +76,11 @@ public interface ProtocolPipeline extends SimpleProtocol { */ boolean filter(Object o, List list) throws Exception; + /** + * Returns the list of protocols this pipeline contains. + * + * @return list of protocols in this pipe + */ List pipes(); /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java index d06fd4b07..354b68bd9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java @@ -22,8 +22,6 @@ */ package com.viaversion.viaversion.api.protocol.packet; -import com.viaversion.viaversion.api.protocol.packet.PacketType; - /** * Interface to be implemented by server outgoing packet type enums, * representing PLAY state packets, ordered by their packet id. diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java index 5b66dd2e7..47fb8e333 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java @@ -22,8 +22,6 @@ */ package com.viaversion.viaversion.api.protocol.packet; -import com.viaversion.viaversion.api.protocol.packet.PacketType; - /** * Interface to be implemented by server incoming packet type enums, * representing PLAY state packets, ordered by their packet id. diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java index 7bdf86291..078580108 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java @@ -230,7 +230,6 @@ public class BungeeServerHandler implements Listener { plMsg.setTag(channel); } - user.setProtocolInfo(info); user.put(storage); user.setActive(protocolPath != null); diff --git a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java index 77f480f1f..8024834a8 100644 --- a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.connection; -import com.google.common.base.Preconditions; import com.google.common.cache.CacheBuilder; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.ProtocolInfo; @@ -58,9 +57,9 @@ public class UserConnectionImpl implements UserConnection { private final Set passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder() .expireAfterWrite(10, TimeUnit.SECONDS) .build().asMap()); + private final ProtocolInfo protocolInfo = new ProtocolInfoImpl(this); private final Channel channel; private final boolean clientSide; - private ProtocolInfo protocolInfo; private boolean active = true; private boolean pendingDisconnect; @@ -73,6 +72,7 @@ public class UserConnectionImpl implements UserConnection { public UserConnectionImpl(@Nullable Channel channel, boolean clientSide) { this.channel = channel; this.clientSide = clientSide; + storedObjects.put(ProtocolInfo.class, (StoredObject) protocolInfo); } /** @@ -313,21 +313,10 @@ public class UserConnectionImpl implements UserConnection { } @Override - public @Nullable ProtocolInfo getProtocolInfo() { + public ProtocolInfo getProtocolInfo() { return protocolInfo; } - @Override - public void setProtocolInfo(@Nullable ProtocolInfo protocolInfo) { - Preconditions.checkArgument(protocolInfo instanceof StoredObject, "ProtocolInfo has to extend StoredObject!"); - this.protocolInfo = protocolInfo; - if (protocolInfo != null) { - storedObjects.put(ProtocolInfo.class, (StoredObject) protocolInfo); - } else { - storedObjects.remove(ProtocolInfo.class); - } - } - @Override public Map, StoredObject> getStoredObjects() { return storedObjects; diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java index 4baa93765..d91a1e044 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java @@ -24,7 +24,6 @@ package com.viaversion.viaversion.protocol; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol; @@ -33,7 +32,6 @@ import com.viaversion.viaversion.api.protocol.base.Protocol; import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; -import com.viaversion.viaversion.connection.ProtocolInfoImpl; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; @@ -42,14 +40,15 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements ProtocolPipeline { + private final UserConnection userConnection; /** * Protocol list ordered from client to server transforation with the base protocols at the end. */ private List protocolList; - private UserConnection userConnection; public ProtocolPipelineImpl(UserConnection userConnection) { - init(userConnection); + this.userConnection = userConnection; + userConnection.getProtocolInfo().setPipeline(this); } @Override @@ -61,17 +60,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot @Override public void init(UserConnection userConnection) { - this.userConnection = userConnection; - - ProtocolInfo protocolInfo = new ProtocolInfoImpl(userConnection); - protocolInfo.setPipeline(this); - - userConnection.setProtocolInfo(protocolInfo); - - /* Init through all our pipes */ - for (Protocol protocol : protocolList) { - protocol.init(userConnection); - } + throw new UnsupportedOperationException("ProtocolPipeline can only be initialized once"); } @Override @@ -155,7 +144,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot @Override public boolean contains(Class pipeClass) { for (Protocol protocol : protocolList) { - if (protocol.getClass().equals(pipeClass)) return true; + if (protocol.getClass() == pipeClass) { + return true; + } } return false; } @@ -163,7 +154,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot @Override public @Nullable

P getProtocol(Class

pipeClass) { for (Protocol protocol : protocolList) { - if (protocol.getClass() == pipeClass) return (P) protocol; + if (protocol.getClass() == pipeClass) { + return (P) protocol; + } } return null; } @@ -187,7 +180,6 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot @Override public void cleanPipes() { - pipes().clear(); registerPackets(); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java index 4f7a6cd05..8075e87ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -67,7 +67,7 @@ public class MappingData extends com.viaversion.viaversion.api.data.MappingData // Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers if (Via.getConfig().isInfestedBlocksFix()) { - short[] oldToNew = blockMappings.getOldToNew(); + int[] oldToNew = blockMappings.getOldToNew(); oldToNew[1552] = 1; // stone oldToNew[1553] = 14; // cobblestone oldToNew[1554] = 3983; // stone bricks