summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/MobData.java
blob: 790cc631b2edb9ca725484948440291effd27347 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package com.earth2me.essentials;

import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.utils.StringUtil;
import java.util.*;
import java.util.logging.Logger;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Colorable;


public enum MobData
{
	BABY_AGEABLE("baby", Ageable.class, Data.BABY, true),
	ADULT_AGEABLE("adult", Ageable.class, Data.ADULT, true),
	BABY_PIG("piglet", EntityType.PIG, Data.BABY, false),
	BABY_WOLF("puppy", EntityType.WOLF, Data.BABY, false),
	BABY_CHICKEN("chick", EntityType.CHICKEN, Data.BABY, false),
	BABY_HORSE("colt", EntityType.HORSE, Data.BABY, false),
	BABY_OCELOT("kitten", EntityType.OCELOT, Data.BABY, false),
	BABY_SHEEP("lamb", EntityType.SHEEP, Data.BABY, false),
	BABY_COW("calf", EntityType.COW.getEntityClass(), Data.BABY, false),
	BABY_VILLAGER("child", EntityType.VILLAGER, Data.BABY, false),
	TAMED_TAMEABLE("tamed", Tameable.class, Data.TAMED, true),
	TAME_TAMEABLE("tame", Tameable.class, Data.TAMED, false),
	RANDOM_SHEEP("random", EntityType.SHEEP, Data.COLORABLE, true),
	COLORABLE_SHEEP("", StringUtil.joinList(DyeColor.values()).toLowerCase(Locale.ENGLISH), EntityType.SHEEP, Data.COLORABLE, true),
	DONKEY_HORSE("donkey", EntityType.HORSE, Horse.Variant.DONKEY, true),
	MULE_HORSE("mule", EntityType.HORSE, Horse.Variant.MULE, true),
	SKELETON_HORSE("skeleton", EntityType.HORSE, Horse.Variant.SKELETON_HORSE, true),
	UNDEAD_HORSE("undead", EntityType.HORSE, Horse.Variant.UNDEAD_HORSE, true),
	ZOMBIE_HORSE("zombie", EntityType.HORSE, Horse.Variant.UNDEAD_HORSE, false),
	POLKA_HORSE("polka", EntityType.HORSE, Horse.Style.BLACK_DOTS, true),
	SOOTY_HORSE("sooty", EntityType.HORSE, Horse.Style.BLACK_DOTS, false),
	BLAZE_HORSE("blaze", EntityType.HORSE, Horse.Style.WHITE, true),
	SOCKS_HORSE("socks", EntityType.HORSE, Horse.Style.WHITE, false),
	LEOPARD_HORSE("leopard", EntityType.HORSE, Horse.Style.WHITE_DOTS, true),
	APPALOOSA_HORSE("appaloosa", EntityType.HORSE, Horse.Style.WHITE_DOTS, false),
	PAINT_HORSE("paint", EntityType.HORSE, Horse.Style.WHITEFIELD, true),
	MILKY_HORSE("milky", EntityType.HORSE, Horse.Style.WHITEFIELD, false),
	SPLOTCHY_HORSE("splotchy", EntityType.HORSE, Horse.Style.WHITEFIELD, false),
	BLACK_HORSE("black", EntityType.HORSE, Horse.Color.BLACK, true),
	CHESTNUT_HORSE("chestnut", EntityType.HORSE, Horse.Color.CHESTNUT, true),
	LIVER_HORSE("liver", EntityType.HORSE, Horse.Color.CHESTNUT, false),
	CREAMY_HORSE("creamy", EntityType.HORSE, Horse.Color.CREAMY, true),
	FLAXEN_HORSE("flaxen", EntityType.HORSE, Horse.Color.CREAMY, false),
	GRAY_HORSE("gray", EntityType.HORSE, Horse.Color.GRAY, true),
	DAPPLE_HORSE("dapple", EntityType.HORSE, Horse.Color.GRAY, false),
	BUCKSKIN_HORSE("buckskin", EntityType.HORSE, Horse.Color.DARK_BROWN, true),
	DARKBROWN_HORSE("darkbrown", EntityType.HORSE, Horse.Color.DARK_BROWN, false),
	DARK_HORSE("dark", EntityType.HORSE, Horse.Color.DARK_BROWN, false),
	DBROWN_HORSE("dbrown", EntityType.HORSE, Horse.Color.DARK_BROWN, false),
	BAY_HORSE("bay", EntityType.HORSE, Horse.Color.BROWN, true),
	BROWN_HORSE("brown", EntityType.HORSE, Horse.Color.BROWN, false),
	CHEST_HORSE("chest", EntityType.HORSE, Data.CHEST, true),
	SADDLE_HORSE("saddle", EntityType.HORSE, Data.HORSESADDLE, true),
	GOLD_ARMOR_HORSE("goldarmor", EntityType.HORSE, Material.GOLD_BARDING, true),
	DIAMOND_ARMOR_HORSE("diamondarmor", EntityType.HORSE, Material.DIAMOND_BARDING, true),
	ARMOR_HORSE("armor", EntityType.HORSE, Material.IRON_BARDING, true),
	SIAMESE_CAT("siamese", EntityType.OCELOT, Ocelot.Type.SIAMESE_CAT, true),
	WHITE_CAT("white", EntityType.OCELOT, Ocelot.Type.SIAMESE_CAT, false),
	RED_CAT("red", EntityType.OCELOT, Ocelot.Type.RED_CAT, true),
	ORANGE_CAT("orange", EntityType.OCELOT, Ocelot.Type.RED_CAT, false),
	TABBY_CAT("tabby", EntityType.OCELOT, Ocelot.Type.RED_CAT, false),
	BLACK_CAT("black", EntityType.OCELOT, Ocelot.Type.BLACK_CAT, true),
	TUXEDO_CAT("tuxedo", EntityType.OCELOT, Ocelot.Type.BLACK_CAT, false),
	VILLAGER_ZOMBIE("villager", EntityType.ZOMBIE.getEntityClass(), Data.VILLAGER, true),
	BABY_ZOMBIE("baby", EntityType.ZOMBIE.getEntityClass(), Data.BABYZOMBIE, true),
	ADULT_ZOMBIE("adult", EntityType.ZOMBIE.getEntityClass(), Data.ADULTZOMBIE, true),
	DIAMOND_SWORD_ZOMBIE("diamondsword", EntityType.ZOMBIE.getEntityClass(), Material.DIAMOND_SWORD, true),
	GOLD_SWORD_ZOMBIE("goldsword", EntityType.ZOMBIE.getEntityClass(), Material.GOLD_SWORD, true),
	IRON_SWORD_ZOMBIE("ironsword", EntityType.ZOMBIE.getEntityClass(), Material.IRON_SWORD, true),
	STONE_SWORD_ZOMBIE("stonesword", EntityType.ZOMBIE.getEntityClass(), Material.STONE_SWORD, false),
	SWORD_ZOMBIE("sword", EntityType.ZOMBIE.getEntityClass(), Material.STONE_SWORD, true),
	DIAMOND_SWORD_SKELETON("diamondsword", EntityType.SKELETON, Material.DIAMOND_SWORD, true),
	GOLD_SWORD_SKELETON("goldsword", EntityType.SKELETON, Material.GOLD_SWORD, true),
	IRON_SWORD_SKELETON("ironsword", EntityType.SKELETON, Material.IRON_SWORD, true),
	STONE_SWORD_SKELETON("stonesword", EntityType.SKELETON, Material.STONE_SWORD, false),
	SWORD_SKELETON("sword", EntityType.SKELETON, Material.STONE_SWORD, true),
	BOW_SKELETON("bow", EntityType.SKELETON, Material.BOW, true),
	WHITHER_SKELETON("wither", EntityType.SKELETON, Data.WITHER, true),
	POWERED_CREEPER("powered", EntityType.CREEPER, Data.ELECTRIFIED, true),
	ELECTRIC_CREEPER("electric", EntityType.CREEPER, Data.ELECTRIFIED, false),
	CHARGED_CREEPER("charged", EntityType.CREEPER, Data.ELECTRIFIED, false),
	SADDLE_PIG("saddle", EntityType.PIG, Data.PIGSADDLE, true),
	ANGRY_WOLF("angry", EntityType.WOLF, Data.ANGRY, true),
	RABID_WOLF("rabid", EntityType.WOLF, Data.ANGRY, false),
	FARMER_VILLAGER("farmer", EntityType.VILLAGER, Villager.Profession.FARMER, true),
	LIBRARIAN_VILLAGER("librarian", EntityType.VILLAGER, Villager.Profession.LIBRARIAN, true),
	PRIEST_VILLAGER("priest", EntityType.VILLAGER, Villager.Profession.PRIEST, true),
	FATHER_VILLAGER("father", EntityType.VILLAGER, Villager.Profession.PRIEST, false),
	SMITH_VILLAGER("smith", EntityType.VILLAGER, Villager.Profession.BLACKSMITH, true),
	BUTCHER_VILLAGER("butcher", EntityType.VILLAGER, Villager.Profession.BUTCHER, true),
	SIZE_SLIME("", "<1-100>", EntityType.SLIME.getEntityClass(), Data.SIZE, true),
	NUM_EXPERIENCE_ORB("", "<1-2000000000>", EntityType.EXPERIENCE_ORB, Data.EXP, true);


	public enum Data
	{
		ADULT,
		BABY,
		CHEST,
		ADULTZOMBIE,
		BABYZOMBIE,
		VILLAGER,
		HORSESADDLE,
		PIGSADDLE,
		ELECTRIFIED,
		WITHER,
		ANGRY,
		TAMED,
		COLORABLE,
		EXP,
		SIZE;
	}
	public static final Logger logger = Logger.getLogger("Essentials");

	private MobData(String n, Object type, Object value, boolean isPublic)
	{
		this.nickname = n;
		this.matched = n;
		this.helpMessage = n;
		this.type = type;
		this.value = value;
		this.isPublic = isPublic;
	}

	private MobData(String n, String h, Object type, Object value, boolean isPublic)
	{
		this.nickname = n;
		this.matched = n;
		this.helpMessage = h;
		this.type = type;
		this.value = value;
		this.isPublic = isPublic;
	}
	final private String nickname;
	final private String helpMessage;
	final private Object type;
	final private Object value;
	final private boolean isPublic;
	private String matched;

	public static LinkedHashMap<String, MobData> getPossibleData(final Entity spawned, boolean publicOnly)
	{
		LinkedHashMap<String, MobData> mobList = new LinkedHashMap<String, MobData>();
		for (MobData data : MobData.values())
		{
			if (data.type instanceof EntityType && spawned.getType().equals(data.type) && ((publicOnly && data.isPublic) || !publicOnly))
			{
				mobList.put(data.nickname.toLowerCase(Locale.ENGLISH), data);
			}
			else if (data.type instanceof Class && ((Class)data.type).isAssignableFrom(spawned.getClass()) && ((publicOnly && data.isPublic) || !publicOnly))
			{
				mobList.put(data.nickname.toLowerCase(Locale.ENGLISH), data);
			}
		}

		return mobList;
	}

	public static List<String> getValidHelp(final Entity spawned)
	{
		List<String> output = new ArrayList<String>();
		LinkedHashMap<String, MobData> posData = getPossibleData(spawned, true);

		for (MobData data : posData.values())
		{
			output.add(data.helpMessage);
		}
		return output;
	}

	public static MobData fromData(final Entity spawned, final String name)
	{
		if (name.isEmpty())
		{
			return null;
		}

		LinkedHashMap<String, MobData> posData = getPossibleData(spawned, false);
		for (String data : posData.keySet())
		{
			if (name.contains(data))
			{
				return posData.get(data);
			}
		}
		return null;
	}

	public String getMatched()
	{
		return this.matched;
	}

	public void setData(final Entity spawned, final Player target, final String rawData) throws Exception
	{
		if (this.value.equals(Data.ANGRY))
		{
			((Wolf)spawned).setAngry(true);
		}
		else if (this.value.equals(Data.ADULT))
		{
			((Ageable)spawned).setAdult();
		}
		else if (this.value.equals(Data.BABY))
		{
			((Ageable)spawned).setBaby();
		}
		else if (this.value.equals(Data.ADULTZOMBIE))
		{
			((Zombie)spawned).setBaby(false);
		}
		else if (this.value.equals(Data.BABYZOMBIE))
		{
			((Zombie)spawned).setBaby(true);
		}
		else if (this.value.equals(Data.CHEST))
		{
			((Horse)spawned).setTamed(true);
			((Horse)spawned).setCarryingChest(true);
		}
		else if (this.value.equals(Data.ELECTRIFIED))
		{
			((Creeper)spawned).setPowered(true);
		}
		else if (this.value.equals(Data.HORSESADDLE))
		{
			final Horse horse = ((Horse)spawned);
			horse.setTamed(true);
			horse.setOwner(target);
			horse.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1));
		}
		else if (this.value.equals(Data.PIGSADDLE))
		{
			((Pig)spawned).setSaddle(true);
		}
		else if (this.value.equals(Data.TAMED))
		{
			final Tameable tameable = ((Tameable)spawned);
			tameable.setTamed(true);
			tameable.setOwner(target);
		}
		else if (this.value.equals(Data.VILLAGER))
		{
			((Zombie)spawned).setVillager(this.value.equals(Data.VILLAGER));
		}
		else if (this.value.equals(Data.WITHER))
		{
			((Skeleton)spawned).setSkeletonType(Skeleton.SkeletonType.WITHER);
		}
		else if (this.value.equals(Data.COLORABLE))
		{
			final String color = rawData.toUpperCase(Locale.ENGLISH);
			try
			{
				if (color.equals("RANDOM"))
				{
					final Random rand = new Random();
					((Colorable)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
				}
				else if (!color.isEmpty())
				{
					((Colorable)spawned).setColor(DyeColor.valueOf(color));
				}
				this.matched = rawData;
			}
			catch (Exception e)
			{
				throw new Exception(tl("sheepMalformedColor"), e);
			}
		}
		else if (this.value.equals(Data.EXP))
		{
			try
			{
				((ExperienceOrb)spawned).setExperience(Integer.parseInt(rawData));
				this.matched = rawData;
			}
			catch (NumberFormatException e)
			{
				throw new Exception(tl("invalidNumber"), e);
			}
		}
		else if (this.value.equals(Data.SIZE))
		{
			try
			{
				((Slime)spawned).setSize(Integer.parseInt(rawData));
				this.matched = rawData;
			}
			catch (NumberFormatException e)
			{
				throw new Exception(tl("slimeMalformedSize"), e);
			}
		}
		else if (this.value instanceof Horse.Color)
		{
			((Horse)spawned).setColor((Horse.Color)this.value);
		}
		else if (this.value instanceof Horse.Style)
		{
			((Horse)spawned).setStyle((Horse.Style)this.value);
		}
		else if (this.value instanceof Horse.Variant)
		{
			((Horse)spawned).setVariant((Horse.Variant)this.value);
		}
		else if (this.value instanceof Ocelot.Type)
		{
			((Ocelot)spawned).setCatType((Ocelot.Type)this.value);
		}
		else if (this.value instanceof Villager.Profession)
		{
			((Villager)spawned).setProfession((Villager.Profession)this.value);
		}
		else if (this.value instanceof Material)
		{
			if (this.type.equals(EntityType.HORSE))
			{
				((Horse)spawned).setTamed(true);
				((Horse)spawned).getInventory().setArmor(new ItemStack((Material)this.value, 1));
			}
			else if (this.type.equals(EntityType.ZOMBIE.getEntityClass()) || this.type.equals(EntityType.SKELETON))
			{
				final EntityEquipment invent = ((LivingEntity)spawned).getEquipment();
				invent.setItemInHand(new ItemStack((Material)this.value, 1));
				invent.setItemInHandDropChance(0.1f);
			}
		}
	}
}