mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
Fixed item and price formatting
This commit is contained in:
parent
1bf4651efa
commit
361724f2be
@ -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
|
||||
@ -213,7 +213,7 @@ public class MaterialUtil {
|
||||
|
||||
data = data.substring(1);
|
||||
|
||||
return NumberUtil.isInteger(data) ? Short.valueOf(data) : 0;
|
||||
return NumberUtil.isShort(data) ? Short.valueOf(data) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,28 +207,37 @@ 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, data = "";
|
||||
String[] split = line.split(":|-", 2);
|
||||
StringBuilder formatted = new StringBuilder(15);
|
||||
String itemName = MaterialUtil.getName(itemStack, false);
|
||||
|
||||
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()) && MaterialUtil.equals(MaterialUtil.getItem(longItemName + data), item)) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user