From 2b5d67a3ca2415ebf447a63c4e974ea68811a2e0 Mon Sep 17 00:00:00 2001 From: jglrxavpok Date: Tue, 2 Feb 2021 14:49:19 +0100 Subject: [PATCH] Don't crash the server if Mixin can't be loaded due to identical file names inside the JAR file. But please spam the console. --- .../java/net/minestom/server/Bootstrap.java | 19 +++++++++++++++++-- .../server/extensions/ExtensionManager.java | 10 ++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/Bootstrap.java b/src/main/java/net/minestom/server/Bootstrap.java index 3e5b26455..2913af492 100644 --- a/src/main/java/net/minestom/server/Bootstrap.java +++ b/src/main/java/net/minestom/server/Bootstrap.java @@ -7,6 +7,7 @@ import net.minestom.server.extras.selfmodification.mixins.MixinServiceMinestom; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.platform.CommandLineOptions; import org.spongepowered.asm.mixin.Mixins; +import org.spongepowered.asm.service.ServiceNotAvailableError; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -21,7 +22,12 @@ public final class Bootstrap { try { ClassLoader classLoader = MinestomRootClassLoader.getInstance(); startMixin(args); - MinestomRootClassLoader.getInstance().addCodeModifier(new MixinCodeModifier()); + try { + MinestomRootClassLoader.getInstance().addCodeModifier(new MixinCodeModifier()); + } catch (RuntimeException e) { + e.printStackTrace(); + System.err.println("Failed to add MixinCodeModifier, mixins will not be injected. Check the log entries above to debug."); + } ExtensionManager.loadCodeModifiersEarly(); @@ -47,7 +53,16 @@ public final class Bootstrap { // hacks required to pass custom arguments Method start = MixinBootstrap.class.getDeclaredMethod("start"); start.setAccessible(true); - if (!((boolean) start.invoke(null))) { + try { + if (!((boolean) start.invoke(null))) { + return; + } + } catch (ServiceNotAvailableError e) { + e.printStackTrace(); + System.err.println("Failed to load Mixin, see error above."); + System.err.println("It is possible you simply have two files with identical names inside your server jar. " + + "Check your META-INF/services directory inside your Minestom implementation and merge files with identical names inside META-INF/services."); + return; } diff --git a/src/main/java/net/minestom/server/extensions/ExtensionManager.java b/src/main/java/net/minestom/server/extensions/ExtensionManager.java index edfdfec97..9a98c27c8 100644 --- a/src/main/java/net/minestom/server/extensions/ExtensionManager.java +++ b/src/main/java/net/minestom/server/extensions/ExtensionManager.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongepowered.asm.mixin.Mixins; +import org.spongepowered.asm.service.ServiceNotAvailableError; import java.io.*; import java.lang.reflect.Constructor; @@ -499,8 +500,13 @@ public class ExtensionManager { } if (!extension.getMixinConfig().isEmpty()) { final String mixinConfigFile = extension.getMixinConfig(); - Mixins.addConfiguration(mixinConfigFile); - LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile); + try { + Mixins.addConfiguration(mixinConfigFile); + LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile); + } catch (ServiceNotAvailableError e) { + MinecraftServer.getExceptionManager().handleException(e); + LOGGER.error("Could not load Mixin configuration: "+mixinConfigFile); + } } } catch (Exception e) { MinecraftServer.getExceptionManager().handleException(e);