From 529da106155d1587b7a89eb98169266d9ed07102 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sun, 7 Jun 2020 12:19:36 +0200 Subject: [PATCH] Move ProtocolInfo into its own field --- .../BukkitBlockConnectionProvider.java | 2 +- .../bukkit/handlers/BukkitPacketHandler.java | 2 +- .../multiversion/PlayerSneakListener.java | 2 +- .../bukkit/platform/BukkitViaAPI.java | 2 +- .../bukkit/platform/BukkitViaLoader.java | 4 ++-- .../BukkitInventoryQuickMoveProvider.java | 2 +- .../BukkitViaMovementTransmitter.java | 2 +- .../bungee/handlers/BungeeServerHandler.java | 10 +++++----- .../bungee/listeners/ElytraPatch.java | 2 +- .../bungee/platform/BungeeViaAPI.java | 2 +- .../providers/BungeeMainHandProvider.java | 2 +- .../providers/BungeeMovementTransmitter.java | 2 +- .../providers/BungeeVersionProvider.java | 2 +- .../myles/ViaVersion/api/PacketWrapper.java | 4 ++-- .../us/myles/ViaVersion/api/ViaListener.java | 2 +- .../ViaVersion/api/data/UserConnection.java | 20 ++++++++++++++++--- .../api/platform/ViaConnectionManager.java | 4 ++-- .../ViaVersion/api/protocol/Protocol.java | 12 ++++++++--- .../api/protocol/ProtocolPipeline.java | 8 ++++---- .../protocols/base/BaseProtocol.java | 4 ++-- .../protocols/base/BaseProtocol1_7.java | 6 +++--- .../TabCompleteThread.java | 4 ++-- .../AbstractFenceConnectionHandler.java | 2 +- .../GlassConnectionHandler.java | 2 +- .../types/Chunk1_9_1_2Type.java | 3 +-- .../protocol1_9to1_8/ViaIdleThread.java | 2 +- .../packets/PlayerPackets.java | 2 +- .../storage/EntityTracker1_9.java | 6 +++--- .../types/Chunk1_9to1_8Type.java | 2 +- .../sponge/handlers/SpongePacketHandler.java | 2 +- .../sponge/platform/SpongeViaAPI.java | 2 +- .../sponge/platform/SpongeViaLoader.java | 2 +- .../handlers/VelocityServerHandler.java | 12 +++++------ .../velocity/listeners/ElytraPatch.java | 2 +- .../velocity/platform/VelocityViaAPI.java | 2 +- .../VelocityMovementTransmitter.java | 3 +-- .../providers/VelocityVersionProvider.java | 3 +-- 37 files changed, 81 insertions(+), 66 deletions(-) diff --git a/bukkit-legacy/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java b/bukkit-legacy/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java index f97e06ff2..70837cd83 100644 --- a/bukkit-legacy/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java +++ b/bukkit-legacy/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java @@ -17,7 +17,7 @@ public class BukkitBlockConnectionProvider extends BlockConnectionProvider { @Override public int getWorldBlockData(UserConnection user, int bx, int by, int bz) { - UUID uuid = user.get(ProtocolInfo.class).getUuid(); + UUID uuid = user.getProtocolInfo().getUuid(); Player player = Bukkit.getPlayer(uuid); if (player != null) { World world = player.getWorld(); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitPacketHandler.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitPacketHandler.java index d3b352dac..44d94f6ba 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitPacketHandler.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitPacketHandler.java @@ -24,7 +24,7 @@ public class BukkitPacketHandler extends MessageToMessageEncoder { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { - if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { + if (info.getProtocolInfo().getPipeline().filter(o, list)) { return; } } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java index 45a66eb9a..a242d69c7 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java @@ -75,7 +75,7 @@ public class PlayerSneakListener extends ViaBukkitListener { Player player = event.getPlayer(); UserConnection userConnection = getUserConnection(player); if (userConnection == null) return; - ProtocolInfo info = userConnection.get(ProtocolInfo.class); + ProtocolInfo info = userConnection.getProtocolInfo(); if (info == null) return; int protocolVersion = info.getProtocolVersion(); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java index d5b623b1b..8678e47ec 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java @@ -35,7 +35,7 @@ public class BukkitViaAPI implements ViaAPI { public int getPlayerVersion(UUID uuid) { if (!isInjected(uuid)) return getExternalVersion(Bukkit.getPlayer(uuid)); - return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion(); + return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion(); } private int getExternalVersion(Player player) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index 7c80e7652..f8595f23b 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -120,11 +120,11 @@ public class BukkitViaLoader implements ViaPlatformLoader { @Override public Item getHandItem(final UserConnection info) { if (handItemCache != null) { - return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); + return handItemCache.getHandItem(info.getProtocolInfo().getUuid()); } try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), () -> { - UUID playerUUID = info.get(ProtocolInfo.class).getUuid(); + UUID playerUUID = info.getProtocolInfo().getUuid(); Player player = Bukkit.getPlayer(playerUUID); if (player != null) { return HandItemCache.convert(player.getItemInHand()); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index 0fbcf42fc..d5e740090 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -63,7 +63,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider } } } - ProtocolInfo info = userConnection.get(ProtocolInfo.class); + ProtocolInfo info = userConnection.getProtocolInfo(); UUID uuid = info.getUuid(); BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid); final boolean registered = updateTask != null; diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitViaMovementTransmitter.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitViaMovementTransmitter.java index 4c9147d98..c1d95ca89 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitViaMovementTransmitter.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitViaMovementTransmitter.java @@ -81,7 +81,7 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider { @Override public void sendPlayer(UserConnection info) { if (USE_NMS) { - Player player = Bukkit.getPlayer(info.get(ProtocolInfo.class).getUuid()); + Player player = Bukkit.getPlayer(info.getProtocolInfo().getUuid()); if (player != null) { try { // Tick player diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java index 3a3ebda12..96e27e21e 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java @@ -77,13 +77,13 @@ public class BungeeServerHandler implements Listener { } int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); - List> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); + List> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId); // Check if ViaVersion can support that version try { //Object pendingConnection = getPendingConnection.invoke(e.getPlayer()); Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection()); - setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId); + setProtocol.invoke(handshake, protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId); } catch (InvocationTargetException | IllegalAccessException e1) { e1.printStackTrace(); } @@ -145,7 +145,7 @@ public class BungeeServerHandler implements Listener { if (storage.getBossbar() != null) { // TODO: Verify whether this packet needs to be sent when 1.8 -> 1.9 protocol isn't present in the pipeline // This ensures we can encode it properly as only the 1.9 protocol is currently implemented. - if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) { + if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { for (UUID uuid : storage.getBossbar()) { PacketWrapper wrapper = new PacketWrapper(0x0C, null, user); wrapper.write(Type.UUID, uuid); @@ -157,12 +157,12 @@ public class BungeeServerHandler implements Listener { } } - ProtocolInfo info = user.get(ProtocolInfo.class); + ProtocolInfo info = user.getProtocolInfo(); int previousServerProtocol = info.getServerProtocolVersion(); // Refresh the pipes List> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); - ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); + ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/ElytraPatch.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/ElytraPatch.java index b9dc05121..8a61369e8 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/ElytraPatch.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/ElytraPatch.java @@ -28,7 +28,7 @@ public class ElytraPatch implements Listener { if (user == null) return; try { - if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) { + if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java index c41583531..7770fba8c 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java @@ -26,7 +26,7 @@ public class BungeeViaAPI implements ViaAPI { if (conn == null) { return player.getPendingConnection().getVersion(); } - return conn.get(ProtocolInfo.class).getProtocolVersion(); + return conn.getProtocolInfo().getProtocolVersion(); } @Override diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMainHandProvider.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMainHandProvider.java index c2bbf36be..67bcc31d4 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMainHandProvider.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMainHandProvider.java @@ -26,7 +26,7 @@ public class BungeeMainHandProvider extends MainHandProvider { @Override public void setMainHand(UserConnection user, int hand) { - ProtocolInfo info = user.get(ProtocolInfo.class); + ProtocolInfo info = user.getProtocolInfo(); if (info == null || info.getUuid() == null) return; ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getUuid()); if (player == null) return; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java index 90928ea64..72515f78e 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java @@ -21,7 +21,7 @@ public class BungeeMovementTransmitter extends MovementTransmitterProvider { } public void sendPlayer(UserConnection userConnection) { - if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { + if (userConnection.getProtocolInfo().getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java index 73370cf89..188e5f3b3 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java @@ -34,7 +34,7 @@ public class BungeeVersionProvider extends VersionProvider { List sorted = new ArrayList<>(list); Collections.sort(sorted); - ProtocolInfo info = user.get(ProtocolInfo.class); + ProtocolInfo info = user.getProtocolInfo(); // Bungee supports it if (sorted.contains(info.getProtocolVersion())) diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index df813e6bf..b6929569a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -319,7 +319,7 @@ public class PacketWrapper { */ private ByteBuf constructPacket(Class packetProtocol, boolean skipCurrentPipeline, Direction direction) throws Exception { // Apply current pipeline - List protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); + List protocols = new ArrayList<>(user().getProtocolInfo().getPipeline().pipes()); if (direction == Direction.OUTGOING) { // Other way if outgoing Collections.reverse(protocols); @@ -337,7 +337,7 @@ public class PacketWrapper { resetReader(); // Apply other protocols - apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols); + apply(direction, user().getProtocolInfo().getState(), index, protocols); // Send ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); writeToBuffer(output); diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java index 149db8083..50d692779 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java @@ -35,7 +35,7 @@ public abstract class ViaListener { protected boolean isOnPipe(UUID uuid) { UserConnection userConnection = getUserConnection(uuid); return userConnection != null && - (requiredPipeline == null || userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline)); + (requiredPipeline == null || userConnection.getProtocolInfo().getPipeline().contains(requiredPipeline)); } /** diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java index dd38bd72b..9e829bce8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java @@ -26,6 +26,7 @@ public class UserConnection { private static final AtomicLong IDS = new AtomicLong(); private final long id = IDS.incrementAndGet(); private final Channel channel; + private ProtocolInfo protocolInfo; Map storedObjects = new ConcurrentHashMap<>(); private boolean active = true; private boolean pendingDisconnect; @@ -193,7 +194,7 @@ public class UserConnection { if (!channel.isOpen() || pendingDisconnect) return; pendingDisconnect = true; - UUID uuid = get(ProtocolInfo.class).getUuid(); + UUID uuid = protocolInfo.getUuid(); if (uuid == null) { channel.close(); // Just disconnect, we don't know what the connection is return; @@ -318,9 +319,8 @@ public class UserConnection { if (id == PacketWrapper.PASSTHROUGH_ID) return; PacketWrapper wrapper = new PacketWrapper(id, draft, this); - ProtocolInfo protInfo = get(ProtocolInfo.class); try { - protInfo.getPipeline().transform(direction, protInfo.getState(), wrapper); + protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper); } catch (CancelException ex) { throw cancelSupplier.apply(ex); } @@ -343,6 +343,20 @@ public class UserConnection { return channel; } + @Nullable + public ProtocolInfo getProtocolInfo() { + return protocolInfo; + } + + public void setProtocolInfo(@Nullable ProtocolInfo protocolInfo) { + this.protocolInfo = protocolInfo; + if (protocolInfo != null) { + storedObjects.put(ProtocolInfo.class, protocolInfo); + } else { + storedObjects.remove(ProtocolInfo.class); + } + } + public Map getStoredObjects() { return storedObjects; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java index 82649612e..77607708a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java @@ -17,7 +17,7 @@ public class ViaConnectionManager { public void onLoginSuccess(UserConnection connection) { Objects.requireNonNull(connection, "connection is null!"); - UUID id = connection.get(ProtocolInfo.class).getUuid(); + UUID id = connection.getProtocolInfo().getUuid(); connections.add(connection); clients.put(id, connection); @@ -28,7 +28,7 @@ public class ViaConnectionManager { public void onDisconnect(UserConnection connection) { Objects.requireNonNull(connection, "connection is null!"); - UUID id = connection.get(ProtocolInfo.class).getUuid(); + UUID id = connection.getProtocolInfo().getUuid(); connections.remove(connection); clients.remove(id); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index f2055f593..8dc7572a9 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.base.Preconditions; +import jdk.nashorn.internal.ir.CallNode; import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; @@ -422,14 +423,14 @@ public abstract class Protocol packetTypeClass = direction == Direction.OUTGOING ? oldClientboundPacketEnum : newServerboundPacketEnum; + Class packetTypeClass = state == State.PLAY ? (direction == Direction.OUTGOING ? oldClientboundPacketEnum : newServerboundPacketEnum) : null; if (packetTypeClass != null) { PacketType[] enumConstants = packetTypeClass.getEnumConstants(); PacketType packetType = oldId < enumConstants.length && oldId >= 0 ? enumConstants[oldId] : null; - Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + oldId + ")"); + Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(oldId) + ")"); } else { Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() - + " IN REMAP OF 0x" + Integer.toHexString(oldId) + "->0x" + Integer.toHexString(newId)); + + " IN REMAP OF 0x" + toNiceHex(oldId) + "->0x" + toNiceHex(newId)); } throw e; } @@ -439,6 +440,11 @@ public abstract class Protocol {5} (0x{6}) [{7}] {8}", 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 35afc80d8..139640bd8 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 @@ -38,7 +38,7 @@ public class BaseProtocol extends SimpleProtocol { int protVer = wrapper.get(Type.VAR_INT, 0); int state = wrapper.get(Type.VAR_INT, 1); - ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); + ProtocolInfo info = wrapper.user().getProtocolInfo(); info.setProtocolVersion(protVer); // Ensure the server has a version provider if (Via.getManager().getProviders().get(VersionProvider.class) == null) { @@ -55,7 +55,7 @@ public class BaseProtocol extends SimpleProtocol { protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol); } - ProtocolPipeline pipeline = wrapper.user().get(ProtocolInfo.class).getPipeline(); + ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline(); if (protocols != null) { for (Pair prot : protocols) { pipeline.add(prot.getValue()); 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 7e20f0f2b..0cbf7b93a 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 @@ -38,7 +38,7 @@ public class BaseProtocol1_7 extends SimpleProtocol { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); + ProtocolInfo info = wrapper.user().getProtocolInfo(); String originalStatus = wrapper.get(Type.STRING, 0); try { JsonElement json = GsonUtil.getGson().fromJson(originalStatus, JsonElement.class); @@ -113,7 +113,7 @@ public class BaseProtocol1_7 extends SimpleProtocol { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); + ProtocolInfo info = wrapper.user().getProtocolInfo(); info.setState(State.PLAY); if (info.getServerProtocolVersion() >= ProtocolVersion.v1_16.getId()) { @@ -170,7 +170,7 @@ public class BaseProtocol1_7 extends SimpleProtocol { handler(new PacketHandler() { @Override public void handle(final PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion(); + int protocol = wrapper.user().getProtocolInfo().getProtocolVersion(); if (Via.getConfig().getBlockedProtocols().contains(protocol)) { if (!wrapper.user().getChannel().isOpen()) return; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java index 57971b5cd..52bf034fe 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/TabCompleteThread.java @@ -2,14 +2,14 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker; public class TabCompleteThread implements Runnable { @Override public void run() { for (UserConnection info : Via.getManager().getConnections()) { - if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) { + if (info.getProtocolInfo() == null) continue; + if (info.getProtocolInfo().getPipeline().contains(Protocol1_13To1_12_2.class)) { if (info.getChannel().isOpen()) { info.get(TabCompleteTracker.class).sendPacketToServer(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java index 36889ec4c..feeac1729 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java @@ -44,7 +44,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { protected byte getStates(UserConnection user, Position position, int blockState) { byte states = 0; - boolean pre1_12 = user.get(ProtocolInfo.class).getServerProtocolVersion() < ProtocolVersion.v1_12.getId(); + boolean pre1_12 = user.getProtocolInfo().getServerProtocolVersion() < ProtocolVersion.v1_12.getId(); if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1; if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2; if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java index 79c3d62e0..0f4ce4af3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java @@ -41,7 +41,7 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler { byte states = super.getStates(user, position, blockState); if (states != 0) return states; - ProtocolInfo protocolInfo = user.get(ProtocolInfo.class); + ProtocolInfo protocolInfo = user.getProtocolInfo(); return protocolInfo.getServerProtocolVersion() <= 47 && protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java index 2dbfc8702..c0303836c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java @@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType; import us.myles.ViaVersion.api.type.types.version.Types1_9; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -26,7 +25,7 @@ public class Chunk1_9_1_2Type extends PartialType { @Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { - boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); + boolean replacePistons = world.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId(); int chunkX = input.readInt(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java index 497eaebfa..852483601 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java @@ -10,7 +10,7 @@ public class ViaIdleThread implements Runnable { @Override public void run() { for (UserConnection info : Via.getManager().getConnections()) { - ProtocolInfo protocolInfo = info.get(ProtocolInfo.class); + ProtocolInfo protocolInfo = info.getProtocolInfo(); if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index eb22c7892..87a408af3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -126,7 +126,7 @@ public class PlayerPackets { if (mode == 0 || mode == 3 || mode == 4) { String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); - String myName = wrapper.user().get(ProtocolInfo.class).getUsername(); + String myName = wrapper.user().getProtocolInfo().getUsername(); String teamName = wrapper.get(Type.STRING, 0); for (String player : players) { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index 82489026d..a4b21b775 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -191,7 +191,7 @@ public class EntityTracker1_9 extends EntityTracker { } } } - UUID uuid = getUser().get(ProtocolInfo.class).getUuid(); + UUID uuid = getUser().getProtocolInfo().getUuid(); // Boss bar if (Via.getConfig().isBossbarPatch()) { if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) { @@ -256,7 +256,7 @@ public class EntityTracker1_9 extends EntityTracker { } else { wrapper.write(Type.BYTE, (byte) 3); } - wrapper.write(Type.STRING_ARRAY, new String[]{getUser().get(ProtocolInfo.class).getUsername()}); + wrapper.write(Type.STRING_ARRAY, new String[]{getUser().getProtocolInfo().getUsername()}); } else { wrapper.write(Type.BYTE, (byte) 1); // remove team } @@ -283,7 +283,7 @@ public class EntityTracker1_9 extends EntityTracker { PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser()); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, metadataList); - getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class) + getUser().getProtocolInfo().getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class) .handleMetadata(entityId, metadataList, getUser()); handleMetadata(entityId, metadataList); if (!metadataList.isEmpty()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java index 455ee4c58..d1428b06c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java @@ -48,7 +48,7 @@ public class Chunk1_9to1_8Type extends PartialType { @Override public Chunk read(ByteBuf input, ClientChunks param) throws Exception { - boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); + boolean replacePistons = param.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId(); int chunkX = input.readInt(); diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongePacketHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongePacketHandler.java index 905685c7e..220d34f78 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongePacketHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongePacketHandler.java @@ -24,7 +24,7 @@ public class SpongePacketHandler extends MessageToMessageEncoder { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { - if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { + if (info.getProtocolInfo().getPipeline().filter(o, list)) { return; } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java index 559481893..08aa32b2f 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java @@ -26,7 +26,7 @@ public class SpongeViaAPI implements ViaAPI { public int getPlayerVersion(UUID uuid) { if (!isInjected(uuid)) return ProtocolRegistry.SERVER_PROTOCOL; - return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion(); + return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion(); } @Override diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java index e73a8b7df..93f6fffc6 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java @@ -76,7 +76,7 @@ public class SpongeViaLoader implements ViaPlatformLoader { @Override public Item getHandItem(final UserConnection info) { if (HandItemCache.CACHE) { - return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); + return HandItemCache.getHandItem(info.getProtocolInfo().getUuid()); } else { return super.getHandItem(info); } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java index f20814eb4..e474e5c87 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java @@ -26,8 +26,6 @@ import java.util.Collection; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; public class VelocityServerHandler { private static Method setProtocolVersion; @@ -62,12 +60,12 @@ public class VelocityServerHandler { } int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName()); - List> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); + List> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId); // Check if ViaVersion can support that version Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null - ? user.get(ProtocolInfo.class).getProtocolVersion() + ? user.getProtocolInfo().getProtocolVersion() : protocolId)); } catch (IllegalAccessException | InvocationTargetException e1) { @@ -105,7 +103,7 @@ public class VelocityServerHandler { if (storage.getBossbar() != null) { // TODO: Verify whether this packet needs to be sent when 1.8 -> 1.9 protocol isn't present in the pipeline // This ensures we can encode it properly as only the 1.9 protocol is currently implemented. - if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) { + if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { for (UUID uuid : storage.getBossbar()) { PacketWrapper wrapper = new PacketWrapper(0x0C, null, user); wrapper.write(Type.UUID, uuid); @@ -117,12 +115,12 @@ public class VelocityServerHandler { } } - ProtocolInfo info = user.get(ProtocolInfo.class); + ProtocolInfo info = user.getProtocolInfo(); int previousServerProtocol = info.getServerProtocolVersion(); // Refresh the pipes List> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); - ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); + ProtocolPipeline pipeline = info.getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/listeners/ElytraPatch.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/listeners/ElytraPatch.java index 194a86600..78cc94b9d 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/listeners/ElytraPatch.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/listeners/ElytraPatch.java @@ -27,7 +27,7 @@ public class ElytraPatch { if (user == null) return; try { - if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) { + if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java index be09a5c8f..b58b2cc7b 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java @@ -22,7 +22,7 @@ public class VelocityViaAPI implements ViaAPI { public int getPlayerVersion(Player player) { if (!isInjected(player.getUniqueId())) return player.getProtocolVersion().getProtocol(); - return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); + return Via.getManager().getConnection(player.getUniqueId()).getProtocolInfo().getProtocolVersion(); } @Override diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityMovementTransmitter.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityMovementTransmitter.java index affbe2b06..831b97653 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityMovementTransmitter.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityMovementTransmitter.java @@ -4,7 +4,6 @@ import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; @@ -21,7 +20,7 @@ public class VelocityMovementTransmitter extends MovementTransmitterProvider { } public void sendPlayer(UserConnection userConnection) { - if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { + if (userConnection.getProtocolInfo().getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java index 7f7f786c9..4f1984c12 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java @@ -4,7 +4,6 @@ import us.myles.ViaVersion.VelocityPlugin; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolVersion; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.velocity.platform.VelocityViaInjector; @@ -15,7 +14,7 @@ public class VelocityVersionProvider extends VersionProvider { @Override public int getServerProtocol(UserConnection user) throws Exception { - int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion(); + int playerVersion = user.getProtocolInfo().getProtocolVersion(); IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream() .mapToInt(com.velocitypowered.api.network.ProtocolVersion::getProtocol);