Fix duplicate expansion loading (#866)

This commit is contained in:
Andre_601 2023-03-17 18:47:27 +01:00 committed by GitHub
parent e246473782
commit d5c371004c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -53,6 +53,7 @@ import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.Msg;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
@ -268,8 +269,7 @@ public final class CloudExpansionManager {
await.remove(toIndexName(expansion)); await.remove(toIndexName(expansion));
if (exception != null) { if (exception != null) {
plugin.getLogger().log(Level.SEVERE, Msg.severe("Failed to download %s:%s", exception, expansion.getName(), expansion.getVersion());
"failed to download " + expansion.getName() + ":" + version.getVersion(), exception);
} }
}, ASYNC_EXECUTOR); }, ASYNC_EXECUTOR);

View File

@ -217,6 +217,12 @@ public final class LocalExpansionManager implements Listener {
return false; 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) { if (expansion instanceof Configurable) {
Map<String, Object> defaults = ((Configurable) expansion).getDefaults(); Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
String pre = "expansions." + identifier + "."; String pre = "expansions." + identifier + ".";
@ -388,7 +394,7 @@ public final class LocalExpansionManager implements Listener {
@NotNull @NotNull
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() { public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar")); File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
if(files == null){ if (files == null) {
return CompletableFuture.completedFuture(Collections.emptyList()); return CompletableFuture.completedFuture(Collections.emptyList());
} }