From 505dfb3449e71f3c309ea2ff49a18434bbd74ac8 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Tue, 20 Dec 2011 21:39:45 +0100 Subject: [PATCH] - Fixed potion stacking and adding items to stacks with a different durability - Modified /iteminfo a bit - Added a message to the DBpage generator - Added more functions to word datavalue - Modified the SignChange fourth line formatting --- com/Acrobot/ChestShop/Commands/ItemInfo.java | 5 ++- com/Acrobot/ChestShop/DB/Generator.java | 4 ++ com/Acrobot/ChestShop/Items/DataValue.java | 38 ++++++++++++++++++- com/Acrobot/ChestShop/Items/Items.java | 10 +++++ .../ChestShop/Listeners/signChange.java | 15 +++++--- com/Acrobot/ChestShop/Utils/uInventory.java | 4 +- plugin.yml | 2 +- 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/com/Acrobot/ChestShop/Commands/ItemInfo.java b/com/Acrobot/ChestShop/Commands/ItemInfo.java index be7b81c..c75f3a8 100644 --- a/com/Acrobot/ChestShop/Commands/ItemInfo.java +++ b/com/Acrobot/ChestShop/Commands/ItemInfo.java @@ -36,8 +36,9 @@ public class ItemInfo implements CommandExecutor { String enchantment = (ench != null ? ChatColor.DARK_AQUA + "-" + ench : ""); sender.sendMessage(Config.getLocal(Language.iteminfo)); - sender.sendMessage(ChatColor.GRAY + uSign.capitalizeFirst(item.getType().name()) - + ChatColor.WHITE + " " + item.getTypeId() + durability + enchantment + ChatColor.WHITE); + String itemname = Items.getName(item); + sender.sendMessage(ChatColor.GRAY + itemname + ChatColor.WHITE + " " + + item.getTypeId() + durability + enchantment + ChatColor.WHITE); Map map = item.getEnchantments(); for (Map.Entry e : map.entrySet()) diff --git a/com/Acrobot/ChestShop/DB/Generator.java b/com/Acrobot/ChestShop/DB/Generator.java index 23778b3..af24080 100644 --- a/com/Acrobot/ChestShop/DB/Generator.java +++ b/com/Acrobot/ChestShop/DB/Generator.java @@ -112,6 +112,9 @@ public class Generator implements Runnable { private static void generateStats() { try { + File f = new File(filePath).getParentFile(); + if (!f.exists()) f.mkdir(); + fileStart(); buf = new BufferedWriter(new FileWriter(filePath, true)); @@ -124,6 +127,7 @@ public class Generator implements Runnable { fileEnd(); } catch (Exception e) { Logging.log("Couldn't generate statistics page!"); + e.printStackTrace(); } } } diff --git a/com/Acrobot/ChestShop/Items/DataValue.java b/com/Acrobot/ChestShop/Items/DataValue.java index ac2ceb1..63c9aa5 100644 --- a/com/Acrobot/ChestShop/Items/DataValue.java +++ b/com/Acrobot/ChestShop/Items/DataValue.java @@ -4,6 +4,7 @@ import org.bukkit.CoalType; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.TreeSpecies; +import org.bukkit.inventory.ItemStack; import org.bukkit.material.*; /** @@ -27,9 +28,11 @@ public class DataValue { materialData = new Step(Items.getMaterial(type)); break; case WOOL: - case INK_SACK: materialData = new Wool(DyeColor.valueOf(type)); break; + case INK_SACK: + materialData = new Wool(15 - DyeColor.valueOf(type).getData()); + break; case COAL: materialData = new Coal(CoalType.valueOf(type)); break; @@ -38,4 +41,37 @@ public class DataValue { return (materialData == null ? 0 : materialData.getData()); } + + public static String getName(ItemStack is){ + short dur = is.getDurability(); + if (dur == 0) return null; + + Material material = is.getType(); + + String name = null; + + try { + switch (material) { + case SAPLING: + case LOG: + name = TreeSpecies.getByData((byte) dur).name(); + break; + case STEP: + case DOUBLE_STEP: + name = new Step(Material.getMaterial(dur)).getMaterial().name(); + break; + case WOOL: + name = DyeColor.getByData((byte) dur).name(); + break; + case INK_SACK: + name = DyeColor.getByData((byte) (15 - dur)).name(); + break; + case COAL: + name = CoalType.getByData((byte) dur).name(); + break; + } + } catch (Exception e) { return null; } + + return name; + } } diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index ff767b4..022f18b 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Items; import com.Acrobot.ChestShop.Utils.uEnchantment; import com.Acrobot.ChestShop.Utils.uNumber; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -31,6 +32,15 @@ public class Items { } return finalMaterial; } + + public static String getName(ItemStack is){ + return getName(is, true); + } + + public static String getName(ItemStack is, boolean showData){ + String name = DataValue.getName(is); + return uSign.capitalizeFirst((name != null && showData ? name + '_' : "") + is.getType()); + } public static ItemStack getItemStack(String itemName) { ItemStack toReturn = getFromOddItem(itemName); diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 68cca94..4f290a0 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -70,7 +70,7 @@ public class signChange extends BlockListener { return; } event.setLine(2, thirdLine); - event.setLine(3, formatFourthLine(line[3], mat)); + event.setLine(3, formatFourthLine(line[3], stock)); Chest chest = uBlock.findChest(signBlock); @@ -148,15 +148,18 @@ public class signChange extends BlockListener { return (thirdLine.length() > 15 ? null : thirdLine); } - private static String formatFourthLine(String fourthLine, Material material) { + private static String formatFourthLine(String fourthLine, ItemStack is) { int index = (fourthLine.indexOf(':') != -1 ? fourthLine.indexOf(':') : 9999); if (fourthLine.indexOf('-') < index && fourthLine.indexOf('-') != -1) index = fourthLine.indexOf('-'); StringBuilder toReturn = new StringBuilder(3); - String matName = uSign.capitalizeFirst(material.name()); - if (index != 9999 && matName.length() > (15 - (fourthLine.length() - index))) matName = matName.substring(0, 15 - (fourthLine.length() - index)); - if (Items.getMaterial(matName) == material) toReturn.append(matName); - else toReturn.append(material.getId()); + String matName = fourthLine.split(":|-")[0]; + matName = matName.trim(); + if (uNumber.isInteger(matName)) matName = Items.getName(is, false); + int iPos = 15 - (fourthLine.length() - index); + if (index != 9999 && matName.length() > iPos) matName = matName.substring(0, iPos); + if (Items.getItemStack(matName).getType() == is.getType()) toReturn.append(matName); + else toReturn.append(is.getTypeId()); if (index != -1 && index != 9999) toReturn.append(fourthLine.substring(index)); return toReturn.toString(); diff --git a/com/Acrobot/ChestShop/Utils/uInventory.java b/com/Acrobot/ChestShop/Utils/uInventory.java index b296ed3..c5aa2e1 100644 --- a/com/Acrobot/ChestShop/Utils/uInventory.java +++ b/com/Acrobot/ChestShop/Utils/uInventory.java @@ -57,7 +57,7 @@ public class uInventory { } private static int addManually(Inventory inv, ItemStack item, int amount) { - return addManually(inv, item, amount, item.getType().getMaxStackSize()); + return addManually(inv, item, amount, (item.getType() != Material.POTION ? item.getType().getMaxStackSize() : 1)); //TODO Change it when it's repaired in Bukkit } public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) { @@ -76,7 +76,7 @@ public class uInventory { dupe.addEnchantments(item.getEnchantments()); amount -= dupe.getAmount(); inv.setItem(slot, dupe); - } else if (equals(item, curItem, item.getDurability()) && curItem.getAmount() != max) { + } else if (equals(item, curItem, curItem.getDurability()) && curItem.getAmount() != max) { int cA = curItem.getAmount(); int amountAdded = amount > max - cA ? max - cA : amount; dupe.setAmount(cA + amountAdded); diff --git a/plugin.yml b/plugin.yml index eb451db..dc6bf63 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.30 +version: 3.31 author: Acrobot