mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 22:07:59 +01:00
37 lines
959 B
Java
37 lines
959 B
Java
package com.minelittlepony.unicopia.spell;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.concurrent.Callable;
|
|
|
|
public class SpellRegistry {
|
|
|
|
private static final SpellRegistry instance = new SpellRegistry();
|
|
|
|
public static SpellRegistry instance() {
|
|
return instance;
|
|
}
|
|
|
|
private final Map<String, Callable<IMagicEffect>> factories = new HashMap<>();
|
|
|
|
private SpellRegistry() {
|
|
registerSpell("shield", SpellShield::new);
|
|
}
|
|
|
|
public Optional<IMagicEffect> getSpellFromName(String name) {
|
|
try {
|
|
if (factories.containsKey(name)) {
|
|
return Optional.ofNullable(factories.get(name).call());
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return Optional.empty();
|
|
}
|
|
|
|
public void registerSpell(String key, Callable<IMagicEffect> factory) {
|
|
factories.put(key, factory);
|
|
}
|
|
}
|