3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Catch all throwables when loading each extension (#4320)

Dieser Commit ist enthalten in:
Konicai 2023-12-04 17:05:12 -05:00 committet von GitHub
Ursprung 308f293021
Commit 998caee156
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -56,7 +56,7 @@ public class GeyserExtensionLoader extends ExtensionLoader {
private final Map<Extension, GeyserExtensionContainer> extensionContainers = new HashMap<>(); private final Map<Extension, GeyserExtensionContainer> extensionContainers = new HashMap<>();
private final Path extensionsDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("extensions"); private final Path extensionsDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("extensions");
public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws InvalidExtensionException { public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws Throwable {
if (path == null) { if (path == null) {
throw new InvalidExtensionException("Path is null"); throw new InvalidExtensionException("Path is null");
} }
@ -92,8 +92,14 @@ public class GeyserExtensionLoader extends ExtensionLoader {
this.classLoaders.put(description.id(), loader); this.classLoaders.put(description.id(), loader);
final Extension extension = loader.load(); try {
return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension)); final Extension extension = loader.load();
return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension));
} catch (Throwable e) {
// if the extension failed to load, remove its classloader and close it.
this.classLoaders.remove(description.id()).close();
throw e;
}
} }
private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) { private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) {
@ -182,9 +188,10 @@ public class GeyserExtensionLoader extends ExtensionLoader {
return; return;
} }
GeyserExtensionContainer container = this.loadExtension(path, description);
extensions.put(id, path); extensions.put(id, path);
loadedExtensions.put(id, this.loadExtension(path, description)); loadedExtensions.put(id, container);
} catch (Exception e) { } catch (Throwable e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e); GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e);
} }
}); });