From d5c371004c28b800b55efe4029a736185b169b20 Mon Sep 17 00:00:00 2001 From: Andre_601 Date: Fri, 17 Mar 2023 18:47:27 +0100 Subject: [PATCH] Fix duplicate expansion loading (#866) --- .../expansion/manager/CloudExpansionManager.java | 4 ++-- .../expansion/manager/LocalExpansionManager.java | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java index 5032698..11d7cb3 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java @@ -53,6 +53,7 @@ import java.util.stream.Collectors; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.cloud.CloudExpansion; +import me.clip.placeholderapi.util.Msg; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -268,8 +269,7 @@ public final class CloudExpansionManager { await.remove(toIndexName(expansion)); if (exception != null) { - plugin.getLogger().log(Level.SEVERE, - "failed to download " + expansion.getName() + ":" + version.getVersion(), exception); + Msg.severe("Failed to download %s:%s", exception, expansion.getName(), expansion.getVersion()); } }, ASYNC_EXECUTOR); diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java index 8f11d3f..c6d1ca6 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java @@ -216,6 +216,12 @@ public final class LocalExpansionManager implements Listener { if (!expansion.canRegister()) { return false; } + + if (expansions.containsKey(identifier)) { + Msg.warn("Failed to load expansion %s. Identifier is already in use.", + expansion.getIdentifier()); + return false; + } if (expansion instanceof Configurable) { Map defaults = ((Configurable) expansion).getDefaults(); @@ -388,7 +394,7 @@ public final class LocalExpansionManager implements Listener { @NotNull public CompletableFuture<@NotNull List<@Nullable Class>> findExpansionsOnDisk() { File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar")); - if(files == null){ + if (files == null) { return CompletableFuture.completedFuture(Collections.emptyList()); }