Ver código fonte

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.

GJ 13 anos atrás
pai
commit
2b4ca80a95

+ 4 - 2
src/main/java/com/gmail/nossr50/config/Config.java

@@ -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();

+ 1 - 3
src/main/java/com/gmail/nossr50/config/LoadTreasures.java

@@ -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 - 0
src/main/java/com/gmail/nossr50/config/mods/LoadCustomTools.java

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

+ 1 - 1
src/main/java/com/gmail/nossr50/datatypes/ToolType.java

@@ -48,7 +48,7 @@ public enum ToolType {
             return ItemChecks.isHoe(is);
 
         case PICKAXE:
-            return ItemChecks.isMiningPick(is);
+            return ItemChecks.isPickaxe(is);
 
         case SHOVEL:
             return ItemChecks.isShovel(is);

+ 59 - 0
src/main/java/com/gmail/nossr50/datatypes/mods/CustomTool.java

@@ -0,0 +1,59 @@
+package com.gmail.nossr50.datatypes.mods;
+
+import org.bukkit.inventory.ItemStack;
+
+public class CustomTool {
+    private int itemID;
+    private double xpMultiplier;
+    private boolean repairable;
+    private ItemStack repairMaterial;
+    private short durability;
+
+    public CustomTool(short durability, ItemStack repairMaterial, boolean repairable, double xpMultiplier, int itemID) {
+        this.itemID = itemID;
+        this.xpMultiplier = xpMultiplier;
+        this.repairable = repairable;
+        this.repairMaterial = repairMaterial;
+        this.durability = durability;
+    }
+
+    public int getItemID() {
+        return itemID;
+    }
+
+    public void setItemID(int itemID) {
+        this.itemID = itemID;
+    }
+
+    public double getXpMultiplier() {
+        return xpMultiplier;
+    }
+
+    public void setXpMultiplier(Double xpMultiplier) {
+        this.xpMultiplier = xpMultiplier;
+    }
+
+    public boolean isRepairable() {
+        return repairable;
+    }
+
+    public void setRepairable(boolean repairable) {
+        this.repairable = repairable;
+    }
+
+    public ItemStack getRepairMaterial() {
+        return repairMaterial;
+    }
+
+    public void setRepairMaterial(ItemStack repairMaterial) {
+        this.repairMaterial = repairMaterial;
+    }
+
+    public short getDurability() {
+        return durability;
+    }
+
+    public void setDurability(short durability) {
+        this.durability = durability;
+    }
+}

+ 2 - 2
src/main/java/com/gmail/nossr50/datatypes/treasure/Treasure.java

@@ -4,7 +4,7 @@ import org.bukkit.inventory.ItemStack;
 
 public abstract class Treasure {
     private int xp;
-    private Double dropChance;
+    private double dropChance;
     private int dropLevel;
     private ItemStack drop;
 
@@ -31,7 +31,7 @@ public abstract class Treasure {
         this.xp = xp;
     }
 
-    public Double getDropChance() {
+    public double getDropChance() {
         return dropChance;
     }
 

+ 2 - 2
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -164,7 +164,7 @@ public class BlockListener implements Listener {
          */
 
         if (Permissions.getInstance().mining(player) && BlockChecks.canBeSuperBroken(mat)) {
-            if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isMiningPick(inhand)) {
+            if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isPickaxe(inhand)) {
                 Mining.miningBlockCheck(player, block);
             }
             else if (!Config.getInstance().getMiningRequiresTool()) {
@@ -279,7 +279,7 @@ public class BlockListener implements Listener {
         }
         else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
             if(!player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {  
-                if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isMiningPick(inhand)) {
+                if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isPickaxe(inhand)) {
                     event.setInstaBreak(true);
                     Mining.SuperBreakerBlockCheck(player, block);
                 }

+ 64 - 6
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -56,6 +56,7 @@ public class mcMMO extends JavaPlugin {
     public static String flatFileDirectory;
     public static String usersFile;
     public static String leaderboardDirectory;
+    public static String modDirectory;
 
     /**
      * Things to be run when the plugin is enabled.
@@ -67,6 +68,7 @@ public class mcMMO extends JavaPlugin {
         mainDirectory = getDataFolder().getPath() + File.separator;
         flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
         leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator;
+        modDirectory = mainDirectory + "ModConfigs" + File.separator;
         usersFile = flatFileDirectory + "mcmmo.users";
 
         if (!Config.getInstance().getUseMySQL()) {
@@ -79,11 +81,12 @@ public class mcMMO extends JavaPlugin {
         pm.registerEvents(playerListener, this);
         pm.registerEvents(blockListener, this);
         pm.registerEvents(entityListener, this);
+
         if (Config.getInstance().getHardcoreEnabled()) {
             pm.registerEvents(hardcoreListener, this);
         }
 
-        PluginDescriptionFile pdfFile = this.getDescription();
+        PluginDescriptionFile pdfFile = getDescription();
 
         //Setup the leaderboards
         if (Config.getInstance().getUseMySQL()) {
@@ -117,7 +120,8 @@ public class mcMMO extends JavaPlugin {
             try {
                 Metrics metrics = new Metrics(this);
                 metrics.start();
-            } catch (IOException e) {
+            }
+            catch (IOException e) {
                 System.out.println("Failed to submit stats.");
             }
         }
@@ -168,12 +172,13 @@ public class mcMMO extends JavaPlugin {
             x.save();
         }
 
-        this.getServer().getScheduler().cancelTasks(this); //This removes our tasks
+        getServer().getScheduler().cancelTasks(this); //This removes our tasks
 
         //Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
         try {
             ZipLibrary.mcMMObackup();
-        } catch (IOException e) {
+        }
+        catch (IOException e) {
             getLogger().severe(e.toString());
         }
 
@@ -304,7 +309,7 @@ public class mcMMO extends JavaPlugin {
     }
 
     /*
-     * Boilerplate Custom Config Stuff
+     * Boilerplate Custom Config Stuff (Treasures)
      */
 
     private FileConfiguration treasuresConfig = null;
@@ -352,7 +357,60 @@ public class mcMMO extends JavaPlugin {
             treasuresConfig.save(treasuresConfigFile);
         }
         catch (IOException ex) {
-            this.getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString());
+            getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString());
+        }
+    }
+
+    /*
+     * Boilerplate Custom Config Stuff (Tools)
+     */
+
+    private FileConfiguration toolsConfig = null;
+    private File toolsConfigFile = null;
+
+    /**
+     * Reload the Tools.yml file.
+     */
+    public void reloadToolsConfig() {
+        if (toolsConfigFile == null) {
+            toolsConfigFile = new File(modDirectory, "tools.yml");
+        }
+
+        toolsConfig = YamlConfiguration.loadConfiguration(toolsConfigFile);
+        InputStream defConfigStream = getResource("tools.yml"); // Look for defaults in the jar
+
+        if (defConfigStream != null) {
+            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
+            toolsConfig.setDefaults(defConfig);
+        }
+    }
+
+    /**
+     * Get the Tools config information.
+     *
+     * @return the configuration object for tools.yml
+     */
+    public FileConfiguration getToolsConfig() {
+        if (toolsConfig == null) {
+            reloadToolsConfig();
+        }
+
+        return toolsConfig;
+    }
+
+    /**
+     * Save the Tools config informtion.
+     */
+    public void saveToolsConfig() {
+        if (toolsConfig == null || toolsConfigFile == null) {
+            return;
+        }
+
+        try {
+            toolsConfig.save(toolsConfigFile);
+        }
+        catch (IOException ex) {
+            getLogger().severe("Could not save config to " + toolsConfigFile + ex.toString());
         }
     }
 }

+ 1 - 1
src/main/java/com/gmail/nossr50/skills/misc/Repair.java

@@ -327,7 +327,7 @@ public class Repair {
         else if (ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getType().equals(Material.SHEARS)) {
             ramt = maxDurability / 2;
         }
-        else if (ItemChecks.isAxe(is) || ItemChecks.isMiningPick(is) || ItemChecks.isStringTool(is)) {
+        else if (ItemChecks.isAxe(is) || ItemChecks.isPickaxe(is) || ItemChecks.isStringTool(is)) {
             ramt = maxDurability / 3;
         }
         else if (ItemChecks.isBoots(is)) {

+ 36 - 8
src/main/java/com/gmail/nossr50/util/ItemChecks.java

@@ -2,7 +2,11 @@ package com.gmail.nossr50.util;
 
 import org.bukkit.inventory.ItemStack;
 
+import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.config.mods.LoadCustomTools;
+
 public class ItemChecks {
+    private static Config configInstance = Config.getInstance();
 
     /**
      * Checks if the item is a sword.
@@ -20,7 +24,12 @@ public class ItemChecks {
             return true;
 
         default:
-            return false;
+            if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customSwordIDs.contains(is.getTypeId())) {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
     }
 
@@ -40,7 +49,12 @@ public class ItemChecks {
             return true;
 
         default:
-            return false;
+            if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customHoeIDs.contains(is.getTypeId())) {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
     }
 
@@ -49,7 +63,7 @@ public class ItemChecks {
      *
      * @param is Item to check
      * @return true if the item is a shovel, false otherwise
-     */
+     */ 
     public static boolean isShovel(ItemStack is) {
         switch (is.getType()) {
         case DIAMOND_SPADE:
@@ -60,7 +74,12 @@ public class ItemChecks {
             return true;
 
         default:
-            return false;
+            if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customShovelIDs.contains(is.getTypeId())) {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
     }
 
@@ -80,7 +99,12 @@ public class ItemChecks {
             return true;
 
         default:
-            return false;
+            if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customAxeIDs.contains(is.getTypeId())) {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
     }
 
@@ -90,7 +114,7 @@ public class ItemChecks {
      * @param is Item to check
      * @return true if the item is a pickaxe, false otherwise
      */
-    public static boolean isMiningPick(ItemStack is) {
+    public static boolean isPickaxe(ItemStack is) {
         switch (is.getType()) {
         case DIAMOND_PICKAXE:
         case GOLD_PICKAXE:
@@ -100,7 +124,12 @@ public class ItemChecks {
             return true;
 
         default:
-            return false;
+            if (configInstance.getToolModsEnabled() && LoadCustomTools.getInstance().customPickaxeIDs.contains(is.getTypeId())) {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
     }
 
@@ -395,4 +424,3 @@ public class ItemChecks {
         }
     }
 }
-    

+ 7 - 0
src/main/resources/config.yml

@@ -40,6 +40,13 @@ Hardcore:
     Vampirism: false
     Vampirism_Stat_Leech_Percentage: 5
 
+#
+#  Settings for SMP Mods
+###
+Mods:
+    Tool_Mods_Enabled: false
+    Block_Mods_Enabled: false
+
 #
 #  Settings for mcMMO items
 ###

+ 113 - 0
src/main/resources/tools.yml

@@ -0,0 +1,113 @@
+#
+#  Settings for Axes
+###
+Axes:
+    Axe_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Axe_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+        
+#
+#  Settings for Bows
+###
+Bows:
+    Bow_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Bow_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+
+#
+#  Settings for Hoes
+###
+Hoes:
+    Hoe_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Hoe_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+
+#
+#  Settings for Pickaxes
+###
+Pickaxes:
+    Pickaxe_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Pickaxe_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+
+#
+#  Settings for Shovels
+###
+Shovels:
+    Shovel_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Shovel_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+
+#
+#  Settings for Swords
+###
+Swords:
+    Sword_1:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999
+    Sword_2:
+        ID: 999
+        XP_Modifer: 1.0
+        Repairable: true
+        Repair_Material_ID: 99
+        Repair_Material_Data_Value: 0
+        Durability: 9999