From c1147cb9f73385b0f429b8d7ceef8a72f7511fc8 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 5 Dec 2018 19:08:55 +0000 Subject: [PATCH] Formatting --- .travis.yml | 2 +- .../protocol1_9to1_8/DeathListener.java | 2 +- .../bukkit/platform/BukkitViaConfig.java | 2 +- .../bungee/platform/BungeeViaConfig.java | 2 +- .../ViaVersion/api/data/UserConnection.java | 6 +- .../ViaVersion/api/minecraft/BlockFace.java | 37 +-- .../api/minecraft/chunks/BaseChunk.java | 22 +- .../api/minecraft/chunks/ChunkSection.java | 34 +-- .../api/protocol/ProtocolRegistry.java | 6 +- .../types/version/Metadata1_13_2Type.java | 34 +-- .../api/type/types/version/Types1_13_2.java | 16 +- .../protocol1_11to1_10/MetadataRewriter.java | 2 +- .../TranslateRewriter.java | 4 +- .../Protocol1_13_2To1_13_1.java | 108 ++++---- .../packets/EntityPackets.java | 146 +++++------ .../packets/InventoryPackets.java | 238 +++++++++--------- .../packets/WorldPackets.java | 54 ++-- .../AbstractFenceConnectionHandler.java | 2 +- .../blockconnections/BlockData.java | 4 +- .../ChestConnectionHandler.java | 90 +++---- .../blockconnections/ConnectionHandler.java | 8 +- .../RedstoneConnectionHandler.java | 14 +- .../TripwireConnectionHandler.java | 134 +++++----- .../WallConnectionHandler.java | 9 +- .../providers/BlockConnectionProvider.java | 18 +- .../packets/WorldPackets.java | 2 +- .../storage/BlockConnectionStorage.java | 17 +- .../protocol1_9to1_8/ItemRewriter.java | 4 +- .../packets/WorldPackets.java | 6 +- .../storage/EntityTracker.java | 2 +- .../types/Chunk1_9to1_8Type.java | 2 +- .../sponge/platform/SpongeViaConfig.java | 2 +- .../SpongeBlockConnectionProvider.java | 2 +- .../handlers/VelocityServerHandler.java | 6 +- .../service/ProtocolDetectorService.java | 28 +-- 35 files changed, 541 insertions(+), 524 deletions(-) diff --git a/.travis.yml b/.travis.yml index 72420f027..50fdf3578 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: java -jdk: +jdk: - oraclejdk8 - openjdk11 diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/DeathListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/DeathListener.java index 164ffb394..de1f0d110 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/DeathListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/DeathListener.java @@ -38,7 +38,7 @@ public class DeathListener extends ViaBukkitListener { @Override public void run() { // If online - if(getUserConnection(p) != null) { + if (getUserConnection(p) != null) { PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p)); try { wrapper.write(Type.VAR_INT, 2); // Event - Entity dead diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java index 467be57d4..056fa2abb 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java @@ -164,7 +164,7 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } - + @Override public boolean is1_12QuickMoveActionFix() { return getBoolean("quick-move-action-fix", false); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index 9acbd7b03..99a307c0b 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -203,7 +203,7 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } - + @Override public boolean is1_12QuickMoveActionFix() { return false; 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 a620c3798..566240937 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 @@ -208,7 +208,7 @@ public class UserConnection { /** * Sends a raw packet to the server * - * @param packet Raw packet to be sent + * @param packet Raw packet to be sent * @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop */ public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) { @@ -248,5 +248,7 @@ public class UserConnection { * * @param packet Raw packet to be sent */ - public void sendRawPacketToServer(ByteBuf packet) { sendRawPacketToServer(packet, false); } + public void sendRawPacketToServer(ByteBuf packet) { + sendRawPacketToServer(packet, false); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java index 888aa1ea1..b63ea78b8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java @@ -9,26 +9,27 @@ import java.util.Map; @Getter @AllArgsConstructor public enum BlockFace { - NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y); + NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y); - private static Map opposites = new HashMap<>(); - static { - opposites.put(BlockFace.NORTH, BlockFace.SOUTH); - opposites.put(BlockFace.SOUTH, BlockFace.NORTH); - opposites.put(BlockFace.EAST, BlockFace.WEST); - opposites.put(BlockFace.WEST, BlockFace.EAST); - opposites.put(BlockFace.TOP, BlockFace.BOTTOM); - opposites.put(BlockFace.BOTTOM, BlockFace.TOP); - } + private static Map opposites = new HashMap<>(); - private int modX, modY, modZ; - private EnumAxis axis; + static { + opposites.put(BlockFace.NORTH, BlockFace.SOUTH); + opposites.put(BlockFace.SOUTH, BlockFace.NORTH); + opposites.put(BlockFace.EAST, BlockFace.WEST); + opposites.put(BlockFace.WEST, BlockFace.EAST); + opposites.put(BlockFace.TOP, BlockFace.BOTTOM); + opposites.put(BlockFace.BOTTOM, BlockFace.TOP); + } - public BlockFace opposite() { - return opposites.get(this); - } + private int modX, modY, modZ; + private EnumAxis axis; - public enum EnumAxis { - X, Y, Z; - } + public BlockFace opposite() { + return opposites.get(this); + } + + public enum EnumAxis { + X, Y, Z; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java index fa5e66e67..9df4980e2 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java @@ -9,16 +9,16 @@ import java.util.List; @AllArgsConstructor @Data public class BaseChunk implements Chunk { - protected int x; - protected int z; - protected boolean groundUp; - protected int bitmask; - protected ChunkSection[] sections; - protected int[] biomeData; - protected List blockEntities; + protected int x; + protected int z; + protected boolean groundUp; + protected int bitmask; + protected ChunkSection[] sections; + protected int[] biomeData; + protected List blockEntities; - @Override - public boolean isBiomeData() { - return biomeData != null; - } + @Override + public boolean isBiomeData() { + return biomeData != null; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 9305a5994..cd102fdef 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -98,22 +98,22 @@ public class ChunkSection { } public void replacePaletteEntry(int oldId, int newId) { - Integer index = inversePalette.remove(oldId); - if (index == null) return; - inversePalette.put(newId, index); - for (int i = 0; i < palette.size(); i++) { - if (palette.get(i) == oldId) palette.set(i, newId); - } + Integer index = inversePalette.remove(oldId); + if (index == null) return; + inversePalette.put(newId, index); + for (int i = 0; i < palette.size(); i++) { + if (palette.get(i) == oldId) palette.set(i, newId); + } } public void addPaletteEntry(int id) { - inversePalette.put(id, palette.size()); - palette.add(id); + inversePalette.put(id, palette.size()); + palette.add(id); } public void clearPalette() { - palette.clear(); - inversePalette.clear(); + palette.clear(); + inversePalette.clear(); } /** @@ -124,14 +124,14 @@ public class ChunkSection { * @param id The raw or flat id of the block */ public void setFlatBlock(int idx, int id) { - Integer index = inversePalette.get(id); - if (index == null) { - index = palette.size(); - palette.add(id); - inversePalette.put(id, index); - } + Integer index = inversePalette.get(id); + if (index == null) { + index = palette.size(); + palette.add(id); + inversePalette.put(id, index); + } - blocks[idx] = index; + blocks[idx] = index; } /** 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 76de968b7..397320c8e 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 @@ -57,8 +57,8 @@ public class ProtocolRegistry { registerProtocol(new Protocol1_12_2TO1_12_1(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_12_1.getId()); registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId()); - registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId()); - registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId()); + registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId()); + registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId()); } /** @@ -95,7 +95,7 @@ public class ProtocolRegistry { * Base Protocols registered later have higher priority * Only one base protocol will be added to pipeline * - * @param baseProtocol Base Protocol to register + * @param baseProtocol Base Protocol to register * @param supportedProtocols Versions that baseProtocol supports */ public static void registerBaseProtocol(Protocol baseProtocol, Range supportedProtocols) { diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java index 608547c0f..468ec6b00 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java @@ -6,24 +6,24 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2; import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; public class Metadata1_13_2Type extends MetaTypeTemplate { - @Override - public Metadata read(ByteBuf buffer) throws Exception { - short index = buffer.readUnsignedByte(); + @Override + public Metadata read(ByteBuf buffer) throws Exception { + short index = buffer.readUnsignedByte(); - if (index == 0xff) return null; //End of metadata - MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte()); + if (index == 0xff) return null; //End of metadata + MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte()); - return new Metadata(index, type, type.getType().read(buffer)); - } + return new Metadata(index, type, type.getType().read(buffer)); + } - @Override - public void write(ByteBuf buffer, Metadata object) throws Exception { - if (object == null) { - buffer.writeByte(255); - } else { - buffer.writeByte(object.getId()); - buffer.writeByte(object.getMetaType().getTypeID()); - object.getMetaType().getType().write(buffer, object.getValue()); - } - } + @Override + public void write(ByteBuf buffer, Metadata object) throws Exception { + if (object == null) { + buffer.writeByte(255); + } else { + buffer.writeByte(object.getId()); + buffer.writeByte(object.getMetaType().getTypeID()); + object.getMetaType().getType().write(buffer, object.getValue()); + } + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java index 0f3a40173..643f2efb2 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java @@ -6,13 +6,13 @@ import us.myles.ViaVersion.api.type.Type; import java.util.List; public class Types1_13_2 { - /** - * Metadata list type for 1.13 - */ - public static final Type> METADATA_LIST = new MetadataList1_13_2Type(); + /** + * Metadata list type for 1.13 + */ + public static final Type> METADATA_LIST = new MetadataList1_13_2Type(); - /** - * Metadata type for 1.13 - */ - public static final Type METADATA = new Metadata1_13_2Type(); + /** + * Metadata type for 1.13 + */ + public static final Type METADATA = new Metadata1_13_2Type(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/MetadataRewriter.java index 4e62fd061..224f63dc7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/MetadataRewriter.java @@ -100,7 +100,7 @@ public class MetadataRewriter { public static void handleMetadata(int entityId, EntityType type, List metadatas, UserConnection connection) { for (Metadata metadata : new ArrayList<>(metadatas)) { try { - if(metadata.getValue() instanceof Item) { + if (metadata.getValue() instanceof Item) { // Apply rewrite EntityIdRewriter.toClientItem((Item) metadata.getValue()); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java index 4a09752c1..982cb39b7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java @@ -8,8 +8,8 @@ public class TranslateRewriter { public static boolean toClient(JsonElement element, UserConnection user) { if (element instanceof JsonObject) { JsonObject obj = (JsonObject) element; - if(obj.has("translate")) { - if(obj.get("translate").getAsString().equals("chat.type.achievement")) { + if (obj.has("translate")) { + if (obj.get("translate").getAsString().equals("chat.type.achievement")) { return false; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java index 19394f359..b036dee34 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java @@ -14,68 +14,68 @@ import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.WorldPackets import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types.Particle1_13_2Type; public class Protocol1_13_2To1_13_1 extends Protocol { - public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type(); + public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type(); - @Override - protected void registerPackets() { - InventoryPackets.register(this); - WorldPackets.register(this); - EntityPackets.register(this); + @Override + protected void registerPackets() { + InventoryPackets.register(this); + WorldPackets.register(this); + EntityPackets.register(this); - //Edit Book - registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); - } - }); + //Edit Book + registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); + } + }); - // Advancements - registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.passthrough(Type.BOOLEAN); // Reset/clear - int size = wrapper.passthrough(Type.VAR_INT); // Mapping size + // Advancements + registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.passthrough(Type.BOOLEAN); // Reset/clear + int size = wrapper.passthrough(Type.VAR_INT); // Mapping size - for (int i = 0; i < size; i++) { - wrapper.passthrough(Type.STRING); // Identifier + for (int i = 0; i < size; i++) { + wrapper.passthrough(Type.STRING); // Identifier - // Parent - if (wrapper.passthrough(Type.BOOLEAN)) - wrapper.passthrough(Type.STRING); + // Parent + if (wrapper.passthrough(Type.BOOLEAN)) + wrapper.passthrough(Type.STRING); - // Display data - if (wrapper.passthrough(Type.BOOLEAN)) { - wrapper.passthrough(Type.STRING); // Title - wrapper.passthrough(Type.STRING); // Description - Item icon = wrapper.read(Type.FLAT_ITEM); - wrapper.write(Type.FLAT_VAR_INT_ITEM, icon); - wrapper.passthrough(Type.VAR_INT); // Frame type - int flags = wrapper.passthrough(Type.INT); // Flags - if ((flags & 1) != 0) - wrapper.passthrough(Type.STRING); // Background texture - wrapper.passthrough(Type.FLOAT); // X - wrapper.passthrough(Type.FLOAT); // Y - } + // Display data + if (wrapper.passthrough(Type.BOOLEAN)) { + wrapper.passthrough(Type.STRING); // Title + wrapper.passthrough(Type.STRING); // Description + Item icon = wrapper.read(Type.FLAT_ITEM); + wrapper.write(Type.FLAT_VAR_INT_ITEM, icon); + wrapper.passthrough(Type.VAR_INT); // Frame type + int flags = wrapper.passthrough(Type.INT); // Flags + if ((flags & 1) != 0) + wrapper.passthrough(Type.STRING); // Background texture + wrapper.passthrough(Type.FLOAT); // X + wrapper.passthrough(Type.FLOAT); // Y + } - wrapper.passthrough(Type.STRING_ARRAY); // Criteria + wrapper.passthrough(Type.STRING_ARRAY); // Criteria - int arrayLength = wrapper.passthrough(Type.VAR_INT); - for (int array = 0; array < arrayLength; array++) { - wrapper.passthrough(Type.STRING_ARRAY); // String array - } - } - } - }); - } - }); - } + int arrayLength = wrapper.passthrough(Type.VAR_INT); + for (int array = 0; array < arrayLength; array++) { + wrapper.passthrough(Type.STRING_ARRAY); // String array + } + } + } + }); + } + }); + } - @Override - public void init(UserConnection userConnection) { + @Override + public void init(UserConnection userConnection) { - } + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java index 5076c268f..b44b505c6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java @@ -14,84 +14,84 @@ import us.myles.ViaVersion.packets.State; public class EntityPackets { - public static void register(Protocol protocol) { - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Entity UUID - map(Type.VAR_INT); // 2 - Entity Type - map(Type.DOUBLE); // 3 - X - map(Type.DOUBLE); // 4 - Y - map(Type.DOUBLE); // 5 - Z - map(Type.BYTE); // 6 - Yaw - map(Type.BYTE); // 7 - Pitch - map(Type.BYTE); // 8 - Head Pitch - map(Type.SHORT); // 9 - Velocity X - map(Type.SHORT); // 10 - Velocity Y - map(Type.SHORT); // 11 - Velocity Z - map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata + public static void register(Protocol protocol) { + // Spawn mob packet + protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Entity UUID + map(Type.VAR_INT); // 2 - Entity Type + map(Type.DOUBLE); // 3 - X + map(Type.DOUBLE); // 4 - Y + map(Type.DOUBLE); // 5 - Z + map(Type.BYTE); // 6 - Yaw + map(Type.BYTE); // 7 - Pitch + map(Type.BYTE); // 8 - Head Pitch + map(Type.SHORT); // 9 - Velocity X + map(Type.SHORT); // 10 - Velocity Y + map(Type.SHORT); // 11 - Velocity Z + map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { - if (metadata.getMetaType() == MetaType1_13.Slot) { - metadata.setMetaType(MetaType1_13_2.Slot); - } - } - } - }); - } - }); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { + if (metadata.getMetaType() == MetaType1_13.Slot) { + metadata.setMetaType(MetaType1_13_2.Slot); + } + } + } + }); + } + }); - // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Player UUID - map(Type.DOUBLE); // 2 - X - map(Type.DOUBLE); // 3 - Y - map(Type.DOUBLE); // 4 - Z - map(Type.BYTE); // 5 - Yaw - map(Type.BYTE); // 6 - Pitch - map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata + // Spawn player packet + protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Player UUID + map(Type.DOUBLE); // 2 - X + map(Type.DOUBLE); // 3 - Y + map(Type.DOUBLE); // 4 - Z + map(Type.BYTE); // 5 - Yaw + map(Type.BYTE); // 6 - Pitch + map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { - if (metadata.getMetaType() == MetaType1_13.Slot) { - metadata.setMetaType(MetaType1_13_2.Slot); - } - } - } - }); - } - }); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { + if (metadata.getMetaType() == MetaType1_13.Slot) { + metadata.setMetaType(MetaType1_13_2.Slot); + } + } + } + }); + } + }); - // Metadata packet - protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list + // Metadata packet + protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { - if (metadata.getMetaType() == MetaType1_13.Slot) { - metadata.setMetaType(MetaType1_13_2.Slot); - } - } - } - }); - } - }); - } + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { + if (metadata.getMetaType() == MetaType1_13.Slot) { + metadata.setMetaType(MetaType1_13_2.Slot); + } + } + } + }); + } + }); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java index faa866127..6ea931ea8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java @@ -9,143 +9,143 @@ import us.myles.ViaVersion.packets.State; public class InventoryPackets { - public static void register(Protocol protocol) { + public static void register(Protocol protocol) { /* Outgoing packets */ - // Set slot packet - protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.BYTE); // 0 - Window ID - map(Type.SHORT); // 1 - Slot ID - map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value - } - }); + // Set slot packet + protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.BYTE); // 0 - Window ID + map(Type.SHORT); // 1 - Slot ID + map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value + } + }); - // Window items packet - protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.UNSIGNED_BYTE); // 0 - Window ID - map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values - } - }); + // Window items packet + protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // 0 - Window ID + map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values + } + }); - // Plugin message - protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.STRING); // Channel - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - String channel = wrapper.get(Type.STRING, 0); - if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) { - wrapper.passthrough(Type.INT); // Passthrough Window ID + // Plugin message + protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); // Channel + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + String channel = wrapper.get(Type.STRING, 0); + if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) { + wrapper.passthrough(Type.INT); // Passthrough Window ID - int size = wrapper.passthrough(Type.UNSIGNED_BYTE); - for (int i = 0; i < size; i++) { - // Input Item - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - // Output Item - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + int size = wrapper.passthrough(Type.UNSIGNED_BYTE); + for (int i = 0; i < size; i++) { + // Input Item + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + // Output Item + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item - if (secondItem) { - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - } + boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item + if (secondItem) { + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + } - wrapper.passthrough(Type.BOOLEAN); // Trade disabled - wrapper.passthrough(Type.INT); // Number of tools uses - wrapper.passthrough(Type.INT); // Maximum number of trade uses - } - } - } - }); - } - }); + wrapper.passthrough(Type.BOOLEAN); // Trade disabled + wrapper.passthrough(Type.INT); // Number of tools uses + wrapper.passthrough(Type.INT); // Maximum number of trade uses + } + } + } + }); + } + }); - // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.VAR_INT); // 1 - Slot ID - map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item - } - }); + // Entity Equipment Packet + protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.VAR_INT); // 1 - Slot ID + map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item + } + }); - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int recipesNo = wrapper.passthrough(Type.VAR_INT); - for (int i = 0; i < recipesNo; i++) { - wrapper.passthrough(Type.STRING); // Id - String type = wrapper.passthrough(Type.STRING); - if (type.equals("crafting_shapeless")) { - wrapper.passthrough(Type.STRING); // Group - int ingredientsNo = wrapper.passthrough(Type.VAR_INT); - for (int i1 = 0; i1 < ingredientsNo; i1++) { - wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); - } - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - } else if (type.equals("crafting_shaped")) { - int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.STRING); // Group - for (int i1 = 0; i1 < ingredientsNo; i1++) { - wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); - } - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - } else if (type.equals("smelting")) { - wrapper.passthrough(Type.STRING); // Group - // Ingredient start - wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); - // Ingredient end - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - wrapper.passthrough(Type.FLOAT); // EXP - wrapper.passthrough(Type.VAR_INT); // Cooking time - } - } - } - }); - } - }); + // Declare Recipes + protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int recipesNo = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < recipesNo; i++) { + wrapper.passthrough(Type.STRING); // Id + String type = wrapper.passthrough(Type.STRING); + if (type.equals("crafting_shapeless")) { + wrapper.passthrough(Type.STRING); // Group + int ingredientsNo = wrapper.passthrough(Type.VAR_INT); + for (int i1 = 0; i1 < ingredientsNo; i1++) { + wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); + } + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + } else if (type.equals("crafting_shaped")) { + int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); + wrapper.passthrough(Type.STRING); // Group + for (int i1 = 0; i1 < ingredientsNo; i1++) { + wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); + } + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + } else if (type.equals("smelting")) { + wrapper.passthrough(Type.STRING); // Group + // Ingredient start + wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT)); + // Ingredient end + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + wrapper.passthrough(Type.FLOAT); // EXP + wrapper.passthrough(Type.VAR_INT); // Cooking time + } + } + } + }); + } + }); /* Incoming packets */ - // Click window packet - protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.UNSIGNED_BYTE); // 0 - Window ID - map(Type.SHORT); // 1 - Slot - map(Type.BYTE); // 2 - Button - map(Type.SHORT); // 3 - Action number - map(Type.VAR_INT); // 4 - Mode - map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item - } - } - ); + // Click window packet + protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.UNSIGNED_BYTE); // 0 - Window ID + map(Type.SHORT); // 1 - Slot + map(Type.BYTE); // 2 - Button + map(Type.SHORT); // 3 - Action number + map(Type.VAR_INT); // 4 - Mode + map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item + } + } + ); - // Creative Inventory Action - protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.SHORT); // 0 - Slot - map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item - } - } - ); - } + // Creative Inventory Action + protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.SHORT); // 0 - Slot + map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item + } + } + ); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java index b62319af7..cdbe42151 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java @@ -9,32 +9,32 @@ import us.myles.ViaVersion.packets.State; public class WorldPackets { - public static void register(Protocol protocol) { - //spawn particle - protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Particle ID - map(Type.BOOLEAN); // 1 - Long Distance - map(Type.FLOAT); // 2 - X - map(Type.FLOAT); // 3 - Y - map(Type.FLOAT); // 4 - Z - map(Type.FLOAT); // 5 - Offset X - map(Type.FLOAT); // 6 - Offset Y - map(Type.FLOAT); // 7 - Offset Z - map(Type.FLOAT); // 8 - Particle Data - map(Type.INT); // 9 - Particle Count - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int id = wrapper.get(Type.INT, 0); - if (id == 27) { - wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); - } - } - }); - } - }); - } + public static void register(Protocol protocol) { + //spawn particle + protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Particle ID + map(Type.BOOLEAN); // 1 - Long Distance + map(Type.FLOAT); // 2 - X + map(Type.FLOAT); // 3 - Y + map(Type.FLOAT); // 4 - Z + map(Type.FLOAT); // 5 - Offset X + map(Type.FLOAT); // 6 - Offset Y + map(Type.FLOAT); // 7 - Offset Z + map(Type.FLOAT); // 8 - Particle Data + map(Type.INT); // 9 - Particle Count + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int id = wrapper.get(Type.INT, 0); + if (id == 27) { + wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); + } + } + }); + } + }); + } } 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 9f475cbaf..c863b24ed 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 @@ -16,7 +16,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { private Set blockStates = new HashSet<>(); private Map connectedBlockStates = new HashMap<>(); - public AbstractFenceConnectionHandler(String blockConnections, String key){ + public AbstractFenceConnectionHandler(String blockConnections, String key) { this.blockConnections = blockConnections; for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/BlockData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/BlockData.java index c6624f93f..86fc10e36 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/BlockData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/BlockData.java @@ -8,11 +8,11 @@ import java.util.Map; public class BlockData { private Map connectData = new HashMap<>(); - public void put(String key, Boolean[] booleans){ + public void put(String key, Boolean[] booleans) { connectData.put(key, booleans); } - public boolean connectsTo(String blockConnection, BlockFace face){ + public boolean connectsTo(String blockConnection, BlockFace face) { final Boolean[] booleans = connectData.get(blockConnection); return booleans != null && booleans[face.ordinal()]; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java index 3a91d0c9c..a3f9739bc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java @@ -10,52 +10,52 @@ import java.util.Map; import java.util.Set; class ChestConnectionHandler extends ConnectionHandler { - private static Map chestFacings = new HashMap<>(); - private static Map connectedStates = new HashMap<>(); - private static Set trappedChests = new HashSet<>(); + private static Map chestFacings = new HashMap<>(); + private static Map connectedStates = new HashMap<>(); + private static Set trappedChests = new HashSet<>(); - static void init() { - ChestConnectionHandler connectionHandler = new ChestConnectionHandler(); - for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { - String key = blockState.getKey().split("\\[")[0]; - if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue; - WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); - if (blockData.getValue("waterlogged").equals("true")) continue; - chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); - if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue()); - connectedStates.put(getStates(blockData), blockState.getValue()); - ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); - } - } + static void init() { + ChestConnectionHandler connectionHandler = new ChestConnectionHandler(); + for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { + String key = blockState.getKey().split("\\[")[0]; + if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue; + WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); + if (blockData.getValue("waterlogged").equals("true")) continue; + chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); + if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue()); + connectedStates.put(getStates(blockData), blockState.getValue()); + ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); + } + } - private static Byte getStates(WrappedBlockData blockData) { - byte states = 0; - String type = blockData.getValue("type"); - if (type.equals("left")) states |= 1; - if (type.equals("right")) states |= 2; - states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2); - if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16; - return states; - } + private static Byte getStates(WrappedBlockData blockData) { + byte states = 0; + String type = blockData.getValue("type"); + if (type.equals("left")) states |= 1; + if (type.equals("right")) states |= 2; + states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2); + if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16; + return states; + } - @Override - public int connect(UserConnection user, Position position, int blockState) { - BlockFace facing = chestFacings.get(blockState); - byte states = 0; - states |= (facing.ordinal() << 2); - boolean trapped = trappedChests.contains(blockState); - if (trapped) states |= 16; - int relative; - if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) { - states |= facing == BlockFace.WEST ? 1 : 2; - } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) { - states |= facing == BlockFace.EAST ? 1 : 2; - } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) { - states |= facing == BlockFace.NORTH ? 2 : 1; - } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) { - states |= facing == BlockFace.SOUTH ? 2 : 1; - } - Integer newBlockState = connectedStates.get(states); - return newBlockState == null ? blockState : newBlockState; - } + @Override + public int connect(UserConnection user, Position position, int blockState) { + BlockFace facing = chestFacings.get(blockState); + byte states = 0; + states |= (facing.ordinal() << 2); + boolean trapped = trappedChests.contains(blockState); + if (trapped) states |= 16; + int relative; + if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) { + states |= facing == BlockFace.WEST ? 1 : 2; + } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) { + states |= facing == BlockFace.EAST ? 1 : 2; + } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) { + states |= facing == BlockFace.NORTH ? 2 : 1; + } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) { + states |= facing == BlockFace.SOUTH ? 2 : 1; + } + Integer newBlockState = connectedStates.get(states); + return newBlockState == null ? blockState : newBlockState; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java index 621185696..ccc27b600 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java @@ -8,12 +8,12 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi public abstract class ConnectionHandler { public abstract int connect(UserConnection user, Position position, int blockState); - public int getBlockData(UserConnection user, Position position) { - return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position); + public int getBlockData(UserConnection user, Position position) { + return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position); } public boolean canConnect(int id) { - ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id); - return handler != null && handler == this; + ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id); + return handler != null && handler == this; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index b2837670c..90948e1e9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -39,11 +39,15 @@ public class RedstoneConnectionHandler extends ConnectionHandler { } private static int getState(String value) { - switch (value){ - case "none": return 0; - case "side" : return 1; - case "up" : return 2; - default: return 0; + switch (value) { + case "none": + return 0; + case "side": + return 1; + case "up": + return 2; + default: + return 0; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java index 343c0a612..651cec4c1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java @@ -11,82 +11,82 @@ import java.util.HashMap; import java.util.Map; public class TripwireConnectionHandler extends ConnectionHandler { - private static Map tripwireDataMap = new HashMap<>(); - private static Map connectedBlocks = new HashMap<>(); - private static Map tripwireHooks = new HashMap<>(); + private static Map tripwireDataMap = new HashMap<>(); + private static Map connectedBlocks = new HashMap<>(); + private static Map tripwireHooks = new HashMap<>(); - static void init() { - TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler(); - for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { - String key = blockState.getKey().split("\\[")[0]; + static void init() { + TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler(); + for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { + String key = blockState.getKey().split("\\[")[0]; - if (key.equals("minecraft:tripwire_hook")) { - WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); - tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); - } else if (key.equals("minecraft:tripwire")) { - WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); + if (key.equals("minecraft:tripwire_hook")) { + WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); + tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); + } else if (key.equals("minecraft:tripwire")) { + WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); - TripwireData tripwireData = new TripwireData( - blockData.getValue("attached").equals("true"), - blockData.getValue("disarmed").equals("true"), - blockData.getValue("powered").equals("true") - ); + TripwireData tripwireData = new TripwireData( + blockData.getValue("attached").equals("true"), + blockData.getValue("disarmed").equals("true"), + blockData.getValue("powered").equals("true") + ); - tripwireDataMap.put(blockState.getValue(), tripwireData); - connectedBlocks.put(getStates(blockData), blockState.getValue()); + tripwireDataMap.put(blockState.getValue(), tripwireData); + connectedBlocks.put(getStates(blockData), blockState.getValue()); - ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); - } - } - } + ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); + } + } + } - private static byte getStates(WrappedBlockData blockData) { - byte b = 0; - if (blockData.getValue("attached").equals("true")) b |= 1; - if (blockData.getValue("disarmed").equals("true")) b |= 2; - if (blockData.getValue("powered").equals("true")) b |= 4; - if (blockData.getValue("east").equals("true")) b |= 8; - if (blockData.getValue("north").equals("true")) b |= 16; - if (blockData.getValue("south").equals("true")) b |= 32; - if (blockData.getValue("west").equals("true")) b |= 64; - return b; - } + private static byte getStates(WrappedBlockData blockData) { + byte b = 0; + if (blockData.getValue("attached").equals("true")) b |= 1; + if (blockData.getValue("disarmed").equals("true")) b |= 2; + if (blockData.getValue("powered").equals("true")) b |= 4; + if (blockData.getValue("east").equals("true")) b |= 8; + if (blockData.getValue("north").equals("true")) b |= 16; + if (blockData.getValue("south").equals("true")) b |= 32; + if (blockData.getValue("west").equals("true")) b |= 64; + return b; + } - @Override - public int connect(UserConnection user, Position position, int blockState) { - TripwireData tripwireData = tripwireDataMap.get(blockState); - if (tripwireData == null) return blockState; - byte b = 0; - if (tripwireData.isAttached()) b |= 1; - if (tripwireData.isDisarmed()) b |= 2; - if (tripwireData.isPowered()) b |= 4; + @Override + public int connect(UserConnection user, Position position, int blockState) { + TripwireData tripwireData = tripwireDataMap.get(blockState); + if (tripwireData == null) return blockState; + byte b = 0; + if (tripwireData.isAttached()) b |= 1; + if (tripwireData.isDisarmed()) b |= 2; + if (tripwireData.isPowered()) b |= 4; - int east = getBlockData(user, position.getRelative(BlockFace.EAST)); - int north = getBlockData(user, position.getRelative(BlockFace.NORTH)); - int south = getBlockData(user, position.getRelative(BlockFace.SOUTH)); - int west = getBlockData(user, position.getRelative(BlockFace.WEST)); + int east = getBlockData(user, position.getRelative(BlockFace.EAST)); + int north = getBlockData(user, position.getRelative(BlockFace.NORTH)); + int south = getBlockData(user, position.getRelative(BlockFace.SOUTH)); + int west = getBlockData(user, position.getRelative(BlockFace.WEST)); - if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) { - b |= 8; - } - if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) { - b |= 16; - } - if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) { - b |= 32; - } - if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) { - b |= 64; - } + if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) { + b |= 8; + } + if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) { + b |= 16; + } + if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) { + b |= 32; + } + if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) { + b |= 64; + } - Integer newBlockState = connectedBlocks.get(b); - return newBlockState == null ? blockState : newBlockState; - } + Integer newBlockState = connectedBlocks.get(b); + return newBlockState == null ? blockState : newBlockState; + } - @AllArgsConstructor - @Getter - @ToString - private static class TripwireData { - private final boolean attached, disarmed, powered; - } + @AllArgsConstructor + @Getter + @ToString + private static class TripwireData { + private final boolean attached, disarmed, powered; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java index da7ac56ff..dda29f196 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java @@ -5,8 +5,8 @@ import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.Position; public class WallConnectionHandler extends AbstractFenceConnectionHandler { - private static final BlockFace[] BLOCK_FACES = { BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST }; - private static final int[] OPPOSITES = { 3, 2, 1, 0 }; + private static final BlockFace[] BLOCK_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST}; + private static final int[] OPPOSITES = {3, 2, 1, 0}; static void init() { new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall"); @@ -32,7 +32,8 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler { } public boolean up(UserConnection user, Position position) { - if(isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP))))return true; + if (isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP)))) + return true; int blockFaces = getBlockFaces(user, position); if (blockFaces == 0 || blockFaces == 0xF) return true; for (int i = 0; i < BLOCK_FACES.length; i++) { @@ -51,7 +52,7 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler { return blockFaces; } - private boolean isWall(int id){ + private boolean isWall(int id) { return getBlockStates().contains(id); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java index c44e26c1d..4cac4c0fa 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java @@ -16,19 +16,27 @@ public class BlockConnectionProvider implements Provider { return -1; } - public void storeBlock(UserConnection connection, Position position, int blockState) {}; + public void storeBlock(UserConnection connection, Position position, int blockState) { - public void removeBlock(UserConnection connection, Position position) {}; + } + + public void removeBlock(UserConnection connection, Position position) { + + } public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) { storeBlock(connection, new Position(x, y, z), blockState); } - public void clearStorage(UserConnection connection) {}; + public void clearStorage(UserConnection connection) { - public void unloadChunk(UserConnection connection, int x, int z) {}; + } - public boolean storesBlocks(){ + public void unloadChunk(UserConnection connection, int x, int z) { + + } + + public boolean storesBlocks() { return false; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 5c9486c42..0c932eaf6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -243,7 +243,7 @@ public class WorldPackets { protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() { @Override public void registerMap() { - if(Via.getConfig().isServersideBlockConnections()){ + if (Via.getConfig().isServersideBlockConnections()) { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index d6734ec01..ad0a9e595 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -34,29 +34,29 @@ public class BlockConnectionStorage extends StoredObject { Pair pair = getPair(position); Map map = getChunkMap(pair); map.remove(new BlockPositon(position)); - if(map.isEmpty()){ + if (map.isEmpty()) { blockStorage.remove(pair); } } - public void clear(){ + public void clear() { blockStorage.clear(); } - public void unloadChunk(int x, int z){ + public void unloadChunk(int x, int z) { blockStorage.remove(new Pair<>(x, z)); } - private Map getChunkMap(Pair pair){ + private Map getChunkMap(Pair pair) { Map map = blockStorage.get(pair); - if(map == null){ + if (map == null) { map = new HashMap<>(); blockStorage.put(pair, map); } return map; } - private Pair getPair(Position position){ + private Pair getPair(Position position) { int chunkX = (int) (position.getX() >> 4); int chunkZ = (int) (position.getZ() >> 4); return new Pair<>(chunkX, chunkZ); @@ -65,8 +65,9 @@ public class BlockConnectionStorage extends StoredObject { @EqualsAndHashCode @Data private class BlockPositon { - int x,y,z; - public BlockPositon(Position position){ + int x, y, z; + + public BlockPositon(Position position) { x = position.getX().intValue(); y = position.getY().intValue(); z = position.getZ().intValue(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java index da848d8f0..c73af9382 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -186,7 +186,7 @@ public class ItemRewriter { } } } - + public static void rewriteBookToServer(Item item) { short id = item.getId(); if (id != 387) { @@ -212,7 +212,7 @@ public class ItemRewriter { stag.setValue(value); } } - + private static String fixBookSpaceChars(String str) { if (!str.startsWith(" ")) { return str; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 0b0540559..1d1a284db 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -121,8 +121,8 @@ public class WorldPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); - Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks); - Chunk1_8 chunk = (Chunk1_8) wrapper.read(type); + Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks); + Chunk1_8 chunk = (Chunk1_8) wrapper.read(type); if (chunk.isUnloadPacket()) { wrapper.setId(0x1D); @@ -311,7 +311,7 @@ public class WorldPackets { // Blocking patch if (Via.getConfig().isShieldBlocking()) { EntityTracker tracker = wrapper.user().get(EntityTracker.class); - + if (item != null && Protocol1_9TO1_8.isSword(item.getId())) { if (hand == 0) { if (!tracker.isBlocking()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 64906f7b7..9a9dce713 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -258,7 +258,7 @@ public class EntityTracker extends StoredObject { } 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().get(ProtocolInfo.class).getUsername()}); } else { wrapper.write(Type.BYTE, (byte) 1); // remove team } 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 7f681d69e..70323c78a 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 @@ -113,7 +113,7 @@ public class Chunk1_9to1_8Type extends PartialType { // Read biome data if (bytesLeft >= BIOME_DATA_LENGTH) { biomeData = new int[BIOME_DATA_LENGTH]; - for (int i = 0; i < BIOME_DATA_LENGTH; i++){ + for (int i = 0; i < BIOME_DATA_LENGTH; i++) { biomeData[i] = input.readByte() & 0xFF; } bytesLeft -= BIOME_DATA_LENGTH; diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index adf21bdc2..4fe598f51 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -185,7 +185,7 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig { public boolean is1_12NBTArrayFix() { return getBoolean("chat-nbt-fix", true); } - + @Override public boolean is1_12QuickMoveActionFix() { return false; diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java index b02fda18b..d74e330c9 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java @@ -24,7 +24,7 @@ public class SpongeBlockConnectionProvider extends BlockConnectionProvider { try { block = Class.forName("net.minecraft.block.Block"); blockStateIds = ReflectionUtil.get( - ReflectionUtil.getStatic(block, "field_176229_d", Object.class), + ReflectionUtil.getStatic(block, "field_176229_d", Object.class), "field_148749_a", Map.class); } catch (ClassNotFoundException e) { Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?"); 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 0a2f6074c..ec35636a4 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 @@ -53,8 +53,8 @@ public class VelocityServerHandler { // Check if ViaVersion can support that version Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null - ? user.get(ProtocolInfo.class).getProtocolVersion() - : protocolId)); + ? user.get(ProtocolInfo.class).getProtocolVersion() + : protocolId)); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) { e1.printStackTrace(); @@ -133,7 +133,7 @@ public class VelocityServerHandler { } Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); - ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection,"getNextProtocolVersion"); + ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection, "getNextProtocolVersion"); setProtocolVersion.invoke(connection, version); } } 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 8abe51927..f87b83710 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 @@ -56,21 +56,21 @@ public class ProtocolDetectorService implements Runnable { public static void probeServer(final RegisteredServer serverInfo) { final String key = serverInfo.getServerInfo().getName(); serverInfo.ping().thenAccept((serverPing) -> { - if (serverPing != null && serverPing.getVersion() != null) { - detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); - if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) { - Map servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); - Integer protocol = servers.get(key); - if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { - return; - } - // Ensure we're the only ones writing to the config - synchronized (Via.getPlatform().getConfigurationProvider()) { - servers.put(key, serverPing.getVersion().getProtocol()); - } - // Save - Via.getPlatform().getConfigurationProvider().saveConfig(); + if (serverPing != null && serverPing.getVersion() != null) { + detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); + if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) { + Map servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); + Integer protocol = servers.get(key); + if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { + return; } + // Ensure we're the only ones writing to the config + synchronized (Via.getPlatform().getConfigurationProvider()) { + servers.put(key, serverPing.getVersion().getProtocol()); + } + // Save + Via.getPlatform().getConfigurationProvider().saveConfig(); + } } }); }