From cfc048ba5355fe8f441ce36df446bfb148136460 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 10 Feb 2024 17:58:54 +0100 Subject: [PATCH] Small random cleanup --- .../bukkit/util/CollisionChecker.java | 2 +- .../BukkitInventoryQuickMoveProvider.java | 6 +----- .../viaversion/legacy/bossbar/CommonBoss.java | 3 ++- .../protocol1_11to1_10/BlockEntityRewriter.java | 8 ++++---- .../AbstractFenceConnectionHandler.java | 2 +- .../AbstractStempConnectionHandler.java | 2 +- .../ChorusPlantConnectionHandler.java | 2 +- .../RedstoneConnectionHandler.java | 3 +-- .../data/ParticleRewriter.java | 7 ++++--- .../protocol1_13to1_12_2/data/RecipeData.java | 12 ++++-------- .../storage/InventoryTracker1_16.java | 2 +- .../Protocol1_19To1_18_2.java | 6 ++---- .../protocol1_9to1_8/Protocol1_9To1_8.java | 17 ++++++++++------- .../metadata/MetadataRewriter1_9To1_8.java | 2 +- .../protocol1_9to1_8/packets/PlayerPackets.java | 2 -- .../viaversion/rewriter/ItemRewriter.java | 2 +- .../com/viaversion/viaversion/SpongePlugin.java | 1 - .../handlers/SpongeChannelInitializer.java | 2 +- 18 files changed, 36 insertions(+), 45 deletions(-) diff --git a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java index 5220aa2d1..9ce05d468 100644 --- a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java +++ b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java @@ -106,7 +106,7 @@ public class CollisionChecker { } private static class DummyList extends AbstractList { - private boolean any = false; + private boolean any; @Override public T get(int index) { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index f4ad544a5..11d432118 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -199,10 +199,6 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider private boolean isSupported() { int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion(); - if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) { - return true; // 1.8-1.11.2 - } - // this is not needed on 1.12+ servers - return false; + return protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion(); // 1.8-1.11.2, not needed with 1.12 } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java index 2f69eb4dd..a3ac22416 100644 --- a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java +++ b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java @@ -31,6 +31,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_ import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -56,7 +57,7 @@ public class CommonBoss implements BossBar { this.color = color == null ? BossColor.PURPLE : color; this.style = style == null ? BossStyle.SOLID : style; this.connections = new MapMaker().weakValues().makeMap(); - this.flags = new HashSet<>(); + this.flags = EnumSet.noneOf(BossFlag.class); this.visible = true; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java index 06fa8f843..336929692 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java @@ -22,7 +22,7 @@ import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.util.Key; public class BlockEntityRewriter { - private static BiMap oldToNewNames = HashBiMap.create(); + private static final BiMap OLD_TO_NEW_NAMES = HashBiMap.create(); // Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles static { @@ -52,15 +52,15 @@ public class BlockEntityRewriter { } private static void rewrite(String oldName, String newName) { - oldToNewNames.put(oldName, Key.namespaced(newName)); + OLD_TO_NEW_NAMES.put(oldName, Key.namespaced(newName)); } public static BiMap inverse() { - return oldToNewNames.inverse(); + return OLD_TO_NEW_NAMES.inverse(); } public static String toNewIdentifier(String oldId) { - String newName = oldToNewNames.get(oldId); + String newName = OLD_TO_NEW_NAMES.get(oldId); if (newName != null) { return newName; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java index c50595e0b..f6a411cf8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java @@ -36,7 +36,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { Arrays.fill(connectedBlockStates, -1); } - public ConnectionData.ConnectorInitAction getInitAction(final String key) { + ConnectionData.ConnectorInitAction getInitAction(final String key) { final AbstractFenceConnectionHandler handler = this; return blockData -> { if (key.equals(blockData.getMinecraftKey())) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java index 75d883958..22717e18b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java @@ -38,7 +38,7 @@ public abstract class AbstractStempConnectionHandler extends ConnectionHandler { this.baseStateId = ConnectionData.getId(baseStateId); } - public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) { + ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) { final AbstractStempConnectionHandler handler = this; return blockData -> { if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java index f2413ff4f..af5dd0161 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java @@ -39,7 +39,7 @@ public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler endstone = ConnectionData.getId("minecraft:end_stone"); } - public ConnectionData.ConnectorInitAction getExtraAction() { + private ConnectionData.ConnectorInitAction getExtraAction() { return blockData -> { if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) { getBlockStates().add(blockData.getSavedBlockStateId()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index 3a9d1f369..592b6c6c7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -59,13 +59,12 @@ public class RedstoneConnectionHandler extends ConnectionHandler { private static int getState(String value) { switch (value) { case "none": + default: return 0; case "side": return 1; case "up": return 2; - default: - return 0; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index c8c176cc0..21c6a37ec 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -99,7 +99,7 @@ public class ParticleRewriter { } NewParticle rewrite = particles.get(particleId); - return rewrite.handle(new Particle(rewrite.getId()), data); + return rewrite.handle(new Particle(rewrite.id()), data); } private static void add(int newId) { @@ -157,6 +157,7 @@ public class ParticleRewriter { }; } + @FunctionalInterface interface ParticleDataHandler { Particle handler(Particle particle, Integer[] data); } @@ -176,11 +177,11 @@ public class ParticleRewriter { return particle; } - public int getId() { + public int id() { return id; } - public ParticleDataHandler getHandler() { + public ParticleDataHandler handler() { return handler; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java index 981e115e1..3b5e0d048 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java @@ -31,20 +31,16 @@ public class RecipeData { public static void init() { InputStream stream = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/itemrecipes1_12_2to1_13.json"); - InputStreamReader reader = new InputStreamReader(stream); - try { + try (InputStreamReader reader = new InputStreamReader(stream)) { recipes = GsonUtil.getGson().fromJson( reader, new TypeToken>() { }.getType() ); - } finally { - try { - reader.close(); - } catch (IOException ignored) { - // Ignored - } + } catch (IOException e) { + throw new RuntimeException(e); } + // Ignored } public static class Recipe { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java index 287bd3b05..7a6a7e7cd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage; import com.viaversion.viaversion.api.connection.StorableObject; public class InventoryTracker1_16 implements StorableObject { - private boolean inventoryOpen = false; + private boolean inventoryOpen; public boolean isInventoryOpen() { return inventoryOpen; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java index 9762ac282..b50b492f1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java @@ -61,7 +61,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol(this).register(ClientboundPackets1_18.STATISTICS); - final PacketHandler singleNullTextComponentMapper = wrapper -> { - wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT))); - }; + final PacketHandler singleNullTextComponentMapper = wrapper -> wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT))); registerClientbound(ClientboundPackets1_18.TITLE_TEXT, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.TITLE_SUBTITLE, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.ACTIONBAR, singleNullTextComponentMapper); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index bae5c01fe..c40b0e824 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -98,13 +98,16 @@ public class Protocol1_9To1_8 extends AbstractProtocol { @ConfigDir(sharedRoot = false) private Path configDir; - @SuppressWarnings("SpongeInjection") @Inject SpongePlugin(final PluginContainer container, final Game game, final org.apache.logging.log4j.Logger logger) { this.container = container; diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java index a25ec6ed1..29d456ba8 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java @@ -52,7 +52,7 @@ public class SpongeChannelInitializer extends ChannelInitializer implem // Ensure ViaVersion is loaded if (Via.getAPI().getServerVersion().isKnown() && channel instanceof SocketChannel) { // channel can be LocalChannel on internal server - UserConnection info = new UserConnectionImpl((SocketChannel) channel); + UserConnection info = new UserConnectionImpl(channel); // init protocol new ProtocolPipelineImpl(info); // Add originals