mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Kill the MultiConfigs
This commit is contained in:
parent
661c63a8aa
commit
ac67e006d8
@ -69,18 +69,11 @@ import java.util.HashMap;
|
||||
*/
|
||||
public final class ConfigManager {
|
||||
|
||||
|
||||
|
||||
/* UNLOAD REGISTER */
|
||||
|
||||
private ArrayList<Unload> unloadables;
|
||||
private ArrayList<File> userFiles;
|
||||
|
||||
/* MULTI CONFIG INSTANCES */
|
||||
|
||||
//private MultiConfigContainer<Repairable> repairableMultiConfigContainer;
|
||||
//private MultiConfigContainer<Salvageable> salvageableMultiConfigContainer;
|
||||
|
||||
/* COLLECTION MANAGERS */
|
||||
|
||||
private RepairableManager repairableManager;
|
||||
|
@ -1,6 +0,0 @@
|
||||
package com.gmail.nossr50.config.collectionconfigs;
|
||||
|
||||
public enum CollectionClassType {
|
||||
REPAIR,
|
||||
SALVAGE;
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
/*
|
||||
package com.gmail.nossr50.config.collectionconfigs;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigCollection;
|
||||
import com.gmail.nossr50.config.Unload;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
*/
|
||||
/**
|
||||
* Represents a type of config collection, these config collections are spread across multiple config files potentially
|
||||
* @param <T>
|
||||
*//*
|
||||
|
||||
public class MultiConfigContainer<T> implements Unload {
|
||||
|
||||
*/
|
||||
/* CONSTANTS *//*
|
||||
|
||||
public static final String DEFAULT_MULTICONFIG_FILENAME_SUFFIX = ".vanilla.yml";
|
||||
|
||||
*/
|
||||
/* VARS *//*
|
||||
|
||||
private final String configPrefix;
|
||||
private Collection<T> collection;
|
||||
public final CollectionClassType collectionClassType;
|
||||
private ConfigCollection vanillaConfig;
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
collection.clear();
|
||||
vanillaConfig.unload();
|
||||
}
|
||||
|
||||
public MultiConfigContainer(String configPrefix, CollectionClassType collectionClassType)
|
||||
{
|
||||
//Define Config Class
|
||||
this.collectionClassType = collectionClassType;
|
||||
|
||||
//Define Config Filename Prefix
|
||||
this.configPrefix = configPrefix;
|
||||
|
||||
//Init Collection
|
||||
collection = new ArrayList<T>();
|
||||
|
||||
//Load Configs
|
||||
|
||||
//Vanilla Config
|
||||
initConfigAndAddCollection(getVanillaConfigName(configPrefix), false, true);
|
||||
|
||||
//Custom Configs
|
||||
loadCustomCollections(configPrefix);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Add another collection to this collection
|
||||
* @param otherCollection
|
||||
*//*
|
||||
|
||||
private void addCollection(Collection<T> otherCollection)
|
||||
{
|
||||
collection.addAll(otherCollection);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Grabs the Class to instance for this config collection
|
||||
* @param collectionClassType the type of class
|
||||
* @return the class to instance for this config collection
|
||||
*//*
|
||||
|
||||
private Class getConfigClass(CollectionClassType collectionClassType)
|
||||
{
|
||||
switch(collectionClassType) {
|
||||
case REPAIR:
|
||||
return RepairConfig.class;
|
||||
case SALVAGE:
|
||||
return SalvageConfig.class;
|
||||
default:
|
||||
mcMMO.p.getLogger().severe("[DEBUG] Config Class type is undefined!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Gets the name of the vanilla config which is always present
|
||||
* @param configPrefix the prefix to the filename, for example "repair" or "salvage"
|
||||
* @return the name of the vanilla config file for this collection
|
||||
*//*
|
||||
|
||||
private String getVanillaConfigName(String configPrefix)
|
||||
{
|
||||
return configPrefix+DEFAULT_MULTICONFIG_FILENAME_SUFFIX;
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Initializes a config and attempts to load add its collection
|
||||
* @param fileName
|
||||
* @param merge
|
||||
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
|
||||
*//*
|
||||
|
||||
private void initConfigAndAddCollection(String fileName, boolean merge, boolean copyDefaults)
|
||||
{
|
||||
mcMMO.p.getLogger().info("Reading from collection config - "+fileName);
|
||||
ConfigCollection configCollection = null;
|
||||
|
||||
if(collectionClassType == CollectionClassType.REPAIR)
|
||||
{
|
||||
configCollection = new RepairConfig(fileName, merge, copyDefaults);
|
||||
} else {
|
||||
configCollection = new SalvageConfig(fileName, merge, copyDefaults);
|
||||
}
|
||||
|
||||
*/
|
||||
/*try {
|
||||
//String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys
|
||||
//String fileName, boolean merge, boolean copyDefaults
|
||||
configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class, Boolean.class, Boolean.class).newInstance(fileName, merge, copyDefaults);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}*//*
|
||||
|
||||
|
||||
//Add the collection loaded from this config
|
||||
addCollection(configCollection.getLoadedCollection());
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* mcMMO allows collection config files to be named things like repair.whatevernameyouwanthere.yml and so on,
|
||||
* these files are treated in the same way as the vanilla file. They serve the purpose of organization
|
||||
* @param configPrefix the prefix of the file name, for example "repair", "salvage", etc
|
||||
*//*
|
||||
|
||||
public void loadCustomCollections(String configPrefix)
|
||||
{
|
||||
String vanillaConfigFileName = getVanillaConfigName(configPrefix);
|
||||
|
||||
//Find other files
|
||||
Pattern pattern = Pattern.compile(configPrefix+"\\.(?:.+)\\.yml");
|
||||
//File dataFolder = McmmoCore.getDataFolderPath();
|
||||
File dataFolder = mcMMO.p.getDataFolder();
|
||||
|
||||
for (String fileName : dataFolder.list()) {
|
||||
//Vanilla Config is already loaded
|
||||
if(fileName.equalsIgnoreCase(vanillaConfigFileName))
|
||||
continue;
|
||||
|
||||
//Find files that match the pattern
|
||||
if (!pattern.matcher(fileName).matches()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Init file
|
||||
File currentFile = new File(dataFolder, fileName);
|
||||
|
||||
//Make sure its not a directory (needed?)
|
||||
if(currentFile.isDirectory())
|
||||
continue;
|
||||
|
||||
//Load and add the collections
|
||||
initConfigAndAddCollection(fileName, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<T> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
*/
|
@ -1,119 +0,0 @@
|
||||
package com.gmail.nossr50.config.collectionconfigs;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigCollection;
|
||||
import com.gmail.nossr50.config.ConfigCollections;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents a collection of config files that serve a similar purpose
|
||||
* For example, files named repair.*.yml are all loaded into memory, this lets admins keep their config files clean
|
||||
*
|
||||
* To be honest I'm not sure how many people make use of this system, but I'm keeping it since its been in mcMMO for like 6+ years
|
||||
*/
|
||||
public final class MultiConfigManager {
|
||||
|
||||
public static final String DEFAULT_MULTICONFIG_FILENAME_SUFFIX = ".vanilla.yml";
|
||||
|
||||
//Configs
|
||||
public com.gmail.nossr50.config.collectionconfigs.RepairConfig vanillaRepairConfig; //This is the main config file that mcMMO will copy out
|
||||
public com.gmail.nossr50.config.collectionconfigs.SalvageConfig vanillaSalvageConfig;
|
||||
|
||||
private static List<Repairable> repairables;
|
||||
private static List<Salvageable> salvageables;
|
||||
|
||||
public MultiConfigManager(String fileNamePrefix)
|
||||
{
|
||||
//init Collections
|
||||
repairables = new ArrayList<>();
|
||||
salvageables = new ArrayList<>();
|
||||
|
||||
//init vanilla configs
|
||||
vanillaRepairConfig = new com.gmail.nossr50.config.collectionconfigs.RepairConfig(getVanillaConfigName("repair"));
|
||||
vanillaSalvageConfig = new com.gmail.nossr50.config.collectionconfigs.SalvageConfig(getVanillaConfigName("salvage"));
|
||||
|
||||
//add valid vanilla collections to main collection
|
||||
repairables.addAll(vanillaRepairConfig.getLoadedCollection());
|
||||
salvageables.addAll(vanillaSalvageConfig.getLoadedCollection());
|
||||
|
||||
//add valid custom collections to main collection
|
||||
loadCustomCollections("repair", repairables, com.gmail.nossr50.config.collectionconfigs.RepairConfig.class);
|
||||
loadCustomCollections("salvage", salvageables, com.gmail.nossr50.config.collectionconfigs.SalvageConfig.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* mcMMO allows collection config files to be named things like repair.whatevernameyouwanthere.yml and so on,
|
||||
* these files are treated in the same way as the vanilla file. They serve the purpose of organization
|
||||
* @param configPrefix the prefix of the file name, for example "repair", "salvage", etc
|
||||
* @param collection the collection that will be added to
|
||||
*/
|
||||
public void loadCustomCollections(String configPrefix, Collection<?> collection, Class<? extends ConfigCollection> configClass)
|
||||
{
|
||||
String vanillaConfigFileName = getVanillaConfigName(configPrefix);
|
||||
|
||||
//Find other files
|
||||
Pattern pattern = Pattern.compile(configPrefix+"\\.(?:.+)\\.yml");
|
||||
//File dataFolder = McmmoCore.getDataFolderPath();
|
||||
File dataFolder = mcMMO.p.getDataFolder();
|
||||
|
||||
for (String fileName : dataFolder.list()) {
|
||||
//Vanilla Config is already loaded
|
||||
if(fileName.equalsIgnoreCase(vanillaConfigFileName))
|
||||
continue;
|
||||
|
||||
//Find files that match the pattern
|
||||
if (!pattern.matcher(fileName).matches()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Init file
|
||||
File currentFile = new File(dataFolder, fileName);
|
||||
|
||||
//Make sure its not a directory (needed?)
|
||||
if(currentFile.isDirectory())
|
||||
continue;
|
||||
|
||||
try {
|
||||
//TODO: Valid?
|
||||
ConfigCollections customConfig = (ConfigCollections) getConfigClass(configPrefix).getConstructor(String.class).newInstance(configPrefix);
|
||||
collection.addAll(customConfig.getLoadedCollection());
|
||||
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getVanillaConfigName(String configPrefix)
|
||||
{
|
||||
return configPrefix+DEFAULT_MULTICONFIG_FILENAME_SUFFIX;
|
||||
}
|
||||
|
||||
private Class getConfigClass(String configPrefix)
|
||||
{
|
||||
switch(configPrefix) {
|
||||
case "repair":
|
||||
return RepairConfig.class;
|
||||
case "salvage":
|
||||
return SalvageConfig.class;
|
||||
default:
|
||||
mcMMO.p.getLogger().severe("[DEBUG] Config Class is null!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
/*
|
||||
package com.gmail.nossr50.config.collectionconfigs;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigCollection;
|
||||
import com.gmail.nossr50.config.ConfigConstants;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
*/
|
||||
/**
|
||||
* This config
|
||||
*//*
|
||||
|
||||
@ConfigSerializable
|
||||
public class RepairConfig extends ConfigCollection {
|
||||
|
||||
public static final String REPAIRABLES = "Repairables";
|
||||
public static final String ITEM_ID = "ItemId";
|
||||
public static final String MATERIAL_TYPE = "ItemMaterialCategory";
|
||||
public static final String REPAIR_MATERIAL = "RepairMaterial";
|
||||
public static final String MAXIMUM_DURABILITY = "MaximumDurability";
|
||||
public static final String ITEM_TYPE = "ItemType";
|
||||
public static final String METADATA = "Metadata";
|
||||
public static final String XP_MULTIPLIER = "XpMultiplier";
|
||||
public static final String MINIMUM_LEVEL = "MinimumLevel";
|
||||
public static final String MINIMUM_QUANTITY = "MinimumQuantity";
|
||||
|
||||
public RepairConfig() {
|
||||
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false);
|
||||
super("repair", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_SKILLS_DIR, true, false, true, false);
|
||||
register();
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* The version of this config
|
||||
*
|
||||
* @return
|
||||
*//*
|
||||
|
||||
@Override
|
||||
public double getConfigVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
//Grab the "keys" under the Repairables node
|
||||
ArrayList<ConfigurationNode> repairChildrenNodes = new ArrayList<>(getChildren(REPAIRABLES));
|
||||
|
||||
//TODO: Remove Debug
|
||||
if(repairChildrenNodes.size() <= 0) {
|
||||
mcMMO.p.getLogger().severe("DEBUG: Repair MultiConfigContainer key list is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
for (ConfigurationNode repairNode : repairChildrenNodes) {
|
||||
// Validate all the things!
|
||||
List<String> errorMessages = new ArrayList<String>();
|
||||
|
||||
*/
|
||||
/*
|
||||
* Match the name of the key to a Material constant definition
|
||||
*//*
|
||||
|
||||
String repairChildNodeName = repairNode.getString();
|
||||
Material itemMaterial = Material.matchMaterial(repairChildNodeName);
|
||||
|
||||
if (itemMaterial == null) {
|
||||
mcMMO.p.getLogger().severe("Repair Invalid material: " + repairChildNodeName);
|
||||
continue;
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
* Determine Repair Material Type
|
||||
*//*
|
||||
|
||||
ItemMaterialCategory repairMaterialType = ItemMaterialCategory.OTHER;
|
||||
String repairMaterialTypeString = getRepairMaterialTypeString(repairChildNodeName);
|
||||
|
||||
if (hasNode(REPAIRABLES, repairChildNodeName, MATERIAL_TYPE)) {
|
||||
ItemStack repairItem = new ItemStack(itemMaterial);
|
||||
|
||||
if (ItemUtils.isWoodTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.WOOD;
|
||||
}
|
||||
else if (ItemUtils.isStoneTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.STONE;
|
||||
}
|
||||
else if (ItemUtils.isStringTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.STRING;
|
||||
}
|
||||
else if (ItemUtils.isLeatherArmor(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.LEATHER;
|
||||
}
|
||||
else if (ItemUtils.isIronArmor(repairItem) || ItemUtils.isIronTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.IRON;
|
||||
}
|
||||
else if (ItemUtils.isGoldArmor(repairItem) || ItemUtils.isGoldTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.GOLD;
|
||||
}
|
||||
else if (ItemUtils.isDiamondArmor(repairItem) || ItemUtils.isDiamondTool(repairItem)) {
|
||||
repairMaterialType = ItemMaterialCategory.DIAMOND;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//If a material cannot be matched, try matching the material to its repair material type string from the config
|
||||
try {
|
||||
repairMaterialType = ItemMaterialCategory.valueOf(repairMaterialTypeString.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
errorMessages.add("Repair Config: " + repairChildNodeName + " has an invalid " + MATERIAL_TYPE + " of " + repairMaterialTypeString);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Repair Material
|
||||
String repairMaterialName = getRepairMaterialStringName(repairChildNodeName);
|
||||
Material repairMaterial = (repairMaterialName == null ? repairMaterialType.getDefaultMaterial() : Material.matchMaterial(repairMaterialName));
|
||||
|
||||
if (repairMaterial == null) {
|
||||
errorMessages.add(repairChildNodeName + " has an invalid repair material: " + repairMaterialName);
|
||||
}
|
||||
|
||||
// Maximum Durability
|
||||
short maximumDurability = (itemMaterial != null ? itemMaterial.getMaxDurability() : getRepairableMaximumDurability(repairChildNodeName));
|
||||
|
||||
if (maximumDurability <= 0) {
|
||||
maximumDurability = getRepairableMaximumDurability(repairChildNodeName);
|
||||
}
|
||||
|
||||
if (maximumDurability <= 0) {
|
||||
errorMessages.add("Maximum durability of " + repairChildNodeName + " must be greater than 0!");
|
||||
}
|
||||
|
||||
// Item Type
|
||||
ItemType repairItemType = ItemType.OTHER;
|
||||
String repairItemTypeString = "";
|
||||
|
||||
if(hasNode(REPAIRABLES, repairChildNodeName, ITEM_TYPE))
|
||||
repairItemTypeString = getStringValue(REPAIRABLES, repairChildNodeName, ITEM_TYPE);
|
||||
else
|
||||
repairItemTypeString = "OTHER";
|
||||
|
||||
if (!hasNode(REPAIRABLES, repairChildNodeName, ITEM_TYPE) && itemMaterial != null) {
|
||||
ItemStack repairItem = new ItemStack(itemMaterial);
|
||||
|
||||
if (ItemUtils.isMinecraftTool(repairItem)) {
|
||||
repairItemType = ItemType.TOOL;
|
||||
}
|
||||
else if (ItemUtils.isArmor(repairItem)) {
|
||||
repairItemType = ItemType.ARMOR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
repairItemType = ItemType.valueOf(repairItemTypeString);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
errorMessages.add(repairChildNodeName + " has an invalid ItemType of " + repairItemTypeString);
|
||||
}
|
||||
}
|
||||
|
||||
byte repairMetadata = -1;
|
||||
|
||||
//Set the metadata byte
|
||||
if(hasNode(REPAIRABLES, repairChildNodeName, REPAIR_MATERIAL, METADATA))
|
||||
repairMetadata = (byte) getIntValue(REPAIRABLES, repairChildNodeName, REPAIR_MATERIAL, METADATA);
|
||||
|
||||
int minimumLevel = getIntValue(REPAIRABLES, repairChildNodeName, MINIMUM_LEVEL);
|
||||
|
||||
double xpMultiplier = 1;
|
||||
|
||||
if(hasNode(REPAIRABLES, repairChildNodeName, XP_MULTIPLIER))
|
||||
xpMultiplier = getDoubleValue(REPAIRABLES, repairChildNodeName, XP_MULTIPLIER);
|
||||
|
||||
// Minimum Quantity
|
||||
int minimumQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(itemMaterial), repairMaterial, repairMetadata);
|
||||
|
||||
if (minimumQuantity <= 0) {
|
||||
minimumQuantity = getIntValue(REPAIRABLES, repairChildNodeName, MINIMUM_QUANTITY);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
* VALIDATE
|
||||
* Just make sure the values we may have just grabbed from the config aren't below 0
|
||||
*//*
|
||||
|
||||
|
||||
//Validate min level
|
||||
if(minimumLevel < 0)
|
||||
minimumLevel = 0;
|
||||
|
||||
//Validate XP Mult
|
||||
if(xpMultiplier < 0)
|
||||
xpMultiplier = 0;
|
||||
|
||||
//Validate Minimum Quantity
|
||||
if (minimumQuantity <= 0) {
|
||||
minimumQuantity = 2;
|
||||
errorMessages.add("Minimum quantity for "+repairChildNodeName+" in repair config should be above 0");
|
||||
}
|
||||
|
||||
Repairable repairable = RepairableFactory.getRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
|
||||
genericCollection.add(repairable);
|
||||
|
||||
for (String error : errorMessages) {
|
||||
//McmmoCore.getLogger().warning(issue);
|
||||
mcMMO.p.getLogger().warning(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getRepairMaterialTypeString(String key) {
|
||||
return getStringValue(REPAIRABLES, key, MATERIAL_TYPE);
|
||||
}
|
||||
|
||||
private short getRepairableMaximumDurability(String key) {
|
||||
return getShortValue(REPAIRABLES, key, MAXIMUM_DURABILITY);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* Gets the Repair Material String Name defined in the config
|
||||
* @param key the key name of the repairable child node under the Repairables parent node
|
||||
* @return the Repair Material String Name defined in the config
|
||||
*//*
|
||||
|
||||
private String getRepairMaterialStringName(String key) {
|
||||
return getStringValue(REPAIRABLES, key, REPAIR_MATERIAL);
|
||||
}
|
||||
}
|
||||
*/
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
@ConfigSerializable
|
||||
public class ConfigSalvage {
|
||||
|
||||
private final static List<Salvageable> DEFAULT_SALVAGEABLES_LIST;
|
||||
private final static ArrayList<Salvageable> DEFAULT_SALVAGEABLES_LIST;
|
||||
|
||||
static {
|
||||
DEFAULT_SALVAGEABLES_LIST = new ArrayList<>();
|
||||
@ -233,8 +233,8 @@ public class ConfigSalvage {
|
||||
*/
|
||||
}
|
||||
|
||||
@Setting()
|
||||
List<Salvageable> configSalvageablesList;
|
||||
@Setting(value = "Z-Salvageables", comment = "Salvage rewards and misc parameters")
|
||||
ArrayList<Salvageable> configSalvageablesList = DEFAULT_SALVAGEABLES_LIST;
|
||||
|
||||
|
||||
@Setting(value = "Arcane-Salvage", comment = "Settings related to the Arcane Salvage Sub-Skill")
|
||||
|
@ -37,53 +37,8 @@ public class Repairable {
|
||||
this.maximumDurability = this.itemMaterial.getMaxDurability();
|
||||
this.baseRepairDurability = (short) (maximumDurability / minimumQuantity);
|
||||
|
||||
this.repairItemType = determineItemType(this.itemMaterial);
|
||||
this.repairItemMaterialCategory = determineMaterialType(this.repairMaterials.get(0));
|
||||
}
|
||||
|
||||
public ItemMaterialCategory determineMaterialType(Material material) {
|
||||
switch (material) {
|
||||
case STRING:
|
||||
return ItemMaterialCategory.STRING;
|
||||
|
||||
case LEATHER:
|
||||
return ItemMaterialCategory.LEATHER;
|
||||
|
||||
case ACACIA_PLANKS:
|
||||
case BIRCH_PLANKS:
|
||||
case DARK_OAK_PLANKS:
|
||||
case JUNGLE_PLANKS:
|
||||
case OAK_PLANKS:
|
||||
case SPRUCE_PLANKS:
|
||||
return ItemMaterialCategory.WOOD;
|
||||
|
||||
case STONE:
|
||||
return ItemMaterialCategory.STONE;
|
||||
|
||||
case IRON_INGOT:
|
||||
return ItemMaterialCategory.IRON;
|
||||
|
||||
case GOLD_INGOT:
|
||||
return ItemMaterialCategory.GOLD;
|
||||
|
||||
case DIAMOND:
|
||||
return ItemMaterialCategory.DIAMOND;
|
||||
|
||||
default:
|
||||
return ItemMaterialCategory.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
private ItemType determineItemType(Material material)
|
||||
{
|
||||
if (ItemUtils.isMinecraftTool(new ItemStack(material))) {
|
||||
return ItemType.TOOL;
|
||||
}
|
||||
else if (ItemUtils.isArmor(new ItemStack((material)))) {
|
||||
return ItemType.ARMOR;
|
||||
} else {
|
||||
return ItemType.OTHER;
|
||||
}
|
||||
this.repairItemType = ItemUtils.determineItemType(this.itemMaterial);
|
||||
this.repairItemMaterialCategory = ItemUtils.determineMaterialType(this.repairMaterials.get(0));
|
||||
}
|
||||
|
||||
public Material getItemMaterial() {
|
||||
|
@ -5,14 +5,15 @@ import org.bukkit.Material;
|
||||
|
||||
public class Salvage {
|
||||
|
||||
public static Material anvilMaterial;
|
||||
public static boolean arcaneSalvageDowngrades;
|
||||
public static boolean arcaneSalvageEnchantLoss;
|
||||
|
||||
public Salvage() {
|
||||
anvilMaterial = mcMMO.getConfigManager().getConfigSalvage().getGeneral().getSalvageAnvilMaterial();
|
||||
arcaneSalvageDowngrades = mcMMO.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isDowngradesEnabled();
|
||||
arcaneSalvageEnchantLoss = mcMMO.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isMayLoseEnchants();
|
||||
}
|
||||
public static Material anvilMaterial;
|
||||
public static boolean arcaneSalvageDowngrades;
|
||||
public static boolean arcaneSalvageEnchantLoss;
|
||||
|
||||
protected static int calculateSalvageableAmount(short currentDurability, short maxDurability, int baseAmount) {
|
||||
double percentDamaged = (maxDurability <= 0) ? 1D : (double) (maxDurability - currentDurability) / maxDurability;
|
||||
|
@ -104,7 +104,6 @@ public class SalvageManager extends SkillManager {
|
||||
|
||||
salvageableAmount = Math.min(salvageableAmount, getSalvageableAmount()); // Always get at least something back, if you're capable of salvaging it.
|
||||
|
||||
|
||||
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||
location.add(0.5, 1, 0.5);
|
||||
|
||||
@ -115,7 +114,7 @@ public class SalvageManager extends SkillManager {
|
||||
enchantBook = arcaneSalvageCheck(enchants);
|
||||
}
|
||||
|
||||
ItemStack salvageResults = new ItemStack(salvageable.getSalvageMaterial(), salvageableAmount);
|
||||
ItemStack salvageResults = new ItemStack(salvageable.getSalvagedItemMaterial(), salvageableAmount);
|
||||
|
||||
//Call event
|
||||
if (EventUtils.callSalvageCheckEvent(player, item, salvageResults, enchantBook).isCancelled()) {
|
||||
|
@ -2,31 +2,22 @@ package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a 'Salvageable' item
|
||||
* Includes all the data needed for determining rewards from Salvage
|
||||
*/
|
||||
public class Salvageable {
|
||||
private final Material itemMaterial, salvagedItemMaterial;
|
||||
private final int maximumQuantity, minimumLevel;
|
||||
private final short maximumDurability, baseSalvageDurability;
|
||||
private final byte salvageMetadata;
|
||||
private final ItemType salvageItemType;
|
||||
private final ItemMaterialCategory salvageItemMaterialCategory;
|
||||
private final double xpMultiplier;
|
||||
|
||||
/*protected Salvageable(Material type, Material salvagedItemMaterial, byte salvageMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ItemType salvageItemType, ItemMaterialCategory salvageItemMaterialCategory, double xpMultiplier) {
|
||||
this.itemMaterial = type;
|
||||
this.salvagedItemMaterial = salvagedItemMaterial;
|
||||
this.salvageMetadata = salvageMetadata;
|
||||
this.salvageItemType = salvageItemType;
|
||||
this.salvageItemMaterialCategory = salvageItemMaterialCategory;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.maximumQuantity = maximumQuantity;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.baseSalvageDurability = (short) (maximumDurability / maximumQuantity);
|
||||
this.xpMultiplier = xpMultiplier;
|
||||
}*/
|
||||
|
||||
public Salvageable(String itemRegisterKey, String salvagedMaterialRegisterKey, int minimumLevel, int maximumQuantity)
|
||||
{
|
||||
this(Material.matchMaterial(itemRegisterKey), Material.matchMaterial(salvagedMaterialRegisterKey), minimumLevel, maximumQuantity);
|
||||
@ -34,17 +25,15 @@ public class Salvageable {
|
||||
|
||||
public Salvageable(Material itemMaterial, Material salvagedItemMaterial, int minimumLevel, int maximumQuantity)
|
||||
{
|
||||
|
||||
this.itemMaterial = itemMaterial;
|
||||
this.salvagedItemMaterial = salvagedItemMaterial;
|
||||
// this.salvageMetadata = salvageMetadata;
|
||||
this.salvageItemType = salvageItemType;
|
||||
this.salvageItemMaterialCategory = salvageItemMaterialCategory;
|
||||
this.salvageItemType = ItemUtils.determineItemType(itemMaterial);
|
||||
this.salvageItemMaterialCategory = ItemUtils.determineMaterialType(salvagedItemMaterial);
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.maximumQuantity = maximumQuantity;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.maximumDurability = itemMaterial.getMaxDurability();
|
||||
this.baseSalvageDurability = (short) (maximumDurability / maximumQuantity);
|
||||
this.xpMultiplier = xpMultiplier;
|
||||
this.xpMultiplier = 1.0D;
|
||||
}
|
||||
|
||||
public Material getItemMaterial() {
|
||||
@ -55,10 +44,6 @@ public class Salvageable {
|
||||
return salvagedItemMaterial;
|
||||
}
|
||||
|
||||
/*public byte getSalvageMaterialMetadata() {
|
||||
return salvageMetadata;
|
||||
}*/
|
||||
|
||||
public ItemType getSalvageItemType() {
|
||||
return salvageItemType;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.MainConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -40,6 +42,61 @@ public final class ItemUtils {
|
||||
return matchedMaterials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the item type, currently used for repairables/salvageables
|
||||
* @param material target material
|
||||
* @return the matching ItemType returns OTHER if no match
|
||||
*/
|
||||
public static ItemType determineItemType(Material material)
|
||||
{
|
||||
if (ItemUtils.isMinecraftTool(new ItemStack(material))) {
|
||||
return ItemType.TOOL;
|
||||
}
|
||||
else if (ItemUtils.isArmor(new ItemStack((material)))) {
|
||||
return ItemType.ARMOR;
|
||||
} else {
|
||||
return ItemType.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the material category, currently used for repairables/salvageables
|
||||
* @param material target material
|
||||
* @return the matching ItemMaterialCategory, return OTHER if no match
|
||||
*/
|
||||
public static ItemMaterialCategory determineMaterialType(Material material) {
|
||||
switch (material) {
|
||||
case STRING:
|
||||
return ItemMaterialCategory.STRING;
|
||||
|
||||
case LEATHER:
|
||||
return ItemMaterialCategory.LEATHER;
|
||||
|
||||
case ACACIA_PLANKS:
|
||||
case BIRCH_PLANKS:
|
||||
case DARK_OAK_PLANKS:
|
||||
case JUNGLE_PLANKS:
|
||||
case OAK_PLANKS:
|
||||
case SPRUCE_PLANKS:
|
||||
return ItemMaterialCategory.WOOD;
|
||||
|
||||
case STONE:
|
||||
return ItemMaterialCategory.STONE;
|
||||
|
||||
case IRON_INGOT:
|
||||
return ItemMaterialCategory.IRON;
|
||||
|
||||
case GOLD_INGOT:
|
||||
return ItemMaterialCategory.GOLD;
|
||||
|
||||
case DIAMOND:
|
||||
return ItemMaterialCategory.DIAMOND;
|
||||
|
||||
default:
|
||||
return ItemMaterialCategory.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the item is a bow.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user