Skip to content

Commit

Permalink
Use a map for modern addon tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed Sep 29, 2024
1 parent f609017 commit 0c30aba
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/main/java/org/skriptlang/skript/SkriptImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import org.skriptlang.skript.util.Registry;

import java.util.Collection;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

Expand Down Expand Up @@ -69,27 +68,26 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
* SkriptAddon Management
*/

private static final Set<SkriptAddon> addons = new HashSet<>();
private static final Map<String, SkriptAddon> addons = new HashMap<>();

@Override
public SkriptAddon registerAddon(Class<?> source, String name) {
// make sure an addon is not already registered with this name
for (SkriptAddon addon : addons) {
if (name.equals(addon.name())) {
throw new SkriptAPIException(
"An addon (provided by '" + addon.source().getName() + "') with the name '" + name + "' is already registered"
);
}
SkriptAddon existing = addons.get(name);
if (existing != null) {
throw new SkriptAPIException(
"An addon (provided by '" + existing.source().getName() + "') with the name '" + name + "' is already registered"
);
}

SkriptAddon addon = new SkriptAddonImpl(this, source, name, null);
addons.add(addon);
addons.put(name, addon);
return addon;
}

@Override
public @Unmodifiable Collection<SkriptAddon> addons() {
return ImmutableSet.copyOf(addons);
return ImmutableSet.copyOf(addons.values());
}

/*
Expand Down

0 comments on commit 0c30aba

Please sign in to comment.