mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-25 01:27:32 +01:00
Fixed item name formatting
And fixed a strange bug involving priorities
This commit is contained in:
parent
1bf4651efa
commit
49165e5965
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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/
|
||||
|
Loading…
Reference in New Issue
Block a user