mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Add custom mobs automatically as they're killed.
This commit is contained in:
@ -114,4 +114,8 @@ public abstract class ConfigLoader {
|
||||
plugin.noErrorsInConfigFiles = false;
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return configFile;
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,10 @@ public class CustomArmorConfig extends ConfigLoader {
|
||||
|
||||
private List<Repairable> repairables;
|
||||
|
||||
public List<Material> customBoots = new ArrayList<Material>();
|
||||
public List<Material> customChestplates = new ArrayList<Material>();
|
||||
public List<Material> customHelmets = new ArrayList<Material>();
|
||||
public List<Material> customLeggings = new ArrayList<Material>();
|
||||
public List<Material> customArmor = new ArrayList<Material>();
|
||||
private List<Material> customBoots = new ArrayList<Material>();
|
||||
private List<Material> customChestplates = new ArrayList<Material>();
|
||||
private List<Material> customHelmets = new ArrayList<Material>();
|
||||
private List<Material> customLeggings = new ArrayList<Material>();
|
||||
|
||||
public CustomArmorConfig() {
|
||||
super("ModConfigs", "armor.yml");
|
||||
@ -100,7 +99,22 @@ public class CustomArmorConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
materialList.add(armorMaterial);
|
||||
customArmor.add(armorMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCustomBoots(Material material) {
|
||||
return customBoots.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomChestplate(Material material) {
|
||||
return customChestplates.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomHelmet(Material material) {
|
||||
return customHelmets.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomLeggings(Material material) {
|
||||
return customLeggings.contains(material);
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,16 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
public class CustomBlockConfig extends ConfigLoader {
|
||||
private static CustomBlockConfig instance;
|
||||
|
||||
public List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customWoodcuttingBlocks = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customOres = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customLogs = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customLeaves = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customAbilityBlocks = new ArrayList<MaterialData>();
|
||||
public List<MaterialData> customItems = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customWoodcuttingBlocks = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customOres = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customLogs = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customLeaves = new ArrayList<MaterialData>();
|
||||
private List<MaterialData> customAbilityBlocks = new ArrayList<MaterialData>();
|
||||
|
||||
public HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
|
||||
private HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
|
||||
|
||||
public CustomBlockConfig() {
|
||||
super("ModConfigs", "blocks.yml");
|
||||
@ -65,7 +64,7 @@ public class CustomBlockConfig extends ConfigLoader {
|
||||
Material blockMaterial = Material.matchMaterial(blockInfo[0]);
|
||||
|
||||
if (blockMaterial == null) {
|
||||
plugin.getLogger().warning("Invalid material name. This item will be skipped.");
|
||||
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + blockInfo[0]);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -77,16 +76,13 @@ public class CustomBlockConfig extends ConfigLoader {
|
||||
continue;
|
||||
}
|
||||
|
||||
customItems.add(blockMaterialData);
|
||||
|
||||
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain");
|
||||
int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
|
||||
|
||||
boolean shouldDropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item");
|
||||
Material dropMaterial = Material.matchMaterial(config.getString(skillType + "." + blockName + ".Drop_Item_Name"));
|
||||
|
||||
if (shouldDropItem && dropMaterial == null) {
|
||||
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
|
||||
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself. - " + blockInfo[0]);
|
||||
shouldDropItem = false;
|
||||
}
|
||||
|
||||
@ -103,8 +99,6 @@ public class CustomBlockConfig extends ConfigLoader {
|
||||
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
|
||||
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
|
||||
|
||||
CustomBlock block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, blockData, blockMaterial);
|
||||
|
||||
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
|
||||
customOres.add(blockMaterialData);
|
||||
}
|
||||
@ -114,11 +108,47 @@ public class CustomBlockConfig extends ConfigLoader {
|
||||
}
|
||||
else {
|
||||
customLeaves.add(blockMaterialData);
|
||||
block.setXpGain(0); // Leaves don't grant XP
|
||||
xp = 0; // Leaves don't grant XP
|
||||
}
|
||||
}
|
||||
|
||||
customBlockMap.put(blockMaterialData, block);
|
||||
customBlockMap.put(blockMaterialData, new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, xp));
|
||||
}
|
||||
}
|
||||
|
||||
public CustomBlock getCustomBlock(MaterialData data) {
|
||||
return customBlockMap.get(data);
|
||||
}
|
||||
|
||||
public boolean isCustomOre(MaterialData data) {
|
||||
return customOres.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomLog(MaterialData data) {
|
||||
return customLogs.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomLeaf(MaterialData data) {
|
||||
return customLeaves.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomAbilityBlock(MaterialData data) {
|
||||
return customAbilityBlocks.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomExcavationBlock(MaterialData data) {
|
||||
return customExcavationBlocks.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomHerbalismBlock(MaterialData data) {
|
||||
return customHerbalismBlocks.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomMiningBlock(MaterialData data) {
|
||||
return customMiningBlocks.contains(data);
|
||||
}
|
||||
|
||||
public boolean isCustomWoodcuttingBlock(MaterialData data) {
|
||||
return customWoodcuttingBlocks.contains(data);
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,21 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
||||
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
|
||||
public class CustomEntityConfig extends ConfigLoader {
|
||||
private static CustomEntityConfig instance;
|
||||
|
||||
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>();
|
||||
|
||||
public HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
|
||||
public HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
|
||||
private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
|
||||
private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
|
||||
|
||||
public CustomEntityConfig() {
|
||||
super("ModConfigs", "entities.yml");
|
||||
@ -38,23 +32,9 @@ public class CustomEntityConfig extends ConfigLoader {
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
loadMobs("Hostile", customHostileEntityTypes);
|
||||
loadMobs("Neutral", customNeutralEntityTypes);
|
||||
loadMobs("Passive", customPassiveEntityTypes);
|
||||
}
|
||||
|
||||
private void loadMobs(String entityType, List<String> entityTypeList) {
|
||||
ConfigurationSection entitySection = config.getConfigurationSection(entityType);
|
||||
|
||||
if (entitySection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> entityConfigSet = entitySection.getKeys(false);
|
||||
|
||||
for (String entityName : entityConfigSet) {
|
||||
for (String entityName : config.getKeys(false)) {
|
||||
Class<?> clazz = null;
|
||||
String className = config.getString(entityType + "." + entityName + ".Class", "");
|
||||
String className = config.getString(entityName + ".Class", "");
|
||||
|
||||
try {
|
||||
clazz = ClassUtils.getClass(className);
|
||||
@ -65,27 +45,68 @@ public class CustomEntityConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
String entityTypeName = entityName.replace("_", ".");
|
||||
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);
|
||||
double xpMultiplier = config.getDouble(entityName + ".XP_Multiplier", 1.0D);
|
||||
|
||||
CustomEntity entity;
|
||||
boolean canBeTamed = config.getBoolean(entityName + ".Tameable");
|
||||
int tamingXp = config.getInt(entityName + ".Taming_XP");
|
||||
|
||||
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.");
|
||||
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)) {
|
||||
plugin.getLogger().warning("Incomplete Call of the Wild information. This entity will not be able to be summoned by Call of the Wild.");
|
||||
canBeSummoned = false;
|
||||
}
|
||||
|
||||
entity = new CustomEntity(xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount);
|
||||
CustomEntity entity = new CustomEntity(xpMultiplier, canBeTamed, tamingXp, canBeSummoned, (canBeSummoned ? new MaterialData(callOfTheWildMaterial, callOfTheWildData).toItemStack(1) : null), callOfTheWildAmount);
|
||||
|
||||
entityTypeList.add(entityTypeName);
|
||||
customEntityTypeMap.put(entityTypeName, entity);
|
||||
customEntityClassMap.put(clazz == null ? null : clazz.getName(), entity);
|
||||
customEntityTypes.add(entityTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCustomEntity(Entity entity) {
|
||||
if (customEntityTypeMap.containsKey(entity.getType().toString())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return customEntityClassMap.containsKey(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
|
||||
return customEntityClassMap.containsKey(entity.getClass().getName());
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public CustomEntity getCustomEntity(Entity entity) {
|
||||
CustomEntity customEntity = customEntityTypeMap.get(entity.getType().toString());
|
||||
|
||||
if (customEntity == null) {
|
||||
try {
|
||||
customEntity = customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
|
||||
customEntity = customEntityClassMap.get(entity.getClass().getName());
|
||||
}
|
||||
else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return customEntity;
|
||||
}
|
||||
|
||||
public void addEntity(CustomEntity customEntity, String className, String entityName) {
|
||||
customEntityTypeMap.put(entityName, customEntity);
|
||||
customEntityClassMap.put(className, customEntity);
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,14 @@ public class CustomToolConfig extends ConfigLoader {
|
||||
private static CustomToolConfig instance;
|
||||
private List<Repairable> repairables;
|
||||
|
||||
public List<Material> customAxes = new ArrayList<Material>();
|
||||
public List<Material> customBows = new ArrayList<Material>();
|
||||
public List<Material> customHoes = new ArrayList<Material>();
|
||||
public List<Material> customPickaxes = new ArrayList<Material>();
|
||||
public List<Material> customShovels = new ArrayList<Material>();
|
||||
public List<Material> customSwords = new ArrayList<Material>();
|
||||
public List<Material> customTool = new ArrayList<Material>();
|
||||
private List<Material> customAxes = new ArrayList<Material>();
|
||||
private List<Material> customBows = new ArrayList<Material>();
|
||||
private List<Material> customHoes = new ArrayList<Material>();
|
||||
private List<Material> customPickaxes = new ArrayList<Material>();
|
||||
private List<Material> customShovels = new ArrayList<Material>();
|
||||
private List<Material> customSwords = new ArrayList<Material>();
|
||||
|
||||
public HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
|
||||
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
|
||||
|
||||
private CustomToolConfig() {
|
||||
super("ModConfigs", "tools.yml");
|
||||
@ -77,7 +76,7 @@ public class CustomToolConfig extends ConfigLoader {
|
||||
Material toolMaterial = Material.matchMaterial(toolName);
|
||||
|
||||
if (toolMaterial == null) {
|
||||
plugin.getLogger().warning("Invalid material name. This item will be skipped.");
|
||||
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + toolName);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -85,7 +84,7 @@ public class CustomToolConfig extends ConfigLoader {
|
||||
Material repairMaterial = Material.matchMaterial(config.getString(toolType + "." + toolName + ".Repair_Material", ""));
|
||||
|
||||
if (repairMaterial == null) {
|
||||
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
|
||||
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + toolName);
|
||||
repairable = false;
|
||||
}
|
||||
|
||||
@ -113,9 +112,39 @@ public class CustomToolConfig extends ConfigLoader {
|
||||
CustomTool tool = new CustomTool(tier, abilityEnabled, multiplier);
|
||||
|
||||
materialList.add(toolMaterial);
|
||||
customTool.add(toolMaterial);
|
||||
customToolMap.put(toolMaterial, tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCustomAxe(Material material) {
|
||||
return customAxes.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomBow(Material material) {
|
||||
return customBows.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomHoe(Material material) {
|
||||
return customHoes.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomPickaxe(Material material) {
|
||||
return customPickaxes.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomShovel(Material material) {
|
||||
return customShovels.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomSword(Material material) {
|
||||
return customSwords.contains(material);
|
||||
}
|
||||
|
||||
public boolean isCustomTool(Material material) {
|
||||
return customToolMap.containsKey(material);
|
||||
}
|
||||
|
||||
public CustomTool getCustomTool(Material material) {
|
||||
return customToolMap.get(material);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user