3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-03 16:31:14 +02:00

Allow cleanup of multiple old extensions

Dieser Commit ist enthalten in:
rtm516 2024-08-10 11:12:07 +01:00
Ursprung 37a608444a
Commit e0df59d31a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 331715B8B007C67A

Datei anzeigen

@ -52,6 +52,7 @@ import java.nio.file.Files;
import java.nio.file.NoSuchFileException; import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -168,17 +169,19 @@ public class GeyserExtensionLoader extends ExtensionLoader {
Path updateDirectory = extensionsDirectory.resolve("update"); Path updateDirectory = extensionsDirectory.resolve("update");
if (Files.isDirectory(updateDirectory)) { if (Files.isDirectory(updateDirectory)) {
// Get the current extensions and store them in a map // Get the current extensions and store them in a map
Map<String, Path> extensionFiles = new HashMap<>(); Map<String, List<Path>> extensionFiles = new HashMap<>();
this.processExtensionsFolder(extensionsDirectory, (path, description) -> extensionFiles.put(description.id(), 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 // this file will throw again when we actually try to load extensions, and it will be handled there
}); });
// Perform the updates // Perform the updates
this.processExtensionsFolder(updateDirectory, (path, description) -> { this.processExtensionsFolder(updateDirectory, (path, description) -> {
// Remove the old extension with the same ID if it exists // Remove the old extension files with the same ID if it exists
Path oldExtensionFile = extensionFiles.get(description.id()); List<Path> oldExtensionFiles = extensionFiles.get(description.id());
if (oldExtensionFile != null && Files.exists(oldExtensionFile)) { if (oldExtensionFiles != null) {
Files.delete(extensionFiles.get(description.id())); for (Path oldExtensionFile : oldExtensionFiles) {
Files.delete(oldExtensionFile);
}
} }
// Overwrite the extension with the new jar // Overwrite the extension with the new jar