2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.api.registry;
|
2015-10-31 17:58:47 -07:00
|
|
|
|
2015-11-02 12:39:44 -08:00
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
2015-10-31 17:58:47 -07:00
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.google.common.collect.HashBiMap;
|
|
|
|
import java.util.ArrayList;
|
2015-11-03 07:35:14 -08:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2015-10-31 17:58:47 -07:00
|
|
|
|
|
|
|
public class RitualRegistry {
|
|
|
|
|
2015-11-03 07:35:14 -08:00
|
|
|
public static final Map<Ritual, Boolean> enabledRituals = new HashMap<Ritual, Boolean>();
|
2015-10-31 17:58:47 -07:00
|
|
|
private static final BiMap<String, Ritual> registry = HashBiMap.create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The safe way to register a new Ritual.
|
|
|
|
*
|
|
|
|
* @param ritual - The ritual to register.
|
|
|
|
* @param id - The ID for the ritual. Cannot be duplicated.
|
|
|
|
*/
|
|
|
|
public static void registerRitual(Ritual ritual, String id) {
|
|
|
|
if (ritual != null) {
|
|
|
|
if (registry.containsKey(id))
|
2015-11-02 12:39:44 -08:00
|
|
|
BloodMagicAPI.getLogger().error("Duplicate ritual id: " + id);
|
2015-10-31 17:58:47 -07:00
|
|
|
else
|
|
|
|
registry.put(id, ritual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Ritual getRitualForId(String id) {
|
|
|
|
return registry.get(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getIdForRitual(Ritual ritual) {
|
|
|
|
return registry.inverse().get(ritual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isMapEmpty() {
|
|
|
|
return registry.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getMapSize() {
|
|
|
|
return registry.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean ritualEnabled(Ritual ritual) {
|
2015-11-02 17:45:11 -08:00
|
|
|
try {
|
|
|
|
return enabledRituals.get(ritual);
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
BloodMagicAPI.getLogger().error("Invalid Ritual was called");
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-31 17:58:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static BiMap<String, Ritual> getRegistry() {
|
|
|
|
return HashBiMap.create(registry);
|
|
|
|
}
|
|
|
|
|
2015-11-03 07:35:14 -08:00
|
|
|
public static Map<Ritual, Boolean> getEnabledMap() {
|
|
|
|
return new HashMap<Ritual, Boolean>(enabledRituals);
|
2015-11-02 17:45:11 -08:00
|
|
|
}
|
|
|
|
|
2015-10-31 17:58:47 -07:00
|
|
|
public static ArrayList<String> getIds() {
|
|
|
|
return new ArrayList<String>(registry.keySet());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ArrayList<Ritual> getRituals() {
|
|
|
|
return new ArrayList<Ritual>(registry.values());
|
|
|
|
}
|
|
|
|
}
|