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.
This commit is contained in:
jglrxavpok 2021-02-02 14:49:19 +01:00
parent 9b9565dbbd
commit 2b5d67a3ca
2 changed files with 25 additions and 4 deletions

View File

@ -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;
}

View File

@ -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);