浏览代码

Redo blocks.yml

** YOU WILL NEED TO UPDATE THIS FILE **
GJ 12 年之前
父节点
当前提交
cf90236e57

+ 45 - 41
src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java

@@ -1,9 +1,11 @@
 package com.gmail.nossr50.config.mods;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
 
+import org.bukkit.Material;
 import org.bukkit.configuration.ConfigurationSection;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.material.MaterialData;
@@ -14,17 +16,17 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
 public class CustomBlockConfig extends ConfigLoader {
     private static CustomBlockConfig instance;
 
-    public List<ItemStack> customExcavationBlocks  = new ArrayList<ItemStack>();
-    public List<ItemStack> customHerbalismBlocks   = new ArrayList<ItemStack>();
-    public List<ItemStack> customMiningBlocks      = new ArrayList<ItemStack>();
-    public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
-    public List<ItemStack> customOres              = new ArrayList<ItemStack>();
-    public List<ItemStack> customLogs              = new ArrayList<ItemStack>();
-    public List<ItemStack> customLeaves            = new ArrayList<ItemStack>();
-    public List<ItemStack> customAbilityBlocks     = new ArrayList<ItemStack>();
-    public List<ItemStack> customItems             = new ArrayList<ItemStack>();
+    public List<MaterialData> customExcavationBlocks  = new ArrayList<MaterialData>();
+    public List<MaterialData> customHerbalismBlocks   = new ArrayList<MaterialData>();
+    public List<MaterialData> customMiningBlocks      = new ArrayList<MaterialData>();
+    public List<MaterialData> customWoodcuttingBlocks = new ArrayList<MaterialData>();
+    public List<MaterialData> customOres              = new ArrayList<MaterialData>();
+    public List<MaterialData> customLogs              = new ArrayList<MaterialData>();
+    public List<MaterialData> customLeaves            = new ArrayList<MaterialData>();
+    public List<MaterialData> customAbilityBlocks     = new ArrayList<MaterialData>();
+    public List<MaterialData> customItems             = new ArrayList<MaterialData>();
 
-    public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
+    public HashMap<MaterialData, CustomBlock> customBlockMap = new HashMap<MaterialData, CustomBlock>();
 
     public CustomBlockConfig() {
         super("ModConfigs", "blocks.yml");
@@ -48,7 +50,7 @@ public class CustomBlockConfig extends ConfigLoader {
         loadBlocks("Ability_Blocks", customAbilityBlocks);
     }
 
-    private void loadBlocks(String skillType, List<ItemStack> blockList) {
+    private void loadBlocks(String skillType, List<MaterialData> blockList) {
         ConfigurationSection skillSection = config.getConfigurationSection(skillType);
 
         if (skillSection == null) {
@@ -58,63 +60,65 @@ public class CustomBlockConfig extends ConfigLoader {
         Set<String> skillConfigSet = skillSection.getKeys(false);
 
         for (String blockName : skillConfigSet) {
-            int id = config.getInt(skillType + "." + blockName + ".ID", 0);
-            byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
-            int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
-            int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
-            boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
-            int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
-            byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
-            int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
-            int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
+            String[] blockInfo = blockName.split("[|]");
 
-            CustomBlock block;
-            ItemStack itemDrop;
-            ItemStack blockItem;
+            Material blockMaterial = Material.matchMaterial(blockInfo[0]);
 
-            if (id == 0) {
-                plugin.getLogger().warning("Missing ID. This block will be skipped.");
+            if (blockMaterial == null) {
+                plugin.getLogger().warning("Invalid material name. This item will be skipped.");
                 continue;
             }
 
-            if (skillType.equals("Ability_Blocks")) {
-                blockItem = (new MaterialData(id, data)).toItemStack(1);
+            byte blockData = Byte.valueOf(blockInfo[1]);
+            MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData);
+            blockList.add(blockMaterialData);
 
-                blockList.add(blockItem);
+            if (skillType.equals("Ability_Blocks")) {
                 continue;
             }
 
-            if (dropItem && dropID == 0) {
+            customItems.add(blockMaterialData);
+
+            int xp = config.getInt(skillType + "." + blockName + ".XP_Gain");
+            int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
+
+            boolean shouldDropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item");
+            Material dropMaterial = Material.matchMaterial(config.getString(skillType + "." + blockName + ".Drop_Item_Name"));
+
+            if (shouldDropItem && dropMaterial == null) {
                 plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
-                dropItem = false;
+                shouldDropItem = false;
             }
 
-            if (dropItem) {
-                itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1);
+            ItemStack itemDrop;
+
+            if (shouldDropItem) {
+                byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value");
+                itemDrop = (new MaterialData(dropMaterial, dropData)).toItemStack(1);
             }
             else {
-                itemDrop = (new MaterialData(id, data)).toItemStack(1);
+                itemDrop = blockMaterialData.toItemStack(1);
             }
 
-            block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
-            blockItem = (new MaterialData(id, data)).toItemStack(1);
+            int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
+            int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
+
+            CustomBlock block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, blockData, blockMaterial);
 
             if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
-                customOres.add(blockItem);
+                customOres.add(blockMaterialData);
             }
             else if (skillType.equals("Woodcutting")) {
                 if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
-                    customLogs.add(blockItem);
+                    customLogs.add(blockMaterialData);
                 }
                 else {
-                    customLeaves.add(blockItem);
+                    customLeaves.add(blockMaterialData);
                     block.setXpGain(0); // Leaves don't grant XP
                 }
             }
 
-            blockList.add(blockItem);
-            customItems.add(blockItem);
-            customBlocks.add(block);
+            customBlockMap.put(blockMaterialData, block);
         }
     }
 }

+ 8 - 7
src/main/java/com/gmail/nossr50/datatypes/mods/CustomBlock.java

@@ -1,9 +1,10 @@
 package com.gmail.nossr50.datatypes.mods;
 
+import org.bukkit.Material;
 import org.bukkit.inventory.ItemStack;
 
 public class CustomBlock {
-    private int itemID;
+    private Material type;
     private byte dataValue;
     private int xpGain;
     private int tier;
@@ -11,8 +12,8 @@ public class CustomBlock {
     private int minimumDropAmount;
     private int maximumDropAmount;
 
-    public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) {
-        this.itemID = itemID;
+    public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, Material type) {
+        this.type = type;
         this.dataValue = dataValue;
         this.xpGain = xpGain;
         this.tier = tier;
@@ -21,12 +22,12 @@ public class CustomBlock {
         this.maximumDropAmount = maximumDropAmount;
     }
 
-    public int getItemID() {
-        return itemID;
+    public Material getType() {
+        return type;
     }
 
-    public void setItemID(int itemID) {
-        this.itemID = itemID;
+    public void setType(Material type) {
+        this.type = type;
     }
 
     public byte getDataValue() {

+ 18 - 139
src/main/java/com/gmail/nossr50/util/ModUtils.java

@@ -3,7 +3,6 @@ package com.gmail.nossr50.util;
 import org.bukkit.block.BlockState;
 import org.bukkit.entity.Entity;
 import org.bukkit.inventory.ItemStack;
-import org.bukkit.material.MaterialData;
 
 import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.config.mods.CustomArmorConfig;
@@ -41,19 +40,7 @@ public final class ModUtils {
      * @return the block if it exists, null otherwise
      */
     public static CustomBlock getCustomBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customItems.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return block;
-                    }
-                }
-            }
-        }
-
-        return null;
+        return CustomBlockConfig.getInstance().customBlockMap.get(blockState.getData());
     }
 
     public static CustomEntity getCustomEntity(Entity entity) {
@@ -74,22 +61,10 @@ public final class ModUtils {
      * Check if a custom block is a woodcutting block.
      *
      * @param blockState The BlockState of the block to check
-     * @return true if the block represents a log, false otherwise
+     * @return true if the block represents a custom woodcutting block, false otherwise
      */
     public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(blockState.getData());
     }
 
     /**
@@ -99,85 +74,37 @@ public final class ModUtils {
      * @return true if the block represents an ability block, false otherwise
      */
     public static boolean isCustomAbilityBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customAbilityBlocks.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customAbilityBlocks.contains(blockState.getData());
     }
 
     /**
      * Check if a custom block is a mining block.
      *
      * @param blockState The BlockState of the block to check
-     * @return true if the block is custom, false otherwise
+     * @return true if the block represents a custom mining block, false otherwise
      */
     public static boolean isCustomMiningBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customMiningBlocks.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customMiningBlocks.contains(blockState.getData());
     }
 
     /**
      * Check if a custom block is an excavation block.
      *
      * @param blockState The BlockState of the block to check
-     * @return true if the block is custom, false otherwise
+     * @return true if the block represents a custom excavation block, false otherwise
      */
     public static boolean isCustomExcavationBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customExcavationBlocks.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customExcavationBlocks.contains(blockState.getData());
     }
 
     /**
      * Check if a custom block is an herbalism block.
      *
-     * @param blockState The block to check
-     * @return true if the block is custom, false otherwise
+     * @param blockState The BlockState of the block to check
+     * @return true if the block represents a custom herbalism block, false otherwise
      */
     public static boolean isCustomHerbalismBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customHerbalismBlocks.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customHerbalismBlocks.contains(blockState.getData());
     }
 
     /**
@@ -187,19 +114,7 @@ public final class ModUtils {
      * @return true if the block represents leaves, false otherwise
      */
     public static boolean isCustomLeafBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customLeaves.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customLeaves.contains(blockState.getData());
     }
 
     /**
@@ -209,41 +124,17 @@ public final class ModUtils {
      * @return true if the block represents a log, false otherwise
      */
     public static boolean isCustomLogBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customLogs.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customLogs.contains(blockState.getData());
     }
 
     /**
      * Check if a custom block is an ore block.
      *
-     * @param blockState The block to check
+     * @param blockState The BlockState of the block to check
      * @return true if the block represents an ore, false otherwise
      */
     public static boolean isCustomOreBlock(BlockState blockState) {
-        if (customBlocksEnabled) {
-            ItemStack item = blockState.getData().toItemStack(1);
-
-            if (CustomBlockConfig.getInstance().customOres.contains(item)) {
-                for (CustomBlock block : CustomBlockConfig.getInstance().customBlocks) {
-                    if (new MaterialData(block.getItemID(), block.getDataValue()).equals(blockState.getData())) {
-                        return true;
-                    }
-                }
-            }
-        }
-
-        return false;
+        return customBlocksEnabled && CustomBlockConfig.getInstance().customOres.contains(blockState.getData());
     }
 
     /**
@@ -253,11 +144,7 @@ public final class ModUtils {
      * @return true if the item is a custom tool, false otherwise
      */
     public static boolean isCustomTool(ItemStack item) {
-        if (customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType())) {
-            return true;
-        }
-
-        return false;
+        return customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType());
     }
 
     /**
@@ -267,19 +154,11 @@ public final class ModUtils {
      * @return true if the item is custom armor, false otherwise
      */
     public static boolean isCustomArmor(ItemStack item) {
-        if (customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType())) {
-            return true;
-        }
-
-        return false;
+        return customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType());
     }
 
     public static boolean isCustomEntity(Entity entity) {
-        if (customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId())) {
-            return true;
-        }
-
-        return false;
+        return customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId());
     }
 
     /**

+ 18 - 38
src/main/resources/blocks.yml

@@ -2,21 +2,17 @@
 #  Settings for Custom Excavation Blocks
 ###
 Excavation:
-    Block_1:
-        ID: 999
-        Data_Value: 0
+    Block_1|0:
         XP_Gain: 99
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
-    Block_2:
-        ID: 999
-        Data_Value: 0
+    Block_2|0:
         XP_Gain: 99
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
@@ -25,21 +21,17 @@ Excavation:
 #  Settings for Custom Herbalism Blocks
 ###
 Herbalism:
-    Block_1:
-        ID: 999
-        Data_Value: 0
+    Block_1|0:
         XP_Gain: 99
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
-    Block_2:
-        ID: 999
-        Data_Value: 0
+    Block_2|0:
         XP_Gain: 99
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
@@ -48,25 +40,21 @@ Herbalism:
 #  Settings for Custom Mining Blocks
 ###
 Mining:
-    Block_1:
-        ID: 999
-        Data_Value: 0
+    Block_1|0:
         XP_Gain: 99
         Is_Ore: true
         Tier: 1
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
-    Block_2:
-        ID: 999
-        Data_Value: 0
+    Block_2|0:
         XP_Gain: 99
         Is_Ore: true
         Tier: 1
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
@@ -75,23 +63,19 @@ Mining:
 #  Settings for Custom Woodcutting Blocks
 ###
 Woodcutting:
-    Block_1:
-        ID: 999
-        Data_Value: 0
+    Block_1|0:
         XP_Gain: 99
         Is_Log: true
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
-    Block_2:
-        ID: 999
-        Data_Value: 0
+    Block_2|0:
         XP_Gain: 99
         Is_Log: true
         Drop_Item: false
-        Drop_Item_ID: 999
+        Drop_Item_Name: BLOCK_DROP
         Drop_Item_Data_Value: 0
         Min_Drop_Item_Amount: 1
         Max_Drop_Item_Amount: 1
@@ -101,9 +85,5 @@ Woodcutting:
 #  (These blocks don't trigger abilities)
 ###
 Ability_Blocks:
-    Block_1:
-        ID: 999
-        Data_Value: 0
-    Block_2:
-        ID: 999
-        Data_Value: 0        
+    Block_1|0:
+    Block_2|0: