new config system pt 7 (jesus)

This commit is contained in:
nossr50 2019-02-15 17:45:48 -08:00
parent f9fb9a17a9
commit 4e8e95e3cb
26 changed files with 196 additions and 100 deletions

View File

@ -126,7 +126,7 @@ public class AdvancedConfig extends ConfigValidated {
private static AdvancedConfig instance; private static AdvancedConfig instance;
private AdvancedConfig() { private AdvancedConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true);
} }
public static AdvancedConfig getInstance() { public static AdvancedConfig getInstance() {

View File

@ -18,6 +18,9 @@ import java.io.InputStream;
//@ConfigSerializable //@ConfigSerializable
public abstract class Config implements VersionedConfig, Unload { public abstract class Config implements VersionedConfig, Unload {
/* SETTINGS */
private boolean mergeNewKeys;
/* PATH VARS */ /* PATH VARS */
public final File DIRECTORY_DATA_FOLDER; //Directory that the file is in 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 */ /* CONFIG MANAGER */
private ConfigurationLoader<CommentedConfigurationNode> configManager; private ConfigurationLoader<CommentedConfigurationNode> configManager;
public Config(String pathToParentFolder, String relativePath) { public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys) {
//TODO: Check if this works... //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..."); 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 * 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 mkdirDefaults(); // Make our default config dir
DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin
FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder 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"); McmmoCore.getLogger().info(userRootNode.getChildrenMap().size() +" items in default root map");
// Merge Values from default // Merge Values from default
userRootNode = userRootNode.mergeValuesFrom(defaultRootNode); if(mergeNewKeys)
userRootNode = userRootNode.mergeValuesFrom(defaultRootNode);
// Update config version // Update config version
updateConfigVersion(); updateConfigVersion();
@ -280,21 +285,41 @@ public abstract class Config implements VersionedConfig, Unload {
return userRootNode; 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) public int getIntValue(String... path)
{ {
return userRootNode.getNode(path).getInt(); 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) public double getDoubleValue(String... path)
{ {
return userRootNode.getNode(path).getDouble(); 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) public boolean getBooleanValue(String... path)
{ {
return userRootNode.getNode(path).getBoolean(); 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) public String getStringValue(String... path)
{ {
return userRootNode.getNode(path).getString(); return userRootNode.getNode(path).getString();

View File

@ -7,13 +7,13 @@ import java.io.File;
*/ */
public abstract class ConfigKeyRegister extends Config implements RegistersKeys { public abstract class ConfigKeyRegister extends Config implements RegistersKeys {
public ConfigKeyRegister(String pathToParentFolder, String relativePath) { public ConfigKeyRegister(String pathToParentFolder, String relativePath, boolean mergeNewKeys) {
super(pathToParentFolder, relativePath); super(pathToParentFolder, relativePath, mergeNewKeys);
loadKeys(); loadKeys();
} }
public ConfigKeyRegister(File pathToParentFolder, String relativePath) { public ConfigKeyRegister(File pathToParentFolder, String relativePath, boolean mergeNewKeys) {
super(pathToParentFolder, relativePath); super(pathToParentFolder, relativePath, mergeNewKeys);
loadKeys(); loadKeys();
} }
} }

View File

@ -9,15 +9,15 @@ import java.util.List;
* This class is used for config files that validate their entries * This class is used for config files that validate their entries
*/ */
public abstract class ConfigValidated extends Config implements DefaultKeys { 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(); validateEntries();
} }
public ConfigValidated(File parentFolderFile, String relativePath) public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys)
{ {
super(parentFolderFile, relativePath); super(parentFolderFile, relativePath, mergeNewKeys);
validateEntries(); validateEntries();
} }

View File

@ -9,7 +9,7 @@ public class CoreSkillsConfig extends Config {
private static CoreSkillsConfig instance; private static CoreSkillsConfig instance;
public CoreSkillsConfig() { public CoreSkillsConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true);
} }
public static CoreSkillsConfig getInstance() { public static CoreSkillsConfig getInstance() {

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.core.config;
import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.McmmoCore;
import com.gmail.nossr50.core.data.database.SQLDatabaseManager; import com.gmail.nossr50.core.data.database.SQLDatabaseManager;
import com.gmail.nossr50.core.datatypes.party.PartyFeature; 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.MobHealthbarType;
import com.gmail.nossr50.core.skills.PrimarySkillType; import com.gmail.nossr50.core.skills.PrimarySkillType;
import com.gmail.nossr50.core.skills.SuperAbilityType; import com.gmail.nossr50.core.skills.SuperAbilityType;
@ -16,7 +17,7 @@ public class MainConfig extends ConfigValidated {
private static MainConfig instance; private static MainConfig instance;
private MainConfig() { private MainConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true);
} }
public static MainConfig getInstance() { public static MainConfig getInstance() {

View File

@ -11,7 +11,7 @@ public class RankConfig extends ConfigValidated {
private static RankConfig instance; private static RankConfig instance;
public RankConfig() { public RankConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true);
this.instance = this; this.instance = this;
} }

View File

@ -10,7 +10,7 @@ public class SoundConfig extends ConfigValidated {
private static SoundConfig instance; private static SoundConfig instance;
public SoundConfig() { public SoundConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true);
this.instance = this; this.instance = this;
} }

View File

@ -76,8 +76,9 @@ public class ExperienceConfig extends ConfigValidated {
public static final String FEATHER_FALL_MULTIPLIER = "FeatherFall_Multiplier"; public static final String FEATHER_FALL_MULTIPLIER = "FeatherFall_Multiplier";
private static ExperienceConfig instance; private static ExperienceConfig instance;
//TODO: Should merge be false? Seems okay to leave it as true..
private ExperienceConfig() { private ExperienceConfig() {
super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml"); super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true);
} }
public static ExperienceConfig getInstance() { public static ExperienceConfig getInstance() {

View File

@ -3,7 +3,7 @@ package com.gmail.nossr50.core.config.mods;
import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.McmmoCore;
import com.gmail.nossr50.core.config.ConfigKeyRegister; import com.gmail.nossr50.core.config.ConfigKeyRegister;
import com.gmail.nossr50.core.mcmmo.item.ItemStack; 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.MaterialType;
import com.gmail.nossr50.core.skills.primary.repair.repairables.Repairable; 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.skills.primary.repair.repairables.RepairableFactory;
@ -22,7 +22,7 @@ public class CustomArmorConfig extends ConfigKeyRegister {
private boolean needsUpdate = false; private boolean needsUpdate = false;
protected CustomArmorConfig(String fileName) { protected CustomArmorConfig(String fileName) {
super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName); super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false);
loadKeys(); loadKeys();
} }
@ -101,7 +101,7 @@ public class CustomArmorConfig extends ConfigKeyRegister {
durability = (short) getIntValue(armorType + "." + armorName + ".Durability", 70); 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); materialList.add(armorMaterial);

View File

@ -24,7 +24,7 @@ public class CustomBlockConfig extends ConfigKeyRegister {
private boolean needsUpdate = false; private boolean needsUpdate = false;
protected CustomBlockConfig(String fileName) { protected CustomBlockConfig(String fileName) {
super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName); super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false);
loadKeys(); loadKeys();
} }

View File

@ -1,46 +1,74 @@
package com.gmail.nossr50.core.config.skills.repair; 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.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.MaterialType;
import com.gmail.nossr50.core.skills.primary.repair.repairables.Repairable; 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.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.ItemUtils;
import com.gmail.nossr50.core.util.skills.SkillUtils; import com.gmail.nossr50.core.util.skills.SkillUtils;
import ninja.leaping.configurate.ConfigurationNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
public class RepairConfig extends Config { /**
* This config
*/
public class RepairConfig extends ConfigKeyRegister {
private List<Repairable> repairables; private List<Repairable> repairables;
public RepairConfig(String fileName) { public RepairConfig(String fileName) {
super(fileName); super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
loadKeys(); loadKeys();
} }
@Override @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<Repairable>(); repairables = new ArrayList<Repairable>();
ConfigurationSection section = config.getConfigurationSection("Repairables"); ConfigurationNode repairablesNode = getUserRootNode().getNode("Repairables");
Set<String> keys = section.getKeys(false); List<? extends ConfigurationNode> repairablesNodeChildrenList = repairablesNode.getChildrenList();
Iterator<? extends ConfigurationNode> configIter = repairablesNodeChildrenList.iterator();
for (String key : keys) { for(Iterator<? extends ConfigurationNode> i = repairablesNodeChildrenList.iterator(); i.hasNext();)
if (config.contains("Repairables." + key + ".ItemId")) { {
backup(); ConfigurationNode iterNode = i.next();
return; //TODO: Verify that this is getting the key
} String key = iterNode.getKey().toString(); //Get the String of the node
// Validate all the things! // Validate all the things!
List<String> reason = new ArrayList<String>(); List<String> reason = new ArrayList<String>();
// 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); reason.add("Invalid material: " + key);
} }
@ -48,8 +76,8 @@ public class RepairConfig extends Config {
MaterialType repairMaterialType = MaterialType.OTHER; MaterialType repairMaterialType = MaterialType.OTHER;
String repairMaterialTypeString = getStringValue("Repairables." + key + ".MaterialType", "OTHER"); String repairMaterialTypeString = getStringValue("Repairables." + key + ".MaterialType", "OTHER");
if (!config.contains("Repairables." + key + ".MaterialType") && itemMaterial != null) { if (!config.contains("Repairables." + key + ".MaterialType") && itemType != null) {
ItemStack repairItem = new ItemStack(itemMaterial); ItemStack repairItem = ItemStack.makeNew(itemType);
if (ItemUtils.isWoodTool(repairItem)) { if (ItemUtils.isWoodTool(repairItem)) {
repairMaterialType = MaterialType.WOOD; repairMaterialType = MaterialType.WOOD;
@ -83,7 +111,7 @@ public class RepairConfig extends Config {
} }
// Maximum Durability // 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) { if (maximumDurability <= 0) {
maximumDurability = (short) getIntValue("Repairables." + key + ".MaximumDurability"); maximumDurability = (short) getIntValue("Repairables." + key + ".MaximumDurability");
@ -94,20 +122,20 @@ public class RepairConfig extends Config {
} }
// ItemStack Type // ItemStack Type
ItemType repairItemType = ItemType.OTHER; ConfigItemCategory repairConfigItemCategory = ConfigItemCategory.OTHER;
String repairItemTypeString = getStringValue("Repairables." + key + ".ItemType", "OTHER"); String repairItemTypeString = getStringValue("Repairables." + key + ".ItemType", "OTHER");
if (!config.contains("Repairables." + key + ".ItemType") && itemMaterial != null) { if (!config.contains("Repairables." + key + ".ItemType") && itemType != null) {
ItemStack repairItem = new ItemStack(itemMaterial); ItemStack repairItem = new ItemStack(itemType);
if (ItemUtils.isMinecraftTool(repairItem)) { if (ItemUtils.isMinecraftTool(repairItem)) {
repairItemType = ItemType.TOOL; repairConfigItemCategory = ConfigItemCategory.TOOL;
} else if (ItemUtils.isArmor(repairItem)) { } else if (ItemUtils.isArmor(repairItem)) {
repairItemType = ItemType.ARMOR; repairConfigItemCategory = ConfigItemCategory.ARMOR;
} }
} else { } else {
try { try {
repairItemType = ItemType.valueOf(repairItemTypeString); repairConfigItemCategory = ConfigItemCategory.valueOf(repairItemTypeString);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
reason.add(key + " has an invalid ItemType of " + repairItemTypeString); reason.add(key + " has an invalid ItemType of " + repairItemTypeString);
} }
@ -122,9 +150,9 @@ public class RepairConfig extends Config {
} }
// Minimum Quantity // 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); minimumQuantity = getIntValue("Repairables." + key + ".MinimumQuantity", 2);
} }
@ -133,7 +161,7 @@ public class RepairConfig extends Config {
} }
if (noErrorsInRepairable(reason)) { 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); repairables.add(repairable);
} }
} }

View File

@ -9,6 +9,13 @@ import java.util.ArrayList;
*/ */
public interface ItemStack { 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 * The maximum amount of this item allowed in a stack
* @return the maximum stack size of the item * @return the maximum stack size of the item

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.skills; package com.gmail.nossr50.core.skills;
public enum ItemType { public enum ConfigItemCategory {
ARMOR, ARMOR,
TOOL, TOOL,
OTHER; OTHER;

View File

@ -71,7 +71,7 @@ public class SalvageManager extends SkillManager {
} }
// Permissions checks on material and item types // 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"); NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
return; return;
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.skills.child.salvage.salvageables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
@ -31,7 +31,7 @@ public interface Salvageable {
* *
* @return the ItemType for this salvageable * @return the ItemType for this salvageable
*/ */
public ItemType getSalvageItemType(); public ConfigItemCategory getSalvageConfigItemCategory();
/** /**
* Gets the MaterialType value for this salvageable item * Gets the MaterialType value for this salvageable item

View File

@ -1,16 +1,16 @@
package com.gmail.nossr50.core.skills.child.salvage.salvageables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
public class SalvageableFactory { public class SalvageableFactory {
public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int maximumQuantity, short maximumDurability) { 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. // 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);
} }
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.skills.child.salvage.salvageables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,15 +10,15 @@ public class SimpleSalvageable implements Salvageable {
private final int maximumQuantity, minimumLevel; private final int maximumQuantity, minimumLevel;
private final short maximumDurability, baseSalvageDurability; private final short maximumDurability, baseSalvageDurability;
private final byte salvageMetadata; private final byte salvageMetadata;
private final ItemType salvageItemType; private final ConfigItemCategory salvageConfigItemCategory;
private final MaterialType salvageMaterialType; private final MaterialType salvageMaterialType;
private final double xpMultiplier; 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.itemMaterial = type;
this.salvageMaterial = salvageMaterial; this.salvageMaterial = salvageMaterial;
this.salvageMetadata = salvageMetadata; this.salvageMetadata = salvageMetadata;
this.salvageItemType = salvageItemType; this.salvageConfigItemCategory = salvageConfigItemCategory;
this.salvageMaterialType = salvageMaterialType; this.salvageMaterialType = salvageMaterialType;
this.minimumLevel = minimumLevel; this.minimumLevel = minimumLevel;
this.maximumQuantity = maximumQuantity; this.maximumQuantity = maximumQuantity;
@ -43,8 +43,8 @@ public class SimpleSalvageable implements Salvageable {
} }
@Override @Override
public ItemType getSalvageItemType() { public ConfigItemCategory getSalvageConfigItemCategory() {
return salvageItemType; return salvageConfigItemCategory;
} }
@Override @Override

View File

@ -77,7 +77,7 @@ public class RepairManager extends SkillManager {
return; return;
} }
if (!Permissions.repairItemType(player, repairable.getRepairItemType())) { if (!Permissions.repairItemType(player, repairable.getRepairConfigItemCategory())) {
NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission"); NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
return; return;
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.skills.primary.repair.repairables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
@ -39,7 +39,7 @@ public interface Repairable {
* *
* @return the RepairItemType for this repairable * @return the RepairItemType for this repairable
*/ */
public ItemType getRepairItemType(); public ConfigItemCategory getRepairConfigItemCategory();
/** /**
* Gets the RepairMaterialType value for this repairable item * Gets the RepairMaterialType value for this repairable item

View File

@ -1,21 +1,21 @@
package com.gmail.nossr50.core.skills.primary.repair.repairables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
public class RepairableFactory { public class RepairableFactory {
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumQuantity, short maximumDurability) { 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) { 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, repairItemType, repairMaterialType, 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. // 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);
} }
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.skills.primary.repair.repairables; 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 com.gmail.nossr50.core.skills.MaterialType;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,17 +10,17 @@ public class SimpleRepairable implements Repairable {
private final int minimumQuantity, minimumLevel; private final int minimumQuantity, minimumLevel;
private final short maximumDurability, baseRepairDurability; private final short maximumDurability, baseRepairDurability;
private final byte repairMetadata; private final byte repairMetadata;
private final ItemType repairItemType; private final ConfigItemCategory repairConfigItemCategory;
private final MaterialType repairMaterialType; private final MaterialType repairMaterialType;
private final double xpMultiplier; private final double xpMultiplier;
private String repairMaterialPrettyName; 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.itemMaterial = type;
this.repairMaterial = repairMaterial; this.repairMaterial = repairMaterial;
this.repairMetadata = repairMetadata; this.repairMetadata = repairMetadata;
this.repairMaterialPrettyName = repairMaterialPrettyName; this.repairMaterialPrettyName = repairMaterialPrettyName;
this.repairItemType = repairItemType; this.repairConfigItemCategory = repairConfigItemCategory;
this.repairMaterialType = repairMaterialType; this.repairMaterialType = repairMaterialType;
this.minimumLevel = minimumLevel; this.minimumLevel = minimumLevel;
this.minimumQuantity = minimumQuantity; this.minimumQuantity = minimumQuantity;
@ -50,8 +50,8 @@ public class SimpleRepairable implements Repairable {
} }
@Override @Override
public ItemType getRepairItemType() { public ConfigItemCategory getRepairConfigItemCategory() {
return repairItemType; return repairConfigItemCategory;
} }
@Override @Override

View File

@ -0,0 +1,7 @@
package com.gmail.nossr50.core.util;
public class InvalidItemException extends RuntimeException {
public InvalidItemException(String message) {
super(message);
}
}

View File

@ -1,18 +1,32 @@
package com.gmail.nossr50.core.util; 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.MainConfig;
import com.gmail.nossr50.core.config.party.ItemWeightConfig;
import com.gmail.nossr50.core.locale.LocaleLoader; import com.gmail.nossr50.core.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.core.mcmmo.colors.ChatColor;
import org.bukkit.ChatColor; import com.gmail.nossr50.core.mcmmo.item.ItemStack;
import org.bukkit.Material; import com.gmail.nossr50.core.mcmmo.item.ItemType;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
public final class ItemUtils { public final class ItemUtils {
private 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!");
} }
/** /**

View File

@ -1,8 +1,11 @@
package com.gmail.nossr50.core.util; 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.permissions.Permissible;
import com.gmail.nossr50.core.mcmmo.world.World; 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.MaterialType;
import com.gmail.nossr50.core.skills.PrimarySkillType; import com.gmail.nossr50.core.skills.PrimarySkillType;
import com.gmail.nossr50.core.skills.SubSkillType; import com.gmail.nossr50.core.skills.SubSkillType;
@ -366,12 +369,12 @@ public final class Permissions {
return permissible.hasPermission("mcmmo.ability.herbalism.greenterra"); return permissible.hasPermission("mcmmo.ability.herbalism.greenterra");
} }
public static boolean greenThumbBlock(Permissible permissible, Material material) { public static boolean greenThumbBlock(Permissible permissible, BlockType blockType) {
return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + material.toString().replace("_", "").toLowerCase()); return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + blockType.getConfigName().toLowerCase());
} }
public static boolean greenThumbPlant(Permissible permissible, Material material) { public static boolean greenThumbPlant(Permissible permissible, BlockType blockType) {
return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + material.toString().replace("_", "").toLowerCase()); return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + blockType.getConfigName().toLowerCase());
} }
/* MINING */ /* MINING */
@ -392,8 +395,8 @@ public final class Permissions {
} }
/* REPAIR */ /* REPAIR */
public static boolean repairItemType(Permissible permissible, ItemType repairItemType) { public static boolean repairItemType(Permissible permissible, ConfigItemCategory repairConfigItemCategory) {
return permissible.hasPermission("mcmmo.ability.repair." + repairItemType.toString().toLowerCase() + "repair"); return permissible.hasPermission("mcmmo.ability.repair." + repairConfigItemCategory.toString().toLowerCase() + "repair");
} }
public static boolean repairMaterialType(Permissible permissible, MaterialType repairMaterialType) { public static boolean repairMaterialType(Permissible permissible, MaterialType repairMaterialType) {
@ -409,8 +412,8 @@ public final class Permissions {
return permissible.hasPermission("mcmmo.ability.salvage.arcanesalvage"); return permissible.hasPermission("mcmmo.ability.salvage.arcanesalvage");
} }
public static boolean salvageItemType(Permissible permissible, ItemType salvageItemType) { public static boolean salvageItemType(Permissible permissible, ConfigItemCategory salvageConfigItemCategory) {
return permissible.hasPermission("mcmmo.ability.salvage." + salvageItemType.toString().toLowerCase() + "salvage"); return permissible.hasPermission("mcmmo.ability.salvage." + salvageConfigItemCategory.toString().toLowerCase() + "salvage");
} }
public static boolean salvageMaterialType(Permissible permissible, MaterialType salvageMaterialType) { 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()); 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() { public static void generateWorldTeleportPermissions() {
Server server = mcMMO.p.getServer(); for (World world : McmmoCore.getServer().getWorlds()) {
PluginManager pluginManager = server.getPluginManager();
for (World world : server.getWorlds()) {
addDynamicPermission("mcmmo.commands.ptp.world." + world.getName(), PermissionDefault.OP, pluginManager); addDynamicPermission("mcmmo.commands.ptp.world." + world.getName(), PermissionDefault.OP, pluginManager);
} }
} }