From 3ada95144e3fb3854915e0b1e58fbcc29271f5e1 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Tue, 27 Aug 2024 17:59:09 +0100 Subject: [PATCH] Address review comments --- .../geyser/extension/GeyserExtensionLoader.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java index a4e9fcc89..c35f6342d 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -168,13 +168,15 @@ public class GeyserExtensionLoader extends ExtensionLoader { Path updateDirectory = extensionsDirectory.resolve("update"); if (Files.isDirectory(updateDirectory)) { - // Get the current extensions and store them in a map + // Step 1: Collect the extension files that currently exist so they can be replaced Map> extensionFiles = new HashMap<>(); - this.processExtensionsFolder(extensionsDirectory, (path, description) -> extensionFiles.computeIfAbsent(description.id(), k -> new ArrayList<>()).add(path), (path, e) -> { + this.processExtensionsFolder(extensionsDirectory, (path, description) -> { + extensionFiles.computeIfAbsent(description.id(), k -> new ArrayList<>()).add(path); + }, (path, e) -> { // this file will throw again when we actually try to load extensions, and it will be handled there }); - // Perform the updates + // Step 2: Move the updated/new extensions this.processExtensionsFolder(updateDirectory, (path, description) -> { // Remove the old extension files with the same ID if it exists List oldExtensionFiles = extensionFiles.get(description.id()); @@ -191,6 +193,7 @@ public class GeyserExtensionLoader extends ExtensionLoader { }); } + // Step 3: Load the extensions this.processExtensionsFolder(extensionsDirectory, (path, description) -> { String name = description.name(); String id = description.id(); @@ -224,6 +227,7 @@ public class GeyserExtensionLoader extends ExtensionLoader { GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e); }); + // Step 4: Register the extensions for (GeyserExtensionContainer container : loadedExtensions.values()) { this.extensionContainers.put(container.extension(), container); this.register(container.extension(), extensionManager);