2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.config.mods;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2013-09-24 18:24:59 +02:00
|
|
|
import java.util.HashMap;
|
2013-03-01 06:52:01 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
import org.apache.commons.lang.ClassUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.config.ConfigLoader;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
|
|
|
|
|
|
|
public class CustomEntityConfig extends ConfigLoader {
|
|
|
|
private static CustomEntityConfig instance;
|
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
public List<String> customHostileEntityTypes = new ArrayList<String>();
|
|
|
|
public List<String> customNeutralEntityTypes = new ArrayList<String>();
|
|
|
|
public List<String> customPassiveEntityTypes = new ArrayList<String>();
|
|
|
|
public List<String> customEntityTypes = new ArrayList<String>();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
public HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
|
|
|
|
public HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public CustomEntityConfig() {
|
|
|
|
super("ModConfigs", "entities.yml");
|
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomEntityConfig getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new CustomEntityConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadKeys() {
|
2013-09-24 18:24:59 +02:00
|
|
|
loadMobs("Hostile", customHostileEntityTypes);
|
|
|
|
loadMobs("Neutral", customNeutralEntityTypes);
|
|
|
|
loadMobs("Passive", customPassiveEntityTypes);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
private void loadMobs(String entityType, List<String> entityTypeList) {
|
2013-03-01 06:52:01 +01:00
|
|
|
ConfigurationSection entitySection = config.getConfigurationSection(entityType);
|
|
|
|
|
|
|
|
if (entitySection == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> entityConfigSet = entitySection.getKeys(false);
|
|
|
|
|
|
|
|
for (String entityName : entityConfigSet) {
|
2013-09-24 18:24:59 +02:00
|
|
|
Class<?> clazz = null;
|
|
|
|
String className = config.getString(entityType + "." + entityName + ".Class", "");
|
|
|
|
|
|
|
|
try {
|
|
|
|
clazz = ClassUtils.getClass(className);
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException e) {
|
|
|
|
plugin.getLogger().warning("Invalid class (" + className + ") detected for " + entityName + ".");
|
|
|
|
plugin.getLogger().warning("This custom entity may not function properly.");
|
|
|
|
}
|
|
|
|
|
|
|
|
String entityTypeName = entityName.replace("_", ".");
|
2013-03-01 06:52:01 +01:00
|
|
|
double xpMultiplier = config.getDouble(entityType + "." + entityName + ".XP_Multiplier", 1.0D);
|
|
|
|
boolean canBeTamed = config.getBoolean(entityType + "." + entityName + ".Tameable", false);
|
|
|
|
int tamingXp = config.getInt(entityType + "." + entityName + "Taming_XP", 0);
|
|
|
|
boolean canBeSummoned = config.getBoolean(entityType + "." + entityName + "CanBeSummoned", false);
|
|
|
|
int callOfTheWildId = config.getInt(entityType + "." + entityName + "COTW_Material_ID", 0);
|
|
|
|
int callOfTheWildData = config.getInt(entityType + "." + entityName + "COTW_Material_Data", 0);
|
|
|
|
int callOfTheWildAmount = config.getInt(entityType + "." + entityName + "COTW_Material_Amount", 0);
|
|
|
|
|
|
|
|
CustomEntity entity;
|
|
|
|
|
|
|
|
if (canBeSummoned && (callOfTheWildId == 0 || callOfTheWildAmount == 0)) {
|
|
|
|
plugin.getLogger().warning("Incomplete Call of the Wild information. This enitity will not be able to be summoned by Call of the Wild.");
|
|
|
|
canBeSummoned = false;
|
|
|
|
}
|
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
entity = new CustomEntity(xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-09-24 18:24:59 +02:00
|
|
|
entityTypeList.add(entityTypeName);
|
|
|
|
customEntityTypeMap.put(entityTypeName, entity);
|
|
|
|
customEntityClassMap.put(clazz == null ? null : clazz.getName(), entity);
|
|
|
|
customEntityTypes.add(entityTypeName);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|