diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index f597c65c1..ada518e35 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -79,7 +79,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { // Check if it's a spigot build with a protocol mod try { - compatSpigotBuild = NMSUtil.nms("PacketEncoder").getDeclaredField("version") != null; + NMSUtil.nms("PacketEncoder").getDeclaredField("version"); + compatSpigotBuild = true; } catch (Exception e) { compatSpigotBuild = false; } 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 d6621b1de..d6576b355 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 @@ -191,7 +191,7 @@ public abstract class Protocol { @AllArgsConstructor @Getter - class ProtocolPacket { + public static class ProtocolPacket { State state; int oldID; int newID; diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java index f4896a790..4dc5bf1c0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java @@ -27,6 +27,6 @@ public class ShortType extends Type implements TypeConverter { if (o instanceof Boolean) { return ((Boolean) o) ? (short) 1 : 0; } - return (short) o; + return (Short) o; } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java index 6f910d872..e35b20a08 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java @@ -27,6 +27,6 @@ public class UnsignedByteType extends Type implements TypeConverter SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap<>(ChatColor.class); - // @formatter:on + protected final static EnumMap SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap<>(ChatColor.class); static { SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.BLACK, 'g'); @@ -363,11 +361,11 @@ public class Protocol1_13To1_12_2 extends Protocol { int id = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 1); if (id == 1010) { // Play record - wrapper.set(Type.INT, 1, data = MappingData.oldToNewItems.get(data << 4)); + wrapper.set(Type.INT, 1, MappingData.oldToNewItems.get(data << 4)); } else if (id == 2001) { // Block break + block break sound int blockId = data & 0xFFF; int blockData = data >> 12; - wrapper.set(Type.INT, 1, data = WorldPackets.toNewId(blockId << 4 | blockData)); + wrapper.set(Type.INT, 1, WorldPackets.toNewId(blockId << 4 | blockData)); } } }); 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 f6e30957b..b5454d0c3 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 @@ -35,7 +35,7 @@ public class RedstoneConnectionHandler extends ConnectionHandler { b |= getState(data.getValue("north")) << 2; b |= getState(data.getValue("south")) << 4; b |= getState(data.getValue("west")) << 6; - b |= Integer.valueOf(data.getValue("power")) << 8; + b |= Integer.parseInt(data.getValue("power")) << 8; return b; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index 02b93706d..7c1425d72 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -21,13 +21,13 @@ import java.util.HashMap; import java.util.Map; public class MappingData { - public static BiMap oldToNewItems = HashBiMap.create(); - public static Map blockTags = new HashMap<>(); - public static Map itemTags = new HashMap<>(); - public static Map fluidTags = new HashMap<>(); - public static BiMap oldEnchantmentsIds = HashBiMap.create(); - public static Map translateMapping = new HashMap<>(); - public static Map mojangTranslation = new HashMap<>(); + public static final BiMap oldToNewItems = HashBiMap.create(); + public static final Map blockTags = new HashMap<>(); + public static final Map itemTags = new HashMap<>(); + public static final Map fluidTags = new HashMap<>(); + public static final BiMap oldEnchantmentsIds = HashBiMap.create(); + public static final Map translateMapping = new HashMap<>(); + public static final Map mojangTranslation = new HashMap<>(); public static Mappings enchantmentMappings; public static Mappings soundMappings; public static Mappings blockMappings; @@ -50,7 +50,6 @@ public class MappingData { Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 sound mapping..."); soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); Via.getPlatform().getLogger().info("Loading translation mappping"); - translateMapping = new HashMap<>(); Map translateData = GsonUtil.getGson().fromJson( new InputStreamReader( MappingData.class.getClassLoader() diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java index 304f623c6..36dc8137d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java @@ -10,8 +10,8 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; public class EntityPackets { @@ -68,11 +68,11 @@ public class EntityPackets { } wrapper.set(Type.INT, 0, data); - } + // Register Type ID + wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); + } } - // Register Type ID - wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 9e5a2e4a1..1b689571a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -624,14 +624,16 @@ public class InventoryPackets { if (oldId == null && newId.startsWith("viaversion:legacy/")) { oldId = Short.valueOf(newId.substring(18)); } - enchEntry.put( - new ShortTag( - "id", - oldId - ) - ); - enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); - ench.add(enchEntry); + if (oldId != null) { + enchEntry.put( + new ShortTag( + "id", + oldId + ) + ); + enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); + ench.add(enchEntry); + } } } tag.remove("Enchantments"); @@ -648,14 +650,16 @@ public class InventoryPackets { if (oldId == null && newId.startsWith("viaversion:legacy/")) { oldId = Short.valueOf(newId.substring(18)); } - enchEntry.put( - new ShortTag( - "id", - oldId - ) - ); - enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); - newStoredEnch.add(enchEntry); + if (oldId != null) { + enchEntry.put( + new ShortTag( + "id", + oldId + ) + ); + enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); + newStoredEnch.add(enchEntry); + } } } tag.remove("StoredEnchantments"); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java index 9a8c3e7b7..da69a8322 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java @@ -9,11 +9,11 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityP import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { - private final int WALL_BANNER_START = 7110; // 4 each - private final int WALL_BANNER_STOP = 7173; + private static final int WALL_BANNER_START = 7110; // 4 each + private static final int WALL_BANNER_STOP = 7173; - private final int BANNER_START = 6854; // 16 each - private final int BANNER_STOP = 7109; + private static final int BANNER_START = 6854; // 16 each + private static final int BANNER_STOP = 7109; @Override public int transform(UserConnection user, CompoundTag tag) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java index 5198ba9cf..7fb61cb20 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java @@ -9,8 +9,8 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityP import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { - private final int SKULL_WALL_START = 5447; - private final int SKULL_END = 5566; + private static final int SKULL_WALL_START = 5447; + private static final int SKULL_END = 5566; @Override public int transform(UserConnection user, CompoundTag tag) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index 421ca58e2..8137f764a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -72,7 +72,7 @@ public class BlockStorage extends StoredObject { @Data @AllArgsConstructor - public class ReplacementData { + public static class ReplacementData { private int original; private int replacement; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index 739a43336..2899a9332 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.data.Mappings; import java.util.*; public class MappingData { - public static BiMap oldToNewItems = HashBiMap.create(); + public final static BiMap oldToNewItems = HashBiMap.create(); public static Mappings blockStateMappings; public static Mappings blockMappings; public static Mappings soundMappings; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index 4195cc4fd..c9ea22ec7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -49,7 +49,6 @@ public class EntityPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); - UUID uuid = wrapper.get(Type.UUID, 0); int typeId = wrapper.get(Type.VAR_INT, 1); Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); @@ -95,11 +94,12 @@ public class EntityPackets { velocity.write(Type.SHORT, wrapper.get(Type.SHORT, 2)); velocity.send(Protocol1_14To1_13_2.class); } + + // Register Type ID + wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, type1_14); } wrapper.set(Type.VAR_INT, 1, typeId); - // Register Type ID - wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, type1_14); } }); } @@ -128,14 +128,11 @@ public class EntityPackets { public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); - UUID uuid = wrapper.get(Type.UUID, 0); type = EntityTypeRewriter.getNewId(type).or(type); - - Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); - wrapper.set(Type.VAR_INT, 1, type); + Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); // Register Type ID wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType); @@ -173,7 +170,6 @@ public class EntityPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - UUID uuid = wrapper.get(Type.UUID, 0); int entityId = wrapper.get(Type.VAR_INT, 0); Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index 0301339e9..417cb149c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -228,9 +228,9 @@ public class WorldPackets { int id = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 1); if (id == 1010) { // Play record - wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data)); + wrapper.set(Type.INT, 1, InventoryPackets.getNewItemId(data)); } else if (id == 2001) { // Block break + block break sound - wrapper.set(Type.INT, 1, data = Protocol1_14To1_13_2.getNewBlockStateId(data)); + wrapper.set(Type.INT, 1, Protocol1_14To1_13_2.getNewBlockStateId(data)); } } }); 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 1a0e05951..a90712ff6 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 @@ -34,7 +34,8 @@ public class Chunk1_9_1_2Type extends PartialType { boolean groundUp = input.readBoolean(); int primaryBitmask = Type.VAR_INT.read(input); - int size = Type.VAR_INT.read(input); + // Size (unused) + Type.VAR_INT.read(input); BitSet usedSections = new BitSet(16); ChunkSection[] sections = new ChunkSection[16]; 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 b9076a2f9..35ea94e31 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 @@ -329,7 +329,7 @@ public class WorldPackets { @Override public void registerMap() { map(Type.POSITION); // 0 - Position - map(Type.VAR_INT, Type.BYTE); // 1 - Block Face + map(Type.VAR_INT, Type.UNSIGNED_BYTE); // 1 - Block Face map(Type.VAR_INT, Type.NOTHING); // 2 - Hand create(new ValueCreator() { @Override @@ -359,7 +359,7 @@ public class WorldPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int face = wrapper.get(Type.BYTE, 0); + int face = wrapper.get(Type.UNSIGNED_BYTE, 0); if (face == 255) return; Position p = wrapper.get(Type.POSITION, 0); diff --git a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java index f5eb29076..e4b8f4ad0 100644 --- a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java @@ -100,14 +100,14 @@ public class UpdateUtil { connection.setDoOutput(true); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); String input; - String content = ""; + StringBuilder builder = new StringBuilder(); while ((input = br.readLine()) != null) { - content = content + input; + builder.append(input); } br.close(); JsonObject statistics; try { - statistics = GsonUtil.getGson().fromJson(content, JsonObject.class); + statistics = GsonUtil.getGson().fromJson(builder.toString(), JsonObject.class); } catch (JsonParseException e) { e.printStackTrace(); return null; diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java index 822b9c29f..0ebfc1605 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/Config.java +++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java @@ -76,10 +76,10 @@ public abstract class Config implements ConfigurationProvider { defaults.remove(option); } // Merge with defaultLoader - for (Object key : config.keySet()) { + for (Map.Entry entry : config.entrySet()) { // Set option in new conf if exists - if (defaults.containsKey(key) && !unsupported.contains(key.toString())) { - defaults.put((String) key, config.get(key)); + if (defaults.containsKey(entry.getKey()) && !unsupported.contains(entry.getKey())) { + defaults.put(entry.getKey(), entry.getValue()); } } } catch (IOException e) { diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java index fa9833ed7..cba7897f5 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java @@ -70,18 +70,22 @@ public class HandItemCache implements Runnable { } } int id = 0; - try { - id = (int) GET_ID.invoke(null, itemInHand.getItem()); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); + if (GET_ID != null) { + try { + id = (int) GET_ID.invoke(null, itemInHand.getItem()); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } int damage = 0; - try { - damage = (int) GET_DAMAGE.get(itemInHand); - } catch (IllegalAccessException e) { - e.printStackTrace(); + if (GET_DAMAGE != null) { + try { + damage = (int) GET_DAMAGE.get(itemInHand); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } } return new Item((short) id, (byte) itemInHand.getQuantity(), (short) damage, null); }