diff --git a/com/Acrobot/Breeze/Utils/MaterialUtil.java b/com/Acrobot/Breeze/Utils/MaterialUtil.java index 6f0a7bc..0c22c96 100644 --- a/com/Acrobot/Breeze/Utils/MaterialUtil.java +++ b/com/Acrobot/Breeze/Utils/MaterialUtil.java @@ -18,8 +18,8 @@ import java.util.regex.Pattern; * @author Acrobot */ public class MaterialUtil { - private static final Pattern DURABILITY = Pattern.compile(":(\\d)*"); - private static final Pattern ENCHANTMENT = Pattern.compile("-([0-9a-zA-Z])*"); + public static final Pattern DURABILITY = Pattern.compile(":(\\d)*"); + public static final Pattern ENCHANTMENT = Pattern.compile("-([0-9a-zA-Z])*"); /** * Checks if the itemStack is empty or null diff --git a/com/Acrobot/ChestShop/Listeners/Block/SignChange.java b/com/Acrobot/ChestShop/Listeners/Block/SignChange.java index 1af453c..721571d 100644 --- a/com/Acrobot/ChestShop/Listeners/Block/SignChange.java +++ b/com/Acrobot/ChestShop/Listeners/Block/SignChange.java @@ -207,28 +207,38 @@ public class SignChange implements Listener { return (line.length() > 15 ? null : line); } - private static String formatItemLine(String line, ItemStack itemStack) { + private static String formatItemLine(String line, ItemStack item) { + String formatted = ""; String[] split = line.split(":|-", 2); - StringBuilder formatted = new StringBuilder(15); - String itemName = MaterialUtil.getName(itemStack, false); + String data = ""; - short dataLength = (short) (line.length() - split[0].length()); - - if (itemName.length() > (15 - dataLength)) { - itemName = itemName.substring(0, 15 - dataLength); + if (MaterialUtil.ENCHANTMENT.matcher(line).matches()) { + data = '-' + MaterialUtil.ENCHANTMENT.matcher(line).group(); } - if (MaterialUtil.getItem(itemName).getType() != itemStack.getType()) { - itemName = String.valueOf(itemStack.getTypeId()); + String longItemName = MaterialUtil.getName(item, true); + + if (longItemName.length() < (15 - data.length())) { + return StringUtil.capitalizeFirstLetter(longItemName + data); + } + + formatted = MaterialUtil.getName(item, false); + data = (split.length == 2 ? split[1] : ""); + + if (formatted.length() > (15 - data.length())) { + formatted = formatted.substring(0, (15 - data.length())); + } + + if (MaterialUtil.getItem(formatted).getType() != item.getType()) { + formatted = String.valueOf(item.getTypeId()); } - formatted.append(itemName); if (split.length == 2) { int dataValuePos = line.indexOf(split[1], split[0].length()); - formatted.append(line.charAt(dataValuePos - 1)).append(split[1]); + formatted += line.charAt(dataValuePos - 1) + split[1]; } - return StringUtil.capitalizeFirstLetter(formatted.toString()); + return StringUtil.capitalizeFirstLetter(formatted); } private static boolean playerCanUseName(Player player, String name) { diff --git a/com/Acrobot/ChestShop/Listeners/PreTransaction/PriceValidator.java b/com/Acrobot/ChestShop/Listeners/PreTransaction/PriceValidator.java index 702aa9e..42a7f1b 100644 --- a/com/Acrobot/ChestShop/Listeners/PreTransaction/PriceValidator.java +++ b/com/Acrobot/ChestShop/Listeners/PreTransaction/PriceValidator.java @@ -1,11 +1,12 @@ package com.Acrobot.ChestShop.Listeners.PreTransaction; -import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import static com.Acrobot.Breeze.Utils.PriceUtil.NO_PRICE; import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.SHOP_DOES_NOT_BUY_THIS_ITEM; import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.SHOP_DOES_NOT_SELL_THIS_ITEM; import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY; @@ -14,7 +15,7 @@ import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY; * @author Acrobot */ public class PriceValidator implements Listener { - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public static void onPriceCheck(PreTransactionEvent event) { if (event.isCancelled()) { return; @@ -23,7 +24,7 @@ public class PriceValidator implements Listener { TransactionEvent.TransactionType transactionType = event.getTransactionType(); double price = event.getPrice(); - if (price == PriceUtil.NO_PRICE) { + if (price == NO_PRICE) { if (transactionType == BUY) { event.setCancelled(SHOP_DOES_NOT_BUY_THIS_ITEM); } else { diff --git a/plugin.yml b/plugin.yml index 586f701..c4d7652 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.50t0022 +version: 3.50t0023 #for CButD dev-url: http://dev.bukkit.org/server-mods/chestshop/