From a0f8ab7bbb65e8841274a105d2f06336eeeb67ec Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 20 Nov 2023 19:56:48 +0100 Subject: [PATCH] Some cleanup --- .../api/command/ViaVersionCommand.java | 2 +- .../bukkit/platform/BukkitViaLoader.java | 8 +++----- .../bungee/commands/BungeeCommandHandler.java | 8 +------- .../providers/BungeeVersionProvider.java | 19 +++---------------- .../viaversion/viaversion/ViaManagerImpl.java | 13 +++++-------- .../platform/LegacyViaInjector.java | 4 ++-- .../protocol/ProtocolManagerImpl.java | 4 ++-- .../metadata/MetadataRewriter1_11To1_10.java | 3 ++- .../TranslateRewriter.java | 4 ++-- .../protocol1_13to1_12_2/ChatRewriter.java | 4 ++-- .../data/ComponentRewriter1_13.java | 7 +++---- .../data/MappingData.java | 4 ++-- .../Protocol1_20_3To1_20_2.java | 7 +++---- .../viaversion/rewriter/EntityRewriter.java | 3 ++- .../command/VelocityCommandHandler.java | 6 +----- 15 files changed, 34 insertions(+), 62 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java index 3afba2be0..64614c20f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java +++ b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java @@ -32,7 +32,7 @@ public interface ViaVersionCommand { * @param command Your own SubCommand instance to handle it. * @throws Exception throws an exception when the subcommand already exists or if it's not valid, example: spacee */ - void registerSubCommand(ViaSubCommand command) throws Exception; + void registerSubCommand(ViaSubCommand command); /** * Check if a subcommand is registered. diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java index 8c4fa95b0..bebc4ce21 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java @@ -48,6 +48,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -111,8 +112,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { try { new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix()).register(); } catch (ReflectiveOperationException e) { - Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub"); - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.WARNING, "Could not load hitbox fix - please report this on our GitHub", e); } } } @@ -165,9 +165,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { return null; }).get(10, TimeUnit.SECONDS); } catch (Exception e) { - Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName()); - if (Via.getManager().isDebug()) - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.SEVERE, "Error fetching hand item", e); return null; } } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java index dd6c7598f..d098f8c05 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java @@ -17,17 +17,11 @@ */ package com.viaversion.viaversion.bungee.commands; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.bungee.commands.subs.ProbeSubCmd; import com.viaversion.viaversion.commands.ViaCommandHandler; public class BungeeCommandHandler extends ViaCommandHandler { public BungeeCommandHandler() { - try { - registerSubCommand(new ProbeSubCmd()); - } catch (Exception e) { - Via.getPlatform().getLogger().severe("Failed to register Bungee subcommands"); - e.printStackTrace(); - } + registerSubCommand(new ProbeSubCmd()); } } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java index 730127749..c967dde4c 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java @@ -28,27 +28,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.protocol.ProtocolConstants; public class BungeeVersionProvider extends BaseVersionProvider { - private static Class ref; - - static { - try { - ref = Class.forName("net.md_5.bungee.protocol.ProtocolConstants"); - } catch (Exception e) { - Via.getPlatform().getLogger().severe("Could not detect the ProtocolConstants class"); - e.printStackTrace(); - } - } @Override public int getClosestServerProtocol(UserConnection user) throws Exception { - if (ref == null) { - return super.getClosestServerProtocol(user); - } - // TODO Have one constant list forever until restart? (Might limit plugins if they change this) - List list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); + List list = ReflectionUtil.getStatic(ProtocolConstants.class, "SUPPORTED_VERSION_IDS", List.class); List sorted = new ArrayList<>(list); Collections.sort(sorted); @@ -79,7 +66,7 @@ public class BungeeVersionProvider extends BaseVersionProvider { public static int getLowestSupportedVersion() { List list; try { - list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); + list = ReflectionUtil.getStatic(ProtocolConstants.class, "SUPPORTED_VERSION_IDS", List.class); return list.get(0); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); diff --git a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index 4fbcedb92..26a333243 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -49,6 +49,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -99,8 +100,7 @@ public class ViaManagerImpl implements ViaManager { try { injector.inject(); } catch (Exception e) { - platform.getLogger().severe("ViaVersion failed to inject:"); - e.printStackTrace(); + platform.getLogger().log(Level.SEVERE, "ViaVersion failed to inject:", e); return; } @@ -196,8 +196,7 @@ public class ViaManagerImpl implements ViaManager { protocolManager.setServerProtocol(versionInfo); } catch (Exception e) { - platform.getLogger().severe("ViaVersion failed to get the server protocol!"); - e.printStackTrace(); + platform.getLogger().log(Level.SEVERE, "ViaVersion failed to get the server protocol!", e); } } @@ -207,8 +206,7 @@ public class ViaManagerImpl implements ViaManager { try { injector.uninject(); } catch (Exception e) { - platform.getLogger().severe("ViaVersion failed to uninject:"); - e.printStackTrace(); + platform.getLogger().log(Level.SEVERE, "ViaVersion failed to uninject:", e); } loader.unload(); @@ -228,8 +226,7 @@ public class ViaManagerImpl implements ViaManager { try { version = Integer.parseInt(versionString); } catch (NumberFormatException e) { - platform.getLogger().warning("Failed to determine Java version; could not parse: " + versionString); - e.printStackTrace(); + platform.getLogger().log(Level.WARNING, "Failed to determine Java version; could not parse: " + versionString, e); return; } diff --git a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java index d3f31ee50..ac56497c7 100644 --- a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java +++ b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java @@ -32,6 +32,7 @@ import io.netty.channel.ChannelPipeline; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import org.checkerframework.checker.nullness.qual.Nullable; public abstract class LegacyViaInjector implements ViaInjector { @@ -141,8 +142,7 @@ public abstract class LegacyViaInjector implements ViaInjector { ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((WrappedChannelInitializer) initializer).original()); } } catch (Exception e) { - Via.getPlatform().getLogger().severe("Failed to remove injection handler, reload won't work with connections, please reboot!"); - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to remove injection handler, reload won't work with connections, please reboot!", e); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java index 10ba1f806..fedb8c8e8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java @@ -82,6 +82,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; +import java.util.logging.Level; import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; @@ -514,8 +515,7 @@ public class ProtocolManagerImpl implements ProtocolManager { private Function mappingLoaderThrowable(Class protocolClass) { return throwable -> { - Via.getPlatform().getLogger().severe("Error during mapping loading of " + protocolClass.getSimpleName()); - throwable.printStackTrace(); + Via.getPlatform().getLogger().log(Level.SEVERE, "Error during mapping loading of " + protocolClass.getSimpleName(), throwable); return null; }; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java index 24e9d574e..67077722f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java @@ -34,6 +34,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPac import com.viaversion.viaversion.rewriter.EntityRewriter; import java.util.List; import java.util.Optional; +import java.util.logging.Level; public class MetadataRewriter1_11To1_10 extends EntityRewriter { @@ -230,7 +231,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter extends ComponentRewriter { @@ -56,8 +57,7 @@ public class ComponentRewriter1_13 extends Comp tag = SNBT.deserializeCompoundTag(text); } catch (Exception e) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { - Via.getPlatform().getLogger().warning("Error reading NBT in show_item:" + text); - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.WARNING, "Error reading NBT in show_item:" + text, e); } return; } @@ -89,8 +89,7 @@ public class ComponentRewriter1_13 extends Comp object.addProperty("text", serializedNBT); hoverEvent.add("value", array); } catch (Exception e) { - Via.getPlatform().getLogger().warning("Error writing NBT in show_item:" + text); - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.WARNING, "Error writing NBT in show_item:" + text, e); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java index 9e7f55a78..20c14ba91 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java @@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.data.MappingDataLoader; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; public class MappingData extends MappingDataBase { private final Map dimensionDataMap = new HashMap<>(); @@ -42,8 +43,7 @@ public class MappingData extends MappingDataBase { try { dimensionRegistry = NBTIO.readTag(MappingDataLoader.getResource("dimension-registry-1.16.2.nbt")); } catch (final IOException e) { - Via.getPlatform().getLogger().severe("Error loading dimension registry:"); - e.printStackTrace(); + Via.getPlatform().getLogger().log(Level.SEVERE, "Error loading dimension registry:", e); } // Data of each dimension diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java index 96cfca2a6..9b49d62ec 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java @@ -71,6 +71,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.logging.Level; import org.checkerframework.checker.nullness.qual.Nullable; public final class Protocol1_20_3To1_20_2 extends AbstractProtocol { @@ -348,8 +349,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol"); } } @@ -358,8 +358,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol"); } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 8432dc7b3..833ac46c5 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -50,6 +50,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; @@ -598,7 +599,7 @@ public abstract class EntityRewriter