simple.client.entity.EntityMap Maven / Gradle / Ivy
package simple.client.entity;
import java.util.HashMap;
import java.util.Map;
import marauroa.common.Pair;
/**
* Registers the relationship between Type, eclass and java class of entity
* Objects.
*
* eclass represents a subtype of type
*
* EntityMap encapsulates the implementation
*
*/
public final class EntityMap {
private static Map, Class extends ClientEntity>> entityMap = new HashMap, Class extends ClientEntity>>();
static {
register();
}
/**
* Fills EntityMap with initial values.
*/
private static void register() {
register("player", null, ClientRPEntity.class);
/*
* Not sure whether to register individual pets from child classes, or
* the whole parent class Pet. suggestions welcome.
*/
register("npc", null, NPC.class);
/* I might add items later, belts?
register("chest", null, Chest.class);
register("item", null, Item.class);
register("item", "box", Box.class);
register("item", "drink", StackableItem.class);
* */
}
/**
* @param type
* the type of the entity to be created, such as Item, creature
* @param eclass
* the subtype of type such as book, drink, food , ,
* small_animal, huge_animal
* @param entityClazz
* the java class of the ClientEntity
*/
private static void register(final String type, final String eclass,
final Class extends ClientEntity> entityClazz) {
entityMap.put(new Pair(type, eclass), entityClazz);
}
/**
* @param type
* the type of the entity to be created, such as Item, creature
* @param eclass
* the subtype of type such as book, drink, food , ,
* small_animal, huge_animal
*
* @return the java class of the ClientEntity belonging to type and eclass
*/
public static Class extends ClientEntity> getClass(final String type,
final String eclass) {
return entityMap.get(new Pair(type, eclass));
}
}