From 04f02ca7f4231294c7ccade82da8115e376b9f86 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sat, 5 Apr 2014 18:31:01 +0200 Subject: [PATCH] Support `MATERIAL|data` format in treasures.yml Allows users to use the same material type for multiple treasures in treasures.yml Fixes #1965 --- Changelog.txt | 1 + .../config/treasure/TreasureConfig.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index ef3abcf6c..696b47004 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -8,6 +8,7 @@ Key: - Removal Version 1.5.01-dev + + Added support for `MATERIAL|data` format in treasures.yml = Fixed bug where the Updater was running on the main thread. ! Vanished players no longer get hit by AoE effects diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java index 8575a1591..acc42161e 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java @@ -158,26 +158,29 @@ public class TreasureConfig extends ConfigLoader { // Validate all the things! List reason = new ArrayList(); + String[] treasureInfo = treasureName.split("[|]"); + String materialName = treasureInfo[0]; + /* * Material, Amount, and Data */ Material material; - if (treasureName.contains("POTION")) { + if (materialName.contains("POTION")) { material = Material.POTION; } - else if (treasureName.contains("INK_SACK")) { + else if (materialName.contains("INK_SACK")) { material = Material.INK_SACK; } else { - material = Material.matchMaterial(treasureName); + material = Material.matchMaterial(materialName); } int amount = config.getInt(type + "." + treasureName + ".Amount"); - int data = config.getInt(type + "." + treasureName + ".Data"); + short data = (treasureInfo.length == 2) ? Byte.valueOf(treasureInfo[1]) : (short) config.getInt(type + "." + treasureName + ".Data"); if (material == null) { - reason.add("Invalid material: " + treasureName); + reason.add("Invalid material: " + materialName); } if (amount <= 0) { @@ -226,8 +229,8 @@ public class TreasureConfig extends ConfigLoader { */ ItemStack item = null; - if (treasureName.contains("POTION")) { - String potionType = treasureName.substring(7); + if (materialName.contains("POTION")) { + String potionType = materialName.substring(7); try { item = new Potion(PotionType.valueOf(potionType.toUpperCase().trim())).toItemStack(amount); @@ -236,8 +239,8 @@ public class TreasureConfig extends ConfigLoader { reason.add("Invalid Potion_Type: " + potionType); } } - else if (treasureName.contains("INK_SACK")) { - String color = treasureName.substring(9); + else if (materialName.contains("INK_SACK")) { + String color = materialName.substring(9); try { Dye dye = new Dye(); @@ -250,7 +253,7 @@ public class TreasureConfig extends ConfigLoader { } } else if (material != null) { - item = new ItemStack(material, amount, (short) data); + item = new ItemStack(material, amount, data); if (config.contains(type + "." + treasureName + ".Custom_Name")) { ItemMeta itemMeta = item.getItemMeta();