Saber-Factions/src/main/java/com/massivecraft/factions/zcore/persist/EM.java
drtshock ddf054330a First implementation of scoreboards.
Boards can be toggled with /f sb. Toggles are persistent in a yml file.
Also fix some small spelling and format things that were really bugging me.
2014-08-05 10:17:27 -05:00

63 lines
2.3 KiB
Java

package com.massivecraft.factions.zcore.persist;
import java.util.LinkedHashMap;
import java.util.Map;
public class EM {
public static Map<Class<? extends Entity>, EntityCollection<? extends Entity>> class2Entities = new LinkedHashMap<Class<? extends Entity>, EntityCollection<? extends Entity>>();
@SuppressWarnings("unchecked")
public static <T extends Entity> EntityCollection<T> getEntitiesCollectionForEntityClass(Class<T> entityClass) {
return (EntityCollection<T>) class2Entities.get(entityClass);
}
public static void setEntitiesCollectionForEntityClass(Class<? extends Entity> entityClass, EntityCollection<? extends Entity> entities) {
class2Entities.put(entityClass, entities);
}
// -------------------------------------------- //
// ATTACH AND DETACH
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public static <T extends Entity> void attach(T entity) {
EntityCollection<T> ec = (EntityCollection<T>) getEntitiesCollectionForEntityClass(entity.getClass());
ec.attach(entity);
}
@SuppressWarnings("unchecked")
public static <T extends Entity> void detach(T entity) {
EntityCollection<T> ec = (EntityCollection<T>) getEntitiesCollectionForEntityClass(entity.getClass());
ec.detach(entity);
}
@SuppressWarnings("unchecked")
public static <T extends Entity> boolean attached(T entity) {
EntityCollection<T> ec = (EntityCollection<T>) getEntitiesCollectionForEntityClass(entity.getClass());
return ec.attached(entity);
}
@SuppressWarnings("unchecked")
public static <T extends Entity> boolean detached(T entity) {
EntityCollection<T> ec = (EntityCollection<T>) getEntitiesCollectionForEntityClass(entity.getClass());
return ec.detached(entity);
}
// -------------------------------------------- //
// DISC
// -------------------------------------------- //
public static void saveAllToDisc() {
for (EntityCollection<? extends Entity> ec : class2Entities.values()) {
ec.saveToDisc();
}
}
public static void loadAllFromDisc() {
for (EntityCollection<? extends Entity> ec : class2Entities.values()) {
ec.loadFromDisc();
}
}
}