From 515248fa99f100a64e0e7f92c9ee60ab6f4c80ad Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 30 Jul 2018 20:49:43 -0400 Subject: [PATCH] Expand the remapping stuff. --- .../protocol/remap/EntityIdRemapper.java | 2 +- .../remap/Minecraft18EntityIdRemapper.java | 40 +++++++++++++++++++ ...emapper.java => NoopEntityIdRemapper.java} | 6 +-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/velocitypowered/proxy/protocol/remap/Minecraft18EntityIdRemapper.java rename src/main/java/com/velocitypowered/proxy/protocol/remap/{DummyEntityIdRemapper.java => NoopEntityIdRemapper.java} (73%) diff --git a/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java b/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java index 8ba085948..ad277d762 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java @@ -24,6 +24,6 @@ public interface EntityIdRemapper { void setServerEntityId(int id); static EntityIdRemapper getMapper(int eid, int protocolVersion) { - return DummyEntityIdRemapper.INSTANCE; + return NoopEntityIdRemapper.INSTANCE; } } diff --git a/src/main/java/com/velocitypowered/proxy/protocol/remap/Minecraft18EntityIdRemapper.java b/src/main/java/com/velocitypowered/proxy/protocol/remap/Minecraft18EntityIdRemapper.java new file mode 100644 index 000000000..e1d186b01 --- /dev/null +++ b/src/main/java/com/velocitypowered/proxy/protocol/remap/Minecraft18EntityIdRemapper.java @@ -0,0 +1,40 @@ +package com.velocitypowered.proxy.protocol.remap; + +import com.velocitypowered.proxy.protocol.ProtocolConstants; +import io.netty.buffer.ByteBuf; + +public class Minecraft18EntityIdRemapper implements EntityIdRemapper { + private final int clientId; + private int serverId; + + public Minecraft18EntityIdRemapper(int clientId, int serverId) { + this.clientId = clientId; + this.serverId = serverId; + } + + @Override + public ByteBuf remap(ByteBuf original, ProtocolConstants.Direction direction) { + if (clientId == serverId) { + // If these are equal (i.e. first connection), no remapping is required. + return original.retain(); + } + + // TODO: Implement. + throw new UnsupportedOperationException("1.8 doesn't allow switching servers."); + } + + @Override + public int getClientEntityId() { + return clientId; + } + + @Override + public int getServerEntityId() { + return serverId; + } + + @Override + public void setServerEntityId(int id) { + this.serverId = id; + } +} diff --git a/src/main/java/com/velocitypowered/proxy/protocol/remap/DummyEntityIdRemapper.java b/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java similarity index 73% rename from src/main/java/com/velocitypowered/proxy/protocol/remap/DummyEntityIdRemapper.java rename to src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java index bd60ff333..f5a3b68f0 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/remap/DummyEntityIdRemapper.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java @@ -3,10 +3,10 @@ package com.velocitypowered.proxy.protocol.remap; import com.velocitypowered.proxy.protocol.ProtocolConstants; import io.netty.buffer.ByteBuf; -public class DummyEntityIdRemapper implements EntityIdRemapper { - public static final DummyEntityIdRemapper INSTANCE = new DummyEntityIdRemapper(); +public class NoopEntityIdRemapper implements EntityIdRemapper { + public static final NoopEntityIdRemapper INSTANCE = new NoopEntityIdRemapper(); - private DummyEntityIdRemapper() { + private NoopEntityIdRemapper() { }