mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Made mod config files modular. Addresses #1802
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user