Auto-correct item code on sign.

This also makes it possible to input IDs on the sign that are longer than the max sign letters that the plugin uses as that just gets auto corrected back down to the correct amount.
This commit is contained in:
Phoenix616 2018-09-09 13:26:08 +01:00
parent afab90d021
commit 2459a406fe
1 changed files with 6 additions and 7 deletions

View File

@ -33,22 +33,17 @@ public class ItemChecker implements Listener {
if (item == null) {
if (Properties.ALLOW_AUTO_ITEM_FILL && itemCode.equals(AUTOFILL_CODE)) {
boolean foundItem = false;
Chest chest = uBlock.findConnectedChest(event.getSign());
if (chest != null) {
for (ItemStack stack : chest.getInventory().getContents()) {
if (!MaterialUtil.isEmpty(stack)) {
itemCode = MaterialUtil.getSignName(stack);
event.setSignLine(ITEM_LINE, itemCode);
foundItem = true;
item = stack;
break;
}
}
}
if (!foundItem) {
if (item == null) {
event.setSignLine(ITEM_LINE, ChatColor.BOLD + ChestShopSign.AUTOFILL_CODE);
event.setOutcome(ITEM_AUTOFILL);
event.getPlayer().sendMessage(Messages.prefix(Messages.CLICK_TO_AUTOFILL_ITEM));
@ -60,10 +55,14 @@ public class ItemChecker implements Listener {
}
}
itemCode = MaterialUtil.getSignName(item);
if (itemCode.length() > MAXIMUM_SIGN_LETTERS) {
event.setOutcome(INVALID_ITEM);
return;
}
event.setSignLine(ITEM_LINE, itemCode);
}
private static boolean isSameItem(String newCode, ItemStack item) {