From e0df59d31aa00dfe8fb915fc103fe251726bb9fe Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 10 Aug 2024 11:12:07 +0100 Subject: [PATCH] Allow cleanup of multiple old extensions --- .../geyser/extension/GeyserExtensionLoader.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 801055c51..a4e9fcc89 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -52,6 +52,7 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -168,17 +169,19 @@ public class GeyserExtensionLoader extends ExtensionLoader { Path updateDirectory = extensionsDirectory.resolve("update"); if (Files.isDirectory(updateDirectory)) { // Get the current extensions and store them in a map - Map extensionFiles = new HashMap<>(); - this.processExtensionsFolder(extensionsDirectory, (path, description) -> extensionFiles.put(description.id(), path), (path, e) -> { + Map> extensionFiles = new HashMap<>(); + 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 this.processExtensionsFolder(updateDirectory, (path, description) -> { - // Remove the old extension with the same ID if it exists - Path oldExtensionFile = extensionFiles.get(description.id()); - if (oldExtensionFile != null && Files.exists(oldExtensionFile)) { - Files.delete(extensionFiles.get(description.id())); + // Remove the old extension files with the same ID if it exists + List oldExtensionFiles = extensionFiles.get(description.id()); + if (oldExtensionFiles != null) { + for (Path oldExtensionFile : oldExtensionFiles) { + Files.delete(oldExtensionFile); + } } // Overwrite the extension with the new jar