Made mod config files modular. Addresses #1802

This commit is contained in:
GJ 2014-02-03 14:48:43 -05:00
parent 62b13a9a84
commit 0c9836eb03
27 changed files with 555 additions and 514 deletions

View File

@ -20,6 +20,7 @@ Version 1.4.08-dev
+ Added new experience bonus perk 'mcmmo.perks.xp.10percentboost.<skillname>' multiplies incoming XP by 1.1
+ Added new experience bonus perk 'mcmmo.perks.xp.customboost.<skillname>' multiplies incoming XP by the boost amount defined in the experience config
+ Added Ender Dragon, Wither, and Witch to combat experience multipliers - they do not give XP by default
+ Added support for multiple mod config files, naming is done in the same style as repair.*.yml (blocks.*.yml, tools.*.yml, entities.*.yml, armor.*.yml)
= Fixed bug where LeafBlower permissions were ignored
= Fixed bug with toggle commands not properly displaying the success message.
= Fixed IllegalArgumentException caused by an empty Fishing treasure category

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ModManager;
import java.io.File;
import java.util.regex.Pattern;
public class ArmorConfigManager {
public ArmorConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("armor\\.(?:.+)\\.yml");
File dataFolder = new File(mcMMO.getModDirectory());
File vanilla = new File(dataFolder, "armor.default.yml");
ModManager modManager = mcMMO.getModManager();
if (!vanilla.exists()) {
plugin.saveResource(plugin.getDataFolder().getName() + File.separator + "armor.default.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
modManager.registerCustomArmor(new CustomArmorConfig(fileName));
}
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ModManager;
import java.io.File;
import java.util.regex.Pattern;
public class BlockConfigManager {
public BlockConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("blocks\\.(?:.+)\\.yml");
File dataFolder = new File(mcMMO.getModDirectory());
File vanilla = new File(dataFolder, "blocks.default.yml");
ModManager modManager = mcMMO.getModManager();
if (!vanilla.exists()) {
plugin.saveResource(plugin.getDataFolder().getName() + File.separator + "blocks.default.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
modManager.registerCustomBlocks(new CustomBlockConfig(fileName));
}
}
}

View File

@ -16,42 +16,22 @@ import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
public class CustomArmorConfig extends ConfigLoader {
private static CustomArmorConfig instance;
private boolean needsUpdate = false;
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>();
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 List<Repairable> repairables = new ArrayList<Repairable>();
public CustomArmorConfig() {
super("mods", "armor.yml");
protected CustomArmorConfig(String fileName) {
super("mods", fileName);
loadKeys();
}
public static CustomArmorConfig getInstance() {
if (instance == null) {
instance = new CustomArmorConfig();
}
return instance;
}
public List<Repairable> getLoadedRepairables() {
if (repairables == null) {
return new ArrayList<Repairable>();
}
return repairables;
}
@Override
protected void loadKeys() {
repairables = new ArrayList<Repairable>();
loadArmor("Boots", customBoots);
loadArmor("Chestplates", customChestplates);
loadArmor("Helmets", customHelmets);
@ -117,20 +97,4 @@ public class CustomArmorConfig extends ConfigLoader {
materialList.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);
}
}

View File

@ -13,40 +13,29 @@ import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlockConfig extends ConfigLoader {
private static CustomBlockConfig instance;
private boolean needsUpdate = false;
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 List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
public List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
public List<MaterialData> customMiningBlocks = 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>();
private HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
public HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
public CustomBlockConfig() {
super("mods", "blocks.yml");
protected CustomBlockConfig(String fileName) {
super("mods", fileName);
loadKeys();
}
public static CustomBlockConfig getInstance() {
if (instance == null) {
instance = new CustomBlockConfig();
}
return instance;
}
@Override
protected void loadKeys() {
loadBlocks("Excavation", customExcavationBlocks);
loadBlocks("Herbalism", customHerbalismBlocks);
loadBlocks("Mining", customMiningBlocks);
loadBlocks("Woodcutting", customWoodcuttingBlocks);
loadBlocks("Woodcutting", null);
loadBlocks("Ability_Blocks", customAbilityBlocks);
if (needsUpdate) {
@ -85,7 +74,10 @@ public class CustomBlockConfig extends ConfigLoader {
byte blockData = (blockInfo.length == 2) ? Byte.valueOf(blockInfo[1]) : 0;
MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData);
blockList.add(blockMaterialData);
if (blockList != null) {
blockList.add(blockMaterialData);
}
if (skillType.equals("Ability_Blocks")) {
continue;
@ -111,40 +103,4 @@ public class CustomBlockConfig extends ConfigLoader {
customBlockMap.put(blockMaterialData, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp));
}
}
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);
}
}

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.config.mods;
import java.util.HashMap;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.ConfigLoader;
@ -12,24 +11,14 @@ import com.gmail.nossr50.datatypes.mods.CustomEntity;
import org.apache.commons.lang.ClassUtils;
public class CustomEntityConfig extends ConfigLoader {
private static CustomEntityConfig instance;
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("mods", "entities.yml");
protected CustomEntityConfig(String fileName) {
super("mods", fileName);
loadKeys();
}
public static CustomEntityConfig getInstance() {
if (instance == null) {
instance = new CustomEntityConfig();
}
return instance;
}
@Override
protected void loadKeys() {
if (config.getConfigurationSection("Hostile") != null) {
@ -71,47 +60,4 @@ public class CustomEntityConfig extends ConfigLoader {
customEntityClassMap.put(clazz == null ? null : clazz.getName(), entity);
}
}
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);
}
}

View File

@ -18,46 +18,26 @@ import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
public class CustomToolConfig extends ConfigLoader {
private static CustomToolConfig instance;
private boolean needsUpdate = false;
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>();
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>();
public List<Repairable> repairables = new ArrayList<Repairable>();
private CustomToolConfig() {
super("mods", "tools.yml");
protected CustomToolConfig(String fileName) {
super("mods", fileName);
loadKeys();
}
public static CustomToolConfig getInstance() {
if (instance == null) {
instance = new CustomToolConfig();
}
return instance;
}
public List<Repairable> getLoadedRepairables() {
if (repairables == null) {
return new ArrayList<Repairable>();
}
return repairables;
}
@Override
protected void loadKeys() {
repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxes);
loadTool("Bows", customBows);
loadTool("Hoes", customHoes);
@ -132,36 +112,4 @@ public class CustomToolConfig extends ConfigLoader {
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);
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ModManager;
import java.io.File;
import java.util.regex.Pattern;
public class EntityConfigManager {
public EntityConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("entities\\.(?:.+)\\.yml");
File dataFolder = new File(mcMMO.getModDirectory());
File vanilla = new File(dataFolder, "entities.default.yml");
ModManager modManager = mcMMO.getModManager();
if (!vanilla.exists()) {
plugin.saveResource(plugin.getDataFolder().getName() + File.separator + "entities.default.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
modManager.registerCustomEntities(new CustomEntityConfig(fileName));
}
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ModManager;
import java.io.File;
import java.util.regex.Pattern;
public class ToolConfigManager {
public ToolConfigManager(mcMMO plugin) {
Pattern pattern = Pattern.compile("tools\\.(?:.+)\\.yml");
File dataFolder = new File(mcMMO.getModDirectory());
File vanilla = new File(dataFolder, "tools.default.yml");
ModManager modManager = mcMMO.getModManager();
if (!vanilla.exists()) {
plugin.saveResource(plugin.getDataFolder().getName() + File.separator + "tools.default.yml", false);
}
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
modManager.registerCustomTools(new CustomToolConfig(fileName));
}
}
}

View File

@ -9,11 +9,9 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
public class RepairConfigManager {
private List<Repairable> repairables;
private final List<Repairable> repairables = new ArrayList<Repairable>();
public RepairConfigManager(mcMMO plugin) {
repairables = new ArrayList<Repairable>();
Pattern pattern = Pattern.compile("repair\\.(?:.+)\\.yml");
File dataFolder = plugin.getDataFolder();
File vanilla = new File(dataFolder, "repair.vanilla.yml");
@ -34,19 +32,11 @@ public class RepairConfigManager {
}
RepairConfig rConfig = new RepairConfig(fileName);
List<Repairable> rConfigRepairables = rConfig.getLoadedRepairables();
if (rConfigRepairables != null) {
repairables.addAll(rConfigRepairables);
}
repairables.addAll(rConfig.getLoadedRepairables());
}
}
public List<Repairable> getLoadedRepairables() {
if (repairables == null) {
return new ArrayList<Repairable>();
}
return repairables;
}
}

View File

@ -47,7 +47,6 @@ import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
@ -757,7 +756,7 @@ public class McMMOPlayer {
xp = (float) (xp / skillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier());
if (Config.getInstance().getToolModsEnabled()) {
CustomTool tool = ModUtils.getToolFromItemStack(player.getItemInHand());
CustomTool tool = mcMMO.getModManager().getTool(player.getItemInHand());
if (tool != null) {
xp *= tool.getXpMultiplier();
@ -843,7 +842,7 @@ public class McMMOPlayer {
ItemStack inHand = player.getItemInHand();
if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) {
if (mcMMO.getModManager().isCustomTool(inHand) && !mcMMO.getModManager().getTool(inHand).isAbilityEnabled()) {
return;
}

View File

@ -5,6 +5,11 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.config.mods.ArmorConfigManager;
import com.gmail.nossr50.config.mods.BlockConfigManager;
import com.gmail.nossr50.config.mods.EntityConfigManager;
import com.gmail.nossr50.config.mods.ToolConfigManager;
import com.gmail.nossr50.util.ModManager;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue;
@ -14,10 +19,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomBlockConfig;
import com.gmail.nossr50.config.mods.CustomEntityConfig;
import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.config.potion.PotionConfig;
import com.gmail.nossr50.config.repair.RepairConfigManager;
import com.gmail.nossr50.config.treasure.TreasureConfig;
@ -65,6 +66,7 @@ public class mcMMO extends JavaPlugin {
/* Managers */
private static ChunkManager placeStore;
private static RepairableManager repairableManager;
private static ModManager modManager;
private static DatabaseManager databaseManager;
private static FormulaManager formulaManager;
private static HolidayManager holidayManager;
@ -131,6 +133,8 @@ public class mcMMO extends JavaPlugin {
setupFilePaths();
modManager = new ModManager();
loadConfigFiles();
if (!noErrorsInConfigFiles) {
@ -294,6 +298,10 @@ public class mcMMO extends JavaPlugin {
return databaseManager;
}
public static ModManager getModManager() {
return modManager;
}
@Deprecated
public static void setDatabaseManager(DatabaseManager databaseManager) {
mcMMO.databaseManager = databaseManager;
@ -329,13 +337,42 @@ public class mcMMO extends JavaPlugin {
if (oldFlatfilePath.exists()) {
if (!oldFlatfilePath.renameTo(new File(flatFileDirectory))) {
getLogger().warning("Failed to rename FlatFileStuff to flatfile !");
getLogger().warning("Failed to rename FlatFileStuff to flatfile!");
}
}
if (oldModPath.exists()) {
if (!oldModPath.renameTo(new File(modDirectory))) {
getLogger().warning("Failed to rename ModConfigs to mods !");
getLogger().warning("Failed to rename ModConfigs to mods!");
}
}
File oldArmorFile = new File(modDirectory + "armor.yml");
File oldBlocksFile = new File(modDirectory + "blocks.yml");
File oldEntitiesFile = new File(modDirectory + "entities.yml");
File oldToolsFile = new File(modDirectory + "tools.yml");
if (oldArmorFile.exists()) {
if (!oldArmorFile.renameTo(new File(modDirectory + "armor.default.yml"))) {
getLogger().warning("Failed to rename armor.yml to armor.default.yml!");
}
}
if (oldBlocksFile.exists()) {
if (!oldBlocksFile.renameTo(new File(modDirectory + "blocks.default.yml"))) {
getLogger().warning("Failed to rename blocks.yml to blocks.default.yml!");
}
}
if (oldEntitiesFile.exists()) {
if (!oldEntitiesFile.renameTo(new File(modDirectory + "entities.default.yml"))) {
getLogger().warning("Failed to rename entities.yml to entities.default.yml!");
}
}
if (oldToolsFile.exists()) {
if (!oldToolsFile.renameTo(new File(modDirectory + "tools.default.yml"))) {
getLogger().warning("Failed to rename tools.yml to tools.default.yml!");
}
}
}
@ -373,24 +410,24 @@ public class mcMMO extends JavaPlugin {
List<Repairable> repairables = new ArrayList<Repairable>();
if (Config.getInstance().getToolModsEnabled()) {
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
new ToolConfigManager(this);
}
if (Config.getInstance().getArmorModsEnabled()) {
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
new ArmorConfigManager(this);
}
if (Config.getInstance().getBlockModsEnabled()) {
CustomBlockConfig.getInstance();
new BlockConfigManager(this);
}
if (Config.getInstance().getEntityModsEnabled()) {
CustomEntityConfig.getInstance();
new EntityConfigManager(this);
}
// Load repair configs, make manager, and register them at this time
RepairConfigManager rManager = new RepairConfigManager(this);
repairables.addAll(rManager.getLoadedRepairables());
repairables.addAll(new RepairConfigManager(this).getLoadedRepairables());
repairables.addAll(modManager.getLoadedRepairables());
repairableManager = new SimpleRepairableManager(repairables.size());
repairableManager.registerRepairables(repairables);
}

View File

@ -3,13 +3,13 @@ package com.gmail.nossr50.skills.excavation;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.mcMMO;
import org.bukkit.block.BlockState;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.util.ModUtils;
public class Excavation {
/**
@ -52,8 +52,8 @@ public class Excavation {
protected static int getBlockXP(BlockState blockState) {
int xp = ExperienceConfig.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
if (xp == 0 && ModUtils.isCustomExcavationBlock(blockState)) {
xp = ModUtils.getCustomBlock(blockState).getXpGain();
if (xp == 0 && mcMMO.getModManager().isCustomExcavationBlock(blockState)) {
xp = mcMMO.getModManager().getBlock(blockState).getXpGain();
}
return xp;

View File

@ -32,7 +32,6 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -136,8 +135,8 @@ public class HerbalismManager extends SkillManager {
int xp;
boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
if (ModUtils.isCustomHerbalismBlock(blockState)) {
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
if (mcMMO.getModManager().isCustomHerbalismBlock(blockState)) {
CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState);
xp = customBlock.getXpGain();
if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS) && customBlock.isDoubleDropEnabled()) {

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
@ -8,7 +9,6 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
public class Mining {
@ -21,8 +21,8 @@ public class Mining {
Material blockType = blockState.getType();
int xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, blockType != Material.GLOWING_REDSTONE_ORE ? blockType : Material.REDSTONE_ORE);
if (xp == 0 && ModUtils.isCustomMiningBlock(blockState)) {
xp = ModUtils.getCustomBlock(blockState).getXpGain();
if (xp == 0 && mcMMO.getModManager().isCustomMiningBlock(blockState)) {
xp = mcMMO.getModManager().getBlock(blockState).getXpGain();
}
return xp;
@ -65,7 +65,7 @@ public class Mining {
return;
default:
if (ModUtils.isCustomMiningBlock(blockState)) {
if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack(1));
}
return;
@ -104,7 +104,7 @@ public class Mining {
return;
default:
if (ModUtils.isCustomMiningBlock(blockState)) {
if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops());
}
return;

View File

@ -23,7 +23,6 @@ import com.gmail.nossr50.skills.mining.BlastMining.Tier;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -70,7 +69,7 @@ public class MiningManager extends SkillManager {
SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage());
}
if ((ModUtils.isCustomMiningBlock(blockState) && !ModUtils.getCustomBlock(blockState).isDoubleDropEnabled()) || material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) {
if ((mcMMO.getModManager().isCustomMiningBlock(blockState) && !mcMMO.getModManager().getBlock(blockState).isDoubleDropEnabled()) || material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) {
return;
}

View File

@ -6,7 +6,6 @@ import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class SimpleRepairableManager implements RepairableManager {
private HashMap<Material, Repairable> repairables;

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.smelting;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
@ -7,7 +8,6 @@ import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.ModUtils;
public class Smelting {
// The order of the values is extremely important, a few methods depend on it to work properly
@ -50,6 +50,6 @@ public class Smelting {
MaterialData data = smelting.getData();
Material resourceType = smelting.getType();
return ModUtils.isCustomOre(data) ? ModUtils.getCustomBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE);
return mcMMO.getModManager().isCustomOre(data) ? mcMMO.getModManager().getBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE);
}
}

View File

@ -16,7 +16,6 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class Woodcutting {
@ -52,8 +51,8 @@ public final class Woodcutting {
break;
}
if (ModUtils.isCustomLogBlock(blockState)) {
return ModUtils.getCustomBlock(blockState).getXpGain();
if (mcMMO.getModManager().isCustomLog(blockState)) {
return mcMMO.getModManager().getBlock(blockState).getXpGain();
}
switch (((Tree) blockState.getData()).getSpecies()) {
@ -86,7 +85,7 @@ public final class Woodcutting {
* @param blockState Block being broken
*/
protected static void checkForDoubleDrop(BlockState blockState) {
if (ModUtils.isCustomLogBlock(blockState) && ModUtils.getCustomBlock(blockState).isDoubleDropEnabled()) {
if (mcMMO.getModManager().isCustomLog(blockState) && mcMMO.getModManager().getBlock(blockState).isDoubleDropEnabled()) {
Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops());
}
else {

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.woodcutting;
import java.util.HashSet;
import java.util.Set;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -22,7 +23,6 @@ import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -126,18 +126,18 @@ public class WoodcuttingManager extends SkillManager {
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
Misc.dropItems(blockState.getLocation(), block.getDrops());
}
else if (ModUtils.isCustomLogBlock(blockState)) {
else if (mcMMO.getModManager().isCustomLog(blockState)) {
if (canGetDoubleDrops()) {
Woodcutting.checkForDoubleDrop(blockState);
}
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState);
xp = customBlock.getXpGain();
Misc.dropItems(blockState.getLocation(), block.getDrops());
}
else if (ModUtils.isCustomLeafBlock(blockState)) {
Misc.randomDropItems(blockState.getLocation(), block.getDrops(), 10.0);
else if (mcMMO.getModManager().isCustomLeaf(blockState)) {
Misc.dropItems(blockState.getLocation(), block.getDrops());
}
else {
Tree tree = (Tree) blockState.getData();

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.util;
import java.util.HashSet;
import com.gmail.nossr50.mcMMO;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.NetherWartsState;
@ -64,7 +65,7 @@ public final class BlockUtils {
return false;
default:
return !isMcMMOAnvil(blockState) && !ModUtils.isCustomAbilityBlock(blockState);
return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
}
}
@ -135,7 +136,7 @@ public final class BlockUtils {
return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
default:
return ModUtils.isCustomHerbalismBlock(blockState);
return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
}
}
@ -157,7 +158,7 @@ public final class BlockUtils {
return true;
default:
return isOre(blockState) || ModUtils.isCustomMiningBlock(blockState);
return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
}
}
@ -181,7 +182,7 @@ public final class BlockUtils {
return true;
default:
return ModUtils.isCustomExcavationBlock(blockState);
return mcMMO.getModManager().isCustomExcavationBlock(blockState);
}
}
@ -199,7 +200,7 @@ public final class BlockUtils {
return true;
default:
return ModUtils.isCustomLogBlock(blockState);
return mcMMO.getModManager().isCustomLog(blockState);
}
}
@ -215,7 +216,7 @@ public final class BlockUtils {
return true;
default:
return ModUtils.isCustomLeafBlock(blockState);
return mcMMO.getModManager().isCustomLeaf(blockState);
}
}

View File

@ -10,9 +10,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Dye;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.locale.LocaleLoader;
@ -33,7 +30,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomBow(type));
return mcMMO.getModManager().isCustomBow(type);
}
}
@ -55,7 +52,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomSword(type));
return mcMMO.getModManager().isCustomSword(type);
}
}
@ -77,7 +74,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomHoe(type));
return mcMMO.getModManager().isCustomHoe(type);
}
}
@ -99,7 +96,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomShovel(type));
return mcMMO.getModManager().isCustomShovel(type);
}
}
@ -121,7 +118,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomAxe(type));
return mcMMO.getModManager().isCustomAxe(type);
}
}
@ -143,7 +140,7 @@ public final class ItemUtils {
return true;
default:
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomPickaxe(type));
return mcMMO.getModManager().isCustomPickaxe(type);
}
}
@ -165,7 +162,7 @@ public final class ItemUtils {
return true;
default:
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomHelmet(type);
return mcMMO.getModManager().isCustomHelmet(type);
}
}
@ -187,7 +184,7 @@ public final class ItemUtils {
return true;
default:
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomChestplate(type);
return mcMMO.getModManager().isCustomChestplate(type);
}
}
@ -209,7 +206,7 @@ public final class ItemUtils {
return true;
default:
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomLeggings(type);
return mcMMO.getModManager().isCustomLeggings(type);
}
}
@ -231,7 +228,7 @@ public final class ItemUtils {
return true;
default:
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomBoots(type);
return mcMMO.getModManager().isCustomBoots(type);
}
}

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.util;
import com.gmail.nossr50.mcMMO;
import org.bukkit.material.MaterialData;
public final class MaterialUtils {
@ -19,7 +20,7 @@ public final class MaterialUtils {
return true;
default:
return ModUtils.isCustomOre(data);
return mcMMO.getModManager().isCustomOre(data);
}
}
}

View File

@ -167,7 +167,7 @@ public final class MobHealthbarUtils {
return true;
default:
return ModUtils.isCustomBossEntity(livingEntity);
return false;
}
}
}

View File

@ -0,0 +1,283 @@
package com.gmail.nossr50.util;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomBlockConfig;
import com.gmail.nossr50.config.mods.CustomEntityConfig;
import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.mods.CustomEntity;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ModManager {
private List<Repairable> repairables = new ArrayList<Repairable>();
// Armor Mods
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>();
// Block Mods
private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customMiningBlocks = 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>();
private HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
// Entity Mods
private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
// Tool Mods
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>();
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
public void registerCustomArmor(CustomArmorConfig config) {
customBoots.addAll(config.customBoots);
customChestplates.addAll(config.customChestplates);
customHelmets.addAll(config.customHelmets);
customLeggings.addAll(config.customLeggings);
repairables.addAll(config.repairables);
}
public void registerCustomBlocks(CustomBlockConfig config) {
customExcavationBlocks.addAll(config.customExcavationBlocks);
customHerbalismBlocks.addAll(config.customHerbalismBlocks);
customMiningBlocks.addAll(config.customMiningBlocks);
customOres.addAll(config.customOres);
customLogs.addAll(config.customLogs);
customLeaves.addAll(config.customLeaves);
customAbilityBlocks.addAll(config.customAbilityBlocks);
customBlockMap.putAll(config.customBlockMap);
}
public void registerCustomEntities(CustomEntityConfig config) {
customEntityClassMap.putAll(config.customEntityClassMap);
customEntityTypeMap.putAll(config.customEntityTypeMap);
}
public void registerCustomTools(CustomToolConfig config) {
customAxes.addAll(config.customAxes);
customBows.addAll(config.customBows);
customHoes.addAll(config.customHoes);
customPickaxes.addAll(config.customPickaxes);
customShovels.addAll(config.customShovels);
customSwords.addAll(config.customSwords);
customToolMap.putAll(config.customToolMap);
repairables.addAll(config.repairables);
}
public boolean isCustomBoots(Material material) {
return Config.getInstance().getArmorModsEnabled() && customBoots.contains(material);
}
public boolean isCustomChestplate(Material material) {
return Config.getInstance().getArmorModsEnabled() && customChestplates.contains(material);
}
public boolean isCustomHelmet(Material material) {
return Config.getInstance().getArmorModsEnabled() && customHelmets.contains(material);
}
public boolean isCustomLeggings(Material material) {
return Config.getInstance().getArmorModsEnabled() && customLeggings.contains(material);
}
public boolean isCustomAxe(Material material) {
return Config.getInstance().getToolModsEnabled() && customAxes.contains(material);
}
public boolean isCustomBow(Material material) {
return Config.getInstance().getToolModsEnabled() && customBows.contains(material);
}
public boolean isCustomHoe(Material material) {
return Config.getInstance().getToolModsEnabled() && customHoes.contains(material);
}
public boolean isCustomPickaxe(Material material) {
return Config.getInstance().getToolModsEnabled() && customPickaxes.contains(material);
}
public boolean isCustomShovel(Material material) {
return Config.getInstance().getToolModsEnabled() && customShovels.contains(material);
}
public boolean isCustomSword(Material material) {
return Config.getInstance().getToolModsEnabled() && customSwords.contains(material);
}
public boolean isCustomOre(MaterialData data) {
return Config.getInstance().getBlockModsEnabled() && customOres.contains(data);
}
public boolean isCustomLog(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customLogs.contains(state.getData());
}
public boolean isCustomLeaf(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getData());
}
public boolean isCustomAbilityBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customAbilityBlocks.contains(state.getData());
}
public boolean isCustomExcavationBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customExcavationBlocks.contains(state.getData());
}
public boolean isCustomHerbalismBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customHerbalismBlocks.contains(state.getData());
}
public boolean isCustomMiningBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customMiningBlocks.contains(state.getData());
}
public CustomBlock getBlock(BlockState state) {
return customBlockMap.get(state.getData());
}
public CustomBlock getBlock(MaterialData data) {
return customBlockMap.get(data);
}
/**
* Checks to see if an item is a custom tool.
*
* @param item Item to check
* @return true if the item is a custom tool, false otherwise
*/
public boolean isCustomTool(ItemStack item) {
return Config.getInstance().getToolModsEnabled() && item != null && customToolMap.containsKey(item.getType());
}
/**
* Get the custom tool associated with an item.
*
* @param item The item to check
* @return the tool if it exists, null otherwise
*/
public CustomTool getTool(ItemStack item) {
return item == null ? null : customToolMap.get(item.getType());
}
public List<Repairable> getLoadedRepairables() {
return repairables;
}
public boolean isCustomEntity(Entity entity) {
if (!Config.getInstance().getEntityModsEnabled()) {
return false;
}
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 getEntity(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 addCustomEntity(Entity entity) {
if (!Config.getInstance().getEntityModsEnabled()) {
return;
}
File entityFile = new File(mcMMO.p.getDataFolder(), "mods" + File.separator + "entities.default.yml");
YamlConfiguration entitiesFile = YamlConfiguration.loadConfiguration(entityFile);
String entityName = entity.getType().toString();
String sanitizedEntityName = entityName.replace(".", "_");
if (entitiesFile.getKeys(false).contains(sanitizedEntityName)) {
return;
}
entitiesFile.set(sanitizedEntityName + ".XP_Multiplier", 1.0D);
entitiesFile.set(sanitizedEntityName + ".Tameable", false);
entitiesFile.set(sanitizedEntityName + ".Taming_XP", 0);
entitiesFile.set(sanitizedEntityName + ".CanBeSummoned", false);
entitiesFile.set(sanitizedEntityName + ".COTW_Material", "");
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Data", 0);
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Amount", 0);
String className = "";
try {
className = ((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName();
}
catch (Exception e) {
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
className = entity.getClass().getName();
}
else {
e.printStackTrace();
}
}
CustomEntity customEntity = new CustomEntity(1.0D, false, 0, false, null, 0);
customEntityTypeMap.put(entityName, customEntity);
customEntityClassMap.put(className, customEntity);
try {
entitiesFile.save(entityFile);
mcMMO.p.debug(entity.getType().toString() + " was added to the custom entities file!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,213 +0,0 @@
package com.gmail.nossr50.util;
import java.io.File;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomBlockConfig;
import com.gmail.nossr50.config.mods.CustomEntityConfig;
import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.mods.CustomEntity;
import com.gmail.nossr50.datatypes.mods.CustomTool;
public final class ModUtils {
private static boolean customToolsEnabled = Config.getInstance().getToolModsEnabled();
private static boolean customBlocksEnabled = Config.getInstance().getBlockModsEnabled();
private static boolean customEntitiesEnabled = Config.getInstance().getEntityModsEnabled();
private ModUtils() {}
/**
* Get the custom tool associated with an item.
*
* @param item The item to check
* @return the tool if it exists, null otherwise
*/
public static CustomTool getToolFromItemStack(ItemStack item) {
return CustomToolConfig.getInstance().getCustomTool(item.getType());
}
/**
* Get the custom entity associated with an entity.
*
* @param entity The entity to check
* @return the entity is if exists, null otherwise
*/
public static CustomEntity getCustomEntity(Entity entity) {
return CustomEntityConfig.getInstance().getCustomEntity(entity);
}
/**
* Get the custom block associated with an block.
*
* @param blockState The BlockState of the bloc to check
* @return the block if it exists, null otherwise
*/
public static CustomBlock getCustomBlock(BlockState blockState) {
return CustomBlockConfig.getInstance().getCustomBlock(blockState.getData());
}
public static CustomBlock getCustomBlock(MaterialData data) {
return CustomBlockConfig.getInstance().getCustomBlock(data);
}
/**
* Check if a custom block is a woodcutting block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents a custom woodcutting block, false otherwise
*/
public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomWoodcuttingBlock(blockState.getData());
}
/**
* Check if a custom block should not activate abilites.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents an ability block, false otherwise
*/
public static boolean isCustomAbilityBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomAbilityBlock(blockState.getData());
}
/**
* Check if a custom block is a mining block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents a custom mining block, false otherwise
*/
public static boolean isCustomMiningBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomMiningBlock(blockState.getData());
}
/**
* Check if a custom block is an excavation block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents a custom excavation block, false otherwise
*/
public static boolean isCustomExcavationBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomExcavationBlock(blockState.getData());
}
/**
* Check if a custom block is an herbalism block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents a custom herbalism block, false otherwise
*/
public static boolean isCustomHerbalismBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomHerbalismBlock(blockState.getData());
}
/**
* Check if a custom block is a leaf block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents leaves, false otherwise
*/
public static boolean isCustomLeafBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLeaf(blockState.getData());
}
/**
* Check if a custom block is a log block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents a log, false otherwise
*/
public static boolean isCustomLogBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLog(blockState.getData());
}
public static boolean isCustomOre(MaterialData data) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(data);
}
/**
* Checks to see if an item is a custom tool.
*
* @param item Item to check
* @return true if the item is a custom tool, false otherwise
*/
public static boolean isCustomTool(ItemStack item) {
return customToolsEnabled && CustomToolConfig.getInstance().isCustomTool(item.getType());
}
/**
* Checks to see if an entity is a custom entity.
*
* @param entity Entity to check
* @return true if the entity is a custom entity, false otherwise
*/
public static boolean isCustomEntity(Entity entity) {
return customEntitiesEnabled && CustomEntityConfig.getInstance().isCustomEntity(entity);
}
/**
* Check if a custom entity is a boss.
*
* @param entity The entity to check
* @return true if the entity represents a boss, false otherwise
*/
public static boolean isCustomBossEntity(Entity entity) {
//TODO: Finish this method
return false;
}
public static void addCustomEntity(Entity entity) {
if (!customEntitiesEnabled) {
return;
}
File entityFile = CustomEntityConfig.getInstance().getFile();
YamlConfiguration entitiesFile = YamlConfiguration.loadConfiguration(entityFile);
String entityName = entity.getType().toString();
String sanitizedEntityName = entityName.replace(".", "_");
if (entitiesFile.getKeys(false).contains(sanitizedEntityName)) {
return;
}
entitiesFile.set(sanitizedEntityName + ".XP_Multiplier", 1.0D);
entitiesFile.set(sanitizedEntityName + ".Tameable", false);
entitiesFile.set(sanitizedEntityName + ".Taming_XP", 0);
entitiesFile.set(sanitizedEntityName + ".CanBeSummoned", false);
entitiesFile.set(sanitizedEntityName + ".COTW_Material", "");
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Data", 0);
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Amount", 0);
String className = "";
try {
className = ((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName();
}
catch (Exception e) {
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
className = entity.getClass().getName();
}
else {
e.printStackTrace();
}
}
CustomEntityConfig.getInstance().addEntity(new CustomEntity(1.0D, false, 0, false, null, 0), className, entityName);
try {
entitiesFile.save(entityFile);
mcMMO.p.debug(entity.getType().toString() + " was added to the custom entities file!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -39,7 +39,6 @@ import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.MobHealthbarUtils;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -421,8 +420,8 @@ public final class CombatUtils {
}
}
else {
if (ModUtils.isCustomEntity(target)) {
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
if (mcMMO.getModManager().isCustomEntity(target)) {
baseXP = mcMMO.getModManager().getEntity(target).getXpMultiplier();
}
else if (target instanceof Animals) {
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
@ -473,7 +472,7 @@ public final class CombatUtils {
default:
baseXP = 1.0;
ModUtils.addCustomEntity(target);
mcMMO.getModManager().addCustomEntity(target);
break;
}
}
@ -609,8 +608,8 @@ public final class CombatUtils {
else if (ItemUtils.isDiamondTool(inHand)) {
tier = 4;
}
else if (ModUtils.isCustomTool(inHand)) {
tier = ModUtils.getToolFromItemStack(inHand).getTier();
else if (mcMMO.getModManager().isCustomTool(inHand)) {
tier = mcMMO.getModManager().getTool(inHand).getTier();
}
return tier;