diff --git a/core/src/main/java/com/gmail/nossr50/core/config/AdvancedConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/AdvancedConfig.java index c6cc31424..181f8ae74 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/AdvancedConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/AdvancedConfig.java @@ -126,7 +126,7 @@ public class AdvancedConfig extends ConfigValidated { private static AdvancedConfig instance; private AdvancedConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); } public static AdvancedConfig getInstance() { diff --git a/core/src/main/java/com/gmail/nossr50/core/config/Config.java b/core/src/main/java/com/gmail/nossr50/core/config/Config.java index d7e1f3ec3..d66a36e61 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/Config.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/Config.java @@ -18,6 +18,9 @@ import java.io.InputStream; //@ConfigSerializable public abstract class Config implements VersionedConfig, Unload { + /* SETTINGS */ + private boolean mergeNewKeys; + /* PATH VARS */ public final File DIRECTORY_DATA_FOLDER; //Directory that the file is in @@ -42,16 +45,17 @@ public abstract class Config implements VersionedConfig, Unload { /* CONFIG MANAGER */ private ConfigurationLoader configManager; - public Config(String pathToParentFolder, String relativePath) { + public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys) { //TODO: Check if this works... - this(new File(pathToParentFolder), relativePath); + this(new File(pathToParentFolder), relativePath, mergeNewKeys); System.out.println("mcMMO Debug: Don't forget to check if loading config file by string instead of File works..."); } - public Config(File pathToParentFolder, String relativePath) { + public Config(File pathToParentFolder, String relativePath, boolean mergeNewKeys) { /* * These must be at the top */ + this.mergeNewKeys = mergeNewKeys; //Whether or not we add new keys when they are found mkdirDefaults(); // Make our default config dir DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder @@ -240,7 +244,8 @@ public abstract class Config implements VersionedConfig, Unload { McmmoCore.getLogger().info(userRootNode.getChildrenMap().size() +" items in default root map"); // Merge Values from default - userRootNode = userRootNode.mergeValuesFrom(defaultRootNode); + if(mergeNewKeys) + userRootNode = userRootNode.mergeValuesFrom(defaultRootNode); // Update config version updateConfigVersion(); @@ -280,21 +285,41 @@ public abstract class Config implements VersionedConfig, Unload { return userRootNode; } + /** + * Grabs an int from the specified node + * @param path + * @return the int from the node, null references will zero initialize + */ public int getIntValue(String... path) { return userRootNode.getNode(path).getInt(); } + /** + * Grabs a double from the specified node + * @param path + * @return the double from the node, null references will zero initialize + */ public double getDoubleValue(String... path) { return userRootNode.getNode(path).getDouble(); } + /** + * Grabs a boolean from the specified node + * @param path + * @return the boolean from the node, null references will zero initialize + */ public boolean getBooleanValue(String... path) { return userRootNode.getNode(path).getBoolean(); } + /** + * Grabs a string from the specified node + * @param path + * @return the string from the node, null references will zero initialize + */ public String getStringValue(String... path) { return userRootNode.getNode(path).getString(); diff --git a/core/src/main/java/com/gmail/nossr50/core/config/ConfigKeyRegister.java b/core/src/main/java/com/gmail/nossr50/core/config/ConfigKeyRegister.java index 666dcc5cd..3c91e53ed 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/ConfigKeyRegister.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/ConfigKeyRegister.java @@ -7,13 +7,13 @@ import java.io.File; */ public abstract class ConfigKeyRegister extends Config implements RegistersKeys { - public ConfigKeyRegister(String pathToParentFolder, String relativePath) { - super(pathToParentFolder, relativePath); + public ConfigKeyRegister(String pathToParentFolder, String relativePath, boolean mergeNewKeys) { + super(pathToParentFolder, relativePath, mergeNewKeys); loadKeys(); } - public ConfigKeyRegister(File pathToParentFolder, String relativePath) { - super(pathToParentFolder, relativePath); + public ConfigKeyRegister(File pathToParentFolder, String relativePath, boolean mergeNewKeys) { + super(pathToParentFolder, relativePath, mergeNewKeys); loadKeys(); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/config/ConfigValidated.java b/core/src/main/java/com/gmail/nossr50/core/config/ConfigValidated.java index 0e0d1e979..da2999b20 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/ConfigValidated.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/ConfigValidated.java @@ -9,15 +9,15 @@ import java.util.List; * This class is used for config files that validate their entries */ public abstract class ConfigValidated extends Config implements DefaultKeys { - public ConfigValidated(String parentFolderPath, String relativePath) + public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys) { - super(parentFolderPath, relativePath); + super(parentFolderPath, relativePath, mergeNewKeys); validateEntries(); } - public ConfigValidated(File parentFolderFile, String relativePath) + public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys) { - super(parentFolderFile, relativePath); + super(parentFolderFile, relativePath, mergeNewKeys); validateEntries(); } diff --git a/core/src/main/java/com/gmail/nossr50/core/config/CoreSkillsConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/CoreSkillsConfig.java index 17a8b2baa..cdd72237d 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/CoreSkillsConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/CoreSkillsConfig.java @@ -9,7 +9,7 @@ public class CoreSkillsConfig extends Config { private static CoreSkillsConfig instance; public CoreSkillsConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); } public static CoreSkillsConfig getInstance() { diff --git a/core/src/main/java/com/gmail/nossr50/core/config/MainConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/MainConfig.java index a399a3347..95cdcae25 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/MainConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/MainConfig.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.core.config; import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.data.database.SQLDatabaseManager; import com.gmail.nossr50.core.datatypes.party.PartyFeature; +import com.gmail.nossr50.core.mcmmo.entity.EntityType; import com.gmail.nossr50.core.skills.MobHealthbarType; import com.gmail.nossr50.core.skills.PrimarySkillType; import com.gmail.nossr50.core.skills.SuperAbilityType; @@ -16,7 +17,7 @@ public class MainConfig extends ConfigValidated { private static MainConfig instance; private MainConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true); } public static MainConfig getInstance() { diff --git a/core/src/main/java/com/gmail/nossr50/core/config/RankConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/RankConfig.java index fe584a4e4..c3cc63549 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/RankConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/RankConfig.java @@ -11,7 +11,7 @@ public class RankConfig extends ConfigValidated { private static RankConfig instance; public RankConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); this.instance = this; } diff --git a/core/src/main/java/com/gmail/nossr50/core/config/SoundConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/SoundConfig.java index 05abe9987..12f7fa2eb 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/SoundConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/SoundConfig.java @@ -10,7 +10,7 @@ public class SoundConfig extends ConfigValidated { private static SoundConfig instance; public SoundConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); this.instance = this; } diff --git a/core/src/main/java/com/gmail/nossr50/core/config/experience/ExperienceConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/experience/ExperienceConfig.java index f2ff721f3..e1c233ac2 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/experience/ExperienceConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/experience/ExperienceConfig.java @@ -76,8 +76,9 @@ public class ExperienceConfig extends ConfigValidated { public static final String FEATHER_FALL_MULTIPLIER = "FeatherFall_Multiplier"; private static ExperienceConfig instance; + //TODO: Should merge be false? Seems okay to leave it as true.. private ExperienceConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml"); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); } public static ExperienceConfig getInstance() { diff --git a/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomArmorConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomArmorConfig.java index b916451b2..ae7fc4136 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomArmorConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomArmorConfig.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.core.config.mods; import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.config.ConfigKeyRegister; import com.gmail.nossr50.core.mcmmo.item.ItemStack; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import com.gmail.nossr50.core.skills.primary.repair.repairables.Repairable; import com.gmail.nossr50.core.skills.primary.repair.repairables.RepairableFactory; @@ -22,7 +22,7 @@ public class CustomArmorConfig extends ConfigKeyRegister { private boolean needsUpdate = false; protected CustomArmorConfig(String fileName) { - super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName); + super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false); loadKeys(); } @@ -101,7 +101,7 @@ public class CustomArmorConfig extends ConfigKeyRegister { durability = (short) getIntValue(armorType + "." + armorName + ".Durability", 70); } - repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ItemType.ARMOR, MaterialType.OTHER, repairXpMultiplier)); + repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ConfigItemCategory.ARMOR, MaterialType.OTHER, repairXpMultiplier)); } materialList.add(armorMaterial); diff --git a/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomBlockConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomBlockConfig.java index 20a9b429b..4b983ec9d 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomBlockConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/mods/CustomBlockConfig.java @@ -24,7 +24,7 @@ public class CustomBlockConfig extends ConfigKeyRegister { private boolean needsUpdate = false; protected CustomBlockConfig(String fileName) { - super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName); + super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false); loadKeys(); } diff --git a/core/src/main/java/com/gmail/nossr50/core/config/skills/repair/RepairConfig.java b/core/src/main/java/com/gmail/nossr50/core/config/skills/repair/RepairConfig.java index 0c2530907..f5d50ce5a 100644 --- a/core/src/main/java/com/gmail/nossr50/core/config/skills/repair/RepairConfig.java +++ b/core/src/main/java/com/gmail/nossr50/core/config/skills/repair/RepairConfig.java @@ -1,46 +1,74 @@ package com.gmail.nossr50.core.config.skills.repair; -import com.gmail.nossr50.core.config.Config; +import com.gmail.nossr50.core.McmmoCore; +import com.gmail.nossr50.core.config.ConfigKeyRegister; import com.gmail.nossr50.core.mcmmo.item.ItemStack; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import com.gmail.nossr50.core.skills.primary.repair.repairables.Repairable; import com.gmail.nossr50.core.skills.primary.repair.repairables.RepairableFactory; +import com.gmail.nossr50.core.util.InvalidItemException; import com.gmail.nossr50.core.util.ItemUtils; import com.gmail.nossr50.core.util.skills.SkillUtils; +import ninja.leaping.configurate.ConfigurationNode; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import java.util.Set; -public class RepairConfig extends Config { +/** + * This config + */ +public class RepairConfig extends ConfigKeyRegister { private List repairables; public RepairConfig(String fileName) { - super(fileName); + super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); loadKeys(); } @Override - protected void loadKeys() { + public void unload() { + + } + + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; + } + + @Override + public void loadKeys() { repairables = new ArrayList(); - ConfigurationSection section = config.getConfigurationSection("Repairables"); - Set keys = section.getKeys(false); + ConfigurationNode repairablesNode = getUserRootNode().getNode("Repairables"); + List repairablesNodeChildrenList = repairablesNode.getChildrenList(); + Iterator configIter = repairablesNodeChildrenList.iterator(); - for (String key : keys) { - if (config.contains("Repairables." + key + ".ItemId")) { - backup(); - return; - } + for(Iterator i = repairablesNodeChildrenList.iterator(); i.hasNext();) + { + ConfigurationNode iterNode = i.next(); + //TODO: Verify that this is getting the key + String key = iterNode.getKey().toString(); //Get the String of the node // Validate all the things! List reason = new ArrayList(); - // ItemStack Material - Material itemMaterial = Material.matchMaterial(key); - if (itemMaterial == null) { + + try { + // ItemStack Material + ConfigItemCategory configItemCategory = ItemUtils.matchItemType(key); + } catch (InvalidItemException e) { + e.printStackTrace(); + } + + if (itemType == null) { reason.add("Invalid material: " + key); } @@ -48,8 +76,8 @@ public class RepairConfig extends Config { MaterialType repairMaterialType = MaterialType.OTHER; String repairMaterialTypeString = getStringValue("Repairables." + key + ".MaterialType", "OTHER"); - if (!config.contains("Repairables." + key + ".MaterialType") && itemMaterial != null) { - ItemStack repairItem = new ItemStack(itemMaterial); + if (!config.contains("Repairables." + key + ".MaterialType") && itemType != null) { + ItemStack repairItem = ItemStack.makeNew(itemType); if (ItemUtils.isWoodTool(repairItem)) { repairMaterialType = MaterialType.WOOD; @@ -83,7 +111,7 @@ public class RepairConfig extends Config { } // Maximum Durability - short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : (short) getIntValue("Repairables." + key + ".MaximumDurability")); + short maximumDurability = (itemType != null ? itemType.getMaxDurability() : (short) getIntValue("Repairables." + key + ".MaximumDurability")); if (maximumDurability <= 0) { maximumDurability = (short) getIntValue("Repairables." + key + ".MaximumDurability"); @@ -94,20 +122,20 @@ public class RepairConfig extends Config { } // ItemStack Type - ItemType repairItemType = ItemType.OTHER; + ConfigItemCategory repairConfigItemCategory = ConfigItemCategory.OTHER; String repairItemTypeString = getStringValue("Repairables." + key + ".ItemType", "OTHER"); - if (!config.contains("Repairables." + key + ".ItemType") && itemMaterial != null) { - ItemStack repairItem = new ItemStack(itemMaterial); + if (!config.contains("Repairables." + key + ".ItemType") && itemType != null) { + ItemStack repairItem = new ItemStack(itemType); if (ItemUtils.isMinecraftTool(repairItem)) { - repairItemType = ItemType.TOOL; + repairConfigItemCategory = ConfigItemCategory.TOOL; } else if (ItemUtils.isArmor(repairItem)) { - repairItemType = ItemType.ARMOR; + repairConfigItemCategory = ConfigItemCategory.ARMOR; } } else { try { - repairItemType = ItemType.valueOf(repairItemTypeString); + repairConfigItemCategory = ConfigItemCategory.valueOf(repairItemTypeString); } catch (IllegalArgumentException ex) { reason.add(key + " has an invalid ItemType of " + repairItemTypeString); } @@ -122,9 +150,9 @@ public class RepairConfig extends Config { } // Minimum Quantity - int minimumQuantity = (itemMaterial != null ? SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata) : getIntValue("Repairables." + key + ".MinimumQuantity", 2)); + int minimumQuantity = (itemType != null ? SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemType), repairMaterial, repairMetadata) : getIntValue("Repairables." + key + ".MinimumQuantity", 2)); - if (minimumQuantity <= 0 && itemMaterial != null) { + if (minimumQuantity <= 0 && itemType != null) { minimumQuantity = getIntValue("Repairables." + key + ".MinimumQuantity", 2); } @@ -133,7 +161,7 @@ public class RepairConfig extends Config { } if (noErrorsInRepairable(reason)) { - Repairable repairable = RepairableFactory.getRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier); + Repairable repairable = RepairableFactory.getRepairable(itemType, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairConfigItemCategory, repairMaterialType, xpMultiplier); repairables.add(repairable); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemStack.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemStack.java index 4a7ee3c38..f932f3542 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemStack.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemStack.java @@ -9,6 +9,13 @@ import java.util.ArrayList; */ public interface ItemStack { + /** + * Makes a new ItemStack for a given itemType with a size of 1 and default properties + * @param itemType the item type for the item stack + * @return a new item stack of size 1 with default properties + */ + ItemStack makeNew(ItemType itemType); + /** * The maximum amount of this item allowed in a stack * @return the maximum stack size of the item diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemType.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemType.java new file mode 100644 index 000000000..d02f66116 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/item/ItemType.java @@ -0,0 +1,12 @@ +package com.gmail.nossr50.core.mcmmo.item; + +/** + * Items are things that the player can pick up and hold in his hand + * Which includes item versions of blocks + */ +public enum ItemType { + //TODO: Fill this in + + COOKED_BEEF, + CAKE; +} diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/ItemType.java b/core/src/main/java/com/gmail/nossr50/core/skills/ConfigItemCategory.java similarity index 69% rename from core/src/main/java/com/gmail/nossr50/core/skills/ItemType.java rename to core/src/main/java/com/gmail/nossr50/core/skills/ConfigItemCategory.java index 2035e841c..86d4a5c13 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/ItemType.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/ConfigItemCategory.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.skills; -public enum ItemType { +public enum ConfigItemCategory { ARMOR, TOOL, OTHER; diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/SalvageManager.java b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/SalvageManager.java index 59d993adc..9e27e5be2 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/SalvageManager.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/SalvageManager.java @@ -71,7 +71,7 @@ public class SalvageManager extends SkillManager { } // Permissions checks on material and item types - if (!Permissions.salvageItemType(player, salvageable.getSalvageItemType())) { + if (!Permissions.salvageItemType(player, salvageable.getSalvageConfigItemCategory())) { NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission"); return; } diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/Salvageable.java b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/Salvageable.java index d15e4be72..ea75c98c4 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/Salvageable.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/Salvageable.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.skills.child.salvage.salvageables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; @@ -31,7 +31,7 @@ public interface Salvageable { * * @return the ItemType for this salvageable */ - public ItemType getSalvageItemType(); + public ConfigItemCategory getSalvageConfigItemCategory(); /** * Gets the MaterialType value for this salvageable item diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SalvageableFactory.java b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SalvageableFactory.java index 155ca567f..c894386d2 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SalvageableFactory.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SalvageableFactory.java @@ -1,16 +1,16 @@ package com.gmail.nossr50.core.skills.child.salvage.salvageables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; public class SalvageableFactory { public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int maximumQuantity, short maximumDurability) { - return getSalvageable(itemMaterial, repairMaterial, repairMetadata, 0, maximumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1); + return getSalvageable(itemMaterial, repairMaterial, repairMetadata, 0, maximumQuantity, maximumDurability, ConfigItemCategory.OTHER, MaterialType.OTHER, 1); } - public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) { + public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ConfigItemCategory repairConfigItemCategory, MaterialType repairMaterialType, double xpMultiplier) { // TODO: Add in loading from config what type of repairable we want. - return new SimpleSalvageable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, maximumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier); + return new SimpleSalvageable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, maximumQuantity, maximumDurability, repairConfigItemCategory, repairMaterialType, xpMultiplier); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SimpleSalvageable.java b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SimpleSalvageable.java index b2c4c0ac9..99ba64274 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SimpleSalvageable.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/child/salvage/salvageables/SimpleSalvageable.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.skills.child.salvage.salvageables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; @@ -10,15 +10,15 @@ public class SimpleSalvageable implements Salvageable { private final int maximumQuantity, minimumLevel; private final short maximumDurability, baseSalvageDurability; private final byte salvageMetadata; - private final ItemType salvageItemType; + private final ConfigItemCategory salvageConfigItemCategory; private final MaterialType salvageMaterialType; private final double xpMultiplier; - protected SimpleSalvageable(Material type, Material salvageMaterial, byte salvageMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ItemType salvageItemType, MaterialType salvageMaterialType, double xpMultiplier) { + protected SimpleSalvageable(Material type, Material salvageMaterial, byte salvageMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ConfigItemCategory salvageConfigItemCategory, MaterialType salvageMaterialType, double xpMultiplier) { this.itemMaterial = type; this.salvageMaterial = salvageMaterial; this.salvageMetadata = salvageMetadata; - this.salvageItemType = salvageItemType; + this.salvageConfigItemCategory = salvageConfigItemCategory; this.salvageMaterialType = salvageMaterialType; this.minimumLevel = minimumLevel; this.maximumQuantity = maximumQuantity; @@ -43,8 +43,8 @@ public class SimpleSalvageable implements Salvageable { } @Override - public ItemType getSalvageItemType() { - return salvageItemType; + public ConfigItemCategory getSalvageConfigItemCategory() { + return salvageConfigItemCategory; } @Override diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/RepairManager.java b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/RepairManager.java index 979d77c54..32250d8bd 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/RepairManager.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/RepairManager.java @@ -77,7 +77,7 @@ public class RepairManager extends SkillManager { return; } - if (!Permissions.repairItemType(player, repairable.getRepairItemType())) { + if (!Permissions.repairItemType(player, repairable.getRepairConfigItemCategory())) { NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission"); return; } diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/Repairable.java b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/Repairable.java index ca51d18b8..6131d282f 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/Repairable.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/Repairable.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.skills.primary.repair.repairables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; @@ -39,7 +39,7 @@ public interface Repairable { * * @return the RepairItemType for this repairable */ - public ItemType getRepairItemType(); + public ConfigItemCategory getRepairConfigItemCategory(); /** * Gets the RepairMaterialType value for this repairable item diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/RepairableFactory.java b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/RepairableFactory.java index 4f50e2153..bfb5c13f1 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/RepairableFactory.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/RepairableFactory.java @@ -1,21 +1,21 @@ package com.gmail.nossr50.core.skills.primary.repair.repairables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; public class RepairableFactory { public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumQuantity, short maximumDurability) { - return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, 0, minimumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1); + return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, 0, minimumQuantity, maximumDurability, ConfigItemCategory.OTHER, MaterialType.OTHER, 1); } - public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) { - return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier); + public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ConfigItemCategory repairConfigItemCategory, MaterialType repairMaterialType, double xpMultiplier) { + return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, minimumLevel, minimumQuantity, maximumDurability, repairConfigItemCategory, repairMaterialType, xpMultiplier); } - public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) { + public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ConfigItemCategory repairConfigItemCategory, MaterialType repairMaterialType, double xpMultiplier) { // TODO: Add in loading from config what type of repairable we want. - return new SimpleRepairable(itemMaterial, repairMaterial, repairMetadata, repairMaterialPrettyName, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier); + return new SimpleRepairable(itemMaterial, repairMaterial, repairMetadata, repairMaterialPrettyName, minimumLevel, minimumQuantity, maximumDurability, repairConfigItemCategory, repairMaterialType, xpMultiplier); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/SimpleRepairable.java b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/SimpleRepairable.java index bfe9efeac..1f37848c7 100644 --- a/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/SimpleRepairable.java +++ b/core/src/main/java/com/gmail/nossr50/core/skills/primary/repair/repairables/SimpleRepairable.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.skills.primary.repair.repairables; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import org.bukkit.Material; @@ -10,17 +10,17 @@ public class SimpleRepairable implements Repairable { private final int minimumQuantity, minimumLevel; private final short maximumDurability, baseRepairDurability; private final byte repairMetadata; - private final ItemType repairItemType; + private final ConfigItemCategory repairConfigItemCategory; private final MaterialType repairMaterialType; private final double xpMultiplier; private String repairMaterialPrettyName; - protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) { + protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ConfigItemCategory repairConfigItemCategory, MaterialType repairMaterialType, double xpMultiplier) { this.itemMaterial = type; this.repairMaterial = repairMaterial; this.repairMetadata = repairMetadata; this.repairMaterialPrettyName = repairMaterialPrettyName; - this.repairItemType = repairItemType; + this.repairConfigItemCategory = repairConfigItemCategory; this.repairMaterialType = repairMaterialType; this.minimumLevel = minimumLevel; this.minimumQuantity = minimumQuantity; @@ -50,8 +50,8 @@ public class SimpleRepairable implements Repairable { } @Override - public ItemType getRepairItemType() { - return repairItemType; + public ConfigItemCategory getRepairConfigItemCategory() { + return repairConfigItemCategory; } @Override diff --git a/core/src/main/java/com/gmail/nossr50/core/util/InvalidItemException.java b/core/src/main/java/com/gmail/nossr50/core/util/InvalidItemException.java new file mode 100644 index 000000000..297322d2c --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/util/InvalidItemException.java @@ -0,0 +1,7 @@ +package com.gmail.nossr50.core.util; + +public class InvalidItemException extends RuntimeException { + public InvalidItemException(String message) { + super(message); + } +} diff --git a/core/src/main/java/com/gmail/nossr50/core/util/ItemUtils.java b/core/src/main/java/com/gmail/nossr50/core/util/ItemUtils.java index af074fc8f..b84afc675 100644 --- a/core/src/main/java/com/gmail/nossr50/core/util/ItemUtils.java +++ b/core/src/main/java/com/gmail/nossr50/core/util/ItemUtils.java @@ -1,18 +1,32 @@ package com.gmail.nossr50.core.util; -import com.gmail.nossr50.config.party.ItemWeightConfig; import com.gmail.nossr50.core.config.MainConfig; +import com.gmail.nossr50.core.config.party.ItemWeightConfig; import com.gmail.nossr50.core.locale.LocaleLoader; -import com.gmail.nossr50.mcMMO; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.inventory.FurnaceRecipe; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.inventory.meta.ItemMeta; +import com.gmail.nossr50.core.mcmmo.colors.ChatColor; +import com.gmail.nossr50.core.mcmmo.item.ItemStack; +import com.gmail.nossr50.core.mcmmo.item.ItemType; public final class ItemUtils { private ItemUtils() { + + } + + /** + * Get an ItemType matching a string + * @param itemTypeString the string to match + * @return the matching ItemType for this string + */ + public static ItemType matchItemType(String itemTypeString) + { + for(ItemType itemType : ItemType.values()) + { + if(itemType.toString().equalsIgnoreCase(itemTypeString)) + return itemType; + } + + //TODO: Add custom exception + throw new InvalidItemException("[mcMMO] ItemType of name "+itemTypeString+" is invalid!"); } /** diff --git a/core/src/main/java/com/gmail/nossr50/core/util/Permissions.java b/core/src/main/java/com/gmail/nossr50/core/util/Permissions.java index 0055051bb..16270091d 100644 --- a/core/src/main/java/com/gmail/nossr50/core/util/Permissions.java +++ b/core/src/main/java/com/gmail/nossr50/core/util/Permissions.java @@ -1,8 +1,11 @@ package com.gmail.nossr50.core.util; +import com.gmail.nossr50.core.McmmoCore; +import com.gmail.nossr50.core.mcmmo.BlockType; +import com.gmail.nossr50.core.mcmmo.entity.EntityType; import com.gmail.nossr50.core.mcmmo.permissions.Permissible; import com.gmail.nossr50.core.mcmmo.world.World; -import com.gmail.nossr50.core.skills.ItemType; +import com.gmail.nossr50.core.skills.ConfigItemCategory; import com.gmail.nossr50.core.skills.MaterialType; import com.gmail.nossr50.core.skills.PrimarySkillType; import com.gmail.nossr50.core.skills.SubSkillType; @@ -366,12 +369,12 @@ public final class Permissions { return permissible.hasPermission("mcmmo.ability.herbalism.greenterra"); } - public static boolean greenThumbBlock(Permissible permissible, Material material) { - return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + material.toString().replace("_", "").toLowerCase()); + public static boolean greenThumbBlock(Permissible permissible, BlockType blockType) { + return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + blockType.getConfigName().toLowerCase()); } - public static boolean greenThumbPlant(Permissible permissible, Material material) { - return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + material.toString().replace("_", "").toLowerCase()); + public static boolean greenThumbPlant(Permissible permissible, BlockType blockType) { + return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + blockType.getConfigName().toLowerCase()); } /* MINING */ @@ -392,8 +395,8 @@ public final class Permissions { } /* REPAIR */ - public static boolean repairItemType(Permissible permissible, ItemType repairItemType) { - return permissible.hasPermission("mcmmo.ability.repair." + repairItemType.toString().toLowerCase() + "repair"); + public static boolean repairItemType(Permissible permissible, ConfigItemCategory repairConfigItemCategory) { + return permissible.hasPermission("mcmmo.ability.repair." + repairConfigItemCategory.toString().toLowerCase() + "repair"); } public static boolean repairMaterialType(Permissible permissible, MaterialType repairMaterialType) { @@ -409,8 +412,8 @@ public final class Permissions { return permissible.hasPermission("mcmmo.ability.salvage.arcanesalvage"); } - public static boolean salvageItemType(Permissible permissible, ItemType salvageItemType) { - return permissible.hasPermission("mcmmo.ability.salvage." + salvageItemType.toString().toLowerCase() + "salvage"); + public static boolean salvageItemType(Permissible permissible, ConfigItemCategory salvageConfigItemCategory) { + return permissible.hasPermission("mcmmo.ability.salvage." + salvageConfigItemCategory.toString().toLowerCase() + "salvage"); } public static boolean salvageMaterialType(Permissible permissible, MaterialType salvageMaterialType) { @@ -494,11 +497,9 @@ public final class Permissions { return permissible.hasPermission("mcmmo.commands.ptp.world." + world.getName()); } + //TODO: Do we even document that server admins can do this anywhere? public static void generateWorldTeleportPermissions() { - Server server = mcMMO.p.getServer(); - PluginManager pluginManager = server.getPluginManager(); - - for (World world : server.getWorlds()) { + for (World world : McmmoCore.getServer().getWorlds()) { addDynamicPermission("mcmmo.commands.ptp.world." + world.getName(), PermissionDefault.OP, pluginManager); } }