Support MATERIAL|data format in treasures.yml

Allows users to use the same material type for multiple treasures in
treasures.yml

Fixes #1965
This commit is contained in:
TfT_02 2014-04-05 18:31:01 +02:00
parent f9dfec5bd0
commit 10dd7619bf
2 changed files with 14 additions and 10 deletions

View File

@ -8,6 +8,7 @@ Key:
- Removal - Removal
Version 1.5.01-dev 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. = Fixed bug where the Updater was running on the main thread.
! Vanished players no longer get hit by AoE effects ! Vanished players no longer get hit by AoE effects

View File

@ -160,26 +160,29 @@ public class TreasureConfig extends ConfigLoader {
// Validate all the things! // Validate all the things!
List<String> reason = new ArrayList<String>(); List<String> reason = new ArrayList<String>();
String[] treasureInfo = treasureName.split("[|]");
String materialName = treasureInfo[0];
/* /*
* Material, Amount, and Data * Material, Amount, and Data
*/ */
Material material; Material material;
if (treasureName.contains("POTION")) { if (materialName.contains("POTION")) {
material = Material.POTION; material = Material.POTION;
} }
else if (treasureName.contains("INK_SACK")) { else if (materialName.contains("INK_SACK")) {
material = Material.INK_SACK; material = Material.INK_SACK;
} }
else { else {
material = Material.matchMaterial(treasureName); material = Material.matchMaterial(materialName);
} }
int amount = config.getInt(type + "." + treasureName + ".Amount"); 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) { if (material == null) {
reason.add("Invalid material: " + treasureName); reason.add("Invalid material: " + materialName);
} }
if (amount <= 0) { if (amount <= 0) {
@ -228,8 +231,8 @@ public class TreasureConfig extends ConfigLoader {
*/ */
ItemStack item = null; ItemStack item = null;
if (treasureName.contains("POTION")) { if (materialName.contains("POTION")) {
String potionType = treasureName.substring(7); String potionType = materialName.substring(7);
try { try {
item = new Potion(PotionType.valueOf(potionType.toUpperCase().trim())).toItemStack(amount); item = new Potion(PotionType.valueOf(potionType.toUpperCase().trim())).toItemStack(amount);
@ -238,8 +241,8 @@ public class TreasureConfig extends ConfigLoader {
reason.add("Invalid Potion_Type: " + potionType); reason.add("Invalid Potion_Type: " + potionType);
} }
} }
else if (treasureName.contains("INK_SACK")) { else if (materialName.contains("INK_SACK")) {
String color = treasureName.substring(9); String color = materialName.substring(9);
try { try {
Dye dye = new Dye(); Dye dye = new Dye();
@ -252,7 +255,7 @@ public class TreasureConfig extends ConfigLoader {
} }
} }
else if (material != null) { else if (material != null) {
item = new ItemStack(material, amount, (short) data); item = new ItemStack(material, amount, data);
if (config.contains(type + "." + treasureName + ".Custom_Name")) { if (config.contains(type + "." + treasureName + ".Custom_Name")) {
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();