/
CustomEntityLegacyConfig.java
61 lines (48 loc) · 2.64 KB
/
CustomEntityLegacyConfig.java
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
package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.config.LegacyConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomEntity;
import com.gmail.nossr50.mcMMO;
import org.apache.commons.lang.ClassUtils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
public class CustomEntityLegacyConfig extends LegacyConfigLoader {
public HashMap<String, CustomEntity> customEntityClassMap = new HashMap<>();
public HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<>();
protected CustomEntityLegacyConfig(String fileName) {
super("mods", fileName);
loadKeys();
}
@Override
protected void loadKeys() {
if (config.getConfigurationSection("Hostile") != null) {
backup();
return;
}
for (String entityName : config.getKeys(false)) {
Class<?> clazz = null;
String className = config.getString(entityName + ".Class", "");
try {
clazz = ClassUtils.getClass(className);
} catch (ClassNotFoundException e) {
mcMMO.p.getLogger().warning("Invalid class (" + className + ") detected for " + entityName + ".");
mcMMO.p.getLogger().warning("This custom entity may not function properly.");
}
String entityTypeName = entityName.replace("_", ".");
double xpMultiplier = config.getDouble(entityName + ".XP_Multiplier", 1.0D);
boolean canBeTamed = config.getBoolean(entityName + ".Tameable");
int tamingXp = config.getInt(entityName + ".Taming_XP");
boolean canBeSummoned = config.getBoolean(entityName + ".CanBeSummoned");
Material callOfTheWildMaterial = Material.matchMaterial(config.getString(entityName + ".COTW_Material", ""));
byte callOfTheWildData = (byte) config.getInt(entityName + ".COTW_Material_Data");
int callOfTheWildAmount = config.getInt(entityName + ".COTW_Material_Amount");
if (canBeSummoned && (callOfTheWildMaterial == null || callOfTheWildAmount == 0)) {
mcMMO.p.getLogger().warning("Incomplete Call of the Wild information. This entity will not be able to be summoned by Call of the Wild.");
canBeSummoned = false;
}
CustomEntity entity = new CustomEntity(xpMultiplier, canBeTamed, tamingXp, canBeSummoned, (canBeSummoned ? new ItemStack(callOfTheWildMaterial) : null), callOfTheWildAmount);
customEntityTypeMap.put(entityTypeName, entity);
customEntityClassMap.put(clazz == null ? null : clazz.getName(), entity);
}
}
}