mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Start of work on allowing custom tool/block mods. This version should
allow for XP gain from vanilla blocks with custom tools. Please report any issues to facilitate further development.
This commit is contained in:
@ -53,7 +53,10 @@ public class Config extends ConfigLoader {
|
||||
public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss_Penalty_Percentage", 75); }
|
||||
public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism_Stat_Leech_Percentage", 5); }
|
||||
public boolean getHardcoreVampirismEnabled() { return config.getBoolean("Hardcore.Vampirism", false); }
|
||||
|
||||
|
||||
/* SMP Mods */
|
||||
public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }
|
||||
public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); }
|
||||
|
||||
/* Commands */
|
||||
public boolean getCommandXPLockEnabled() { return config.getBoolean("Commands.xplock.Enabled", true); }
|
||||
@ -446,7 +449,6 @@ public class Config extends ConfigLoader {
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
// If it doesn't exist, copy it from the .jar
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveDefaultConfig();
|
||||
|
@ -48,8 +48,6 @@ public class LoadTreasures extends ConfigLoader{
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
|
||||
// If it doesn't exist, copy it from the .jar
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveTreasuresConfig();
|
||||
@ -95,7 +93,7 @@ public class LoadTreasures extends ConfigLoader{
|
||||
int data = config.getInt("Treasures." + treasureName + ".Data");
|
||||
|
||||
if (Material.getMaterial(id) == null) {
|
||||
reason.add("Invlid id: " + id);
|
||||
reason.add("Invalid id: " + id);
|
||||
}
|
||||
|
||||
if (amount < 1) {
|
||||
|
109
src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java
Normal file
109
src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java
Normal file
@ -0,0 +1,109 @@
|
||||
package com.gmail.nossr50.config.mods;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||
|
||||
public class LoadCustomTools extends ConfigLoader {
|
||||
private static LoadCustomTools instance;
|
||||
|
||||
public static LoadCustomTools getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new LoadCustomTools(mcMMO.p);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public List<CustomTool> customAxes = new ArrayList<CustomTool>();
|
||||
public List<CustomTool> customBows = new ArrayList<CustomTool>();
|
||||
public List<CustomTool> customHoes = new ArrayList<CustomTool>();
|
||||
public List<CustomTool> customPickaxes = new ArrayList<CustomTool>();
|
||||
public List<CustomTool> customShovels = new ArrayList<CustomTool>();
|
||||
public List<CustomTool> customSwords = new ArrayList<CustomTool>();
|
||||
|
||||
public List<Integer> customAxeIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customBowIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customHoeIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customShovelIDs = new ArrayList<Integer>();
|
||||
public List<Integer> customSwordIDs = new ArrayList<Integer>();
|
||||
|
||||
private LoadCustomTools(mcMMO plugin) {
|
||||
super(plugin, "ModConfigs" + File.separator + "tools.yml");
|
||||
config = plugin.getToolsConfig();
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveToolsConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
plugin.getLogger().info("Loading mcMMO tools.yml File...");
|
||||
|
||||
loadTool("Axes", customAxes, customAxeIDs);
|
||||
loadTool("Bows", customBows, customBowIDs);
|
||||
loadTool("Hoes", customHoes, customHoeIDs);
|
||||
loadTool("Pickaxes", customPickaxes, customPickaxeIDs);
|
||||
loadTool("Shovels", customShovels, customShovelIDs);
|
||||
loadTool("Swords", customSwords, customSwordIDs);
|
||||
}
|
||||
|
||||
private void loadTool(String toolType, List<CustomTool> toolList, List<Integer> idList) {
|
||||
ConfigurationSection toolSection = config.getConfigurationSection(toolType);
|
||||
Set<String> toolConfigSet = toolSection.getKeys(false);
|
||||
Iterator<String> iterator = toolConfigSet.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String toolName = iterator.next();
|
||||
|
||||
int id = config.getInt(toolType + "." + toolName + ".ID");
|
||||
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
|
||||
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
|
||||
int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID");
|
||||
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value");
|
||||
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability");
|
||||
|
||||
if (id == 0) {
|
||||
plugin.getLogger().warning("Missing ID. This item will be skipped.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (repairable && (repairID == 0 || durability == 0)) {
|
||||
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
|
||||
repairable = false;
|
||||
}
|
||||
|
||||
CustomTool tool;
|
||||
|
||||
if (repairable) {
|
||||
ItemStack repairMaterial = new ItemStack(repairID, 1, (short) 0, repairData);
|
||||
tool = new CustomTool(durability, repairMaterial, repairable, multiplier, id);
|
||||
}
|
||||
else {
|
||||
tool = new CustomTool(durability, null, repairable, multiplier, id);
|
||||
}
|
||||
|
||||
toolList.add(tool);
|
||||
idList.add(id);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user