summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/bukkit/LivingEntities.java
blob: 7057eb399b97b0418f04e5889667cb65d0fec412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package net.ess3.bukkit;

import java.util.*;
import static net.ess3.I18n._;
import org.bukkit.entity.EntityType;


public class LivingEntities
{
	final private static Map<String, EntityType> entities = new HashMap<String, EntityType>();
	final private static EnumMap<EntityType, String> entityI18n = new EnumMap<EntityType, String>(EntityType.class);
	final private static EnumMap<EntityType, String> entityI18nPlural = new EnumMap<EntityType, String>(EntityType.class);

	static
	{
		for (EntityType entityType : EntityType.values())
		{
			if (entityType.isAlive() && entityType.isSpawnable())
			{
				String entityName = entityType.name().toLowerCase(Locale.ENGLISH).replace("_", "");
				entities.put(entityName, entityType);
				entityI18n.put(entityType, entityName);
				entityI18nPlural.put(entityType, entityName + "Plural");
			}
		}
	}

	public static Set<String> getLivingEntityList()
	{
		return Collections.unmodifiableSet(entities.keySet());
	}

	public static EntityType fromName(final String name)
	{
		return entities.get(name.toLowerCase(Locale.ENGLISH));
	}

	public static String getName(int count, EntityType type)
	{
		return count == 1 ? _(entityI18n.get(type)) : _(entityI18nPlural.get(type));
	}


	public static class MobException extends Exception
	{
		private static final long serialVersionUID = 1L;
	}
}