From 70cc75b27f6c3839eeea5c4a376f8f594ae3c871 Mon Sep 17 00:00:00 2001 From: xsmeths Date: Mon, 15 Apr 2024 06:05:08 +0100 Subject: [PATCH] more menu fixes stop people making vouchers with no id make it so the anvil gui logic updates your exp back to what it was after using it TextUtils for formatting --- .../epicvouchers/menus/VoucherMenu.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/craftaro/epicvouchers/menus/VoucherMenu.java b/src/main/java/com/craftaro/epicvouchers/menus/VoucherMenu.java index 25ef9d6..c2ff76d 100644 --- a/src/main/java/com/craftaro/epicvouchers/menus/VoucherMenu.java +++ b/src/main/java/com/craftaro/epicvouchers/menus/VoucherMenu.java @@ -29,7 +29,7 @@ public class VoucherMenu extends IconInv { if (getInventory().firstEmpty() != -1) { ItemStack voucherItemStack = voucher.toItemStack(); ItemMeta voucherItemMeta = voucherItemStack.getItemMeta(); - voucherItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', voucher.getName())); + voucherItemMeta.setDisplayName(TextUtils.formatText(voucher.getName())); voucherItemStack.setItemMeta(voucherItemMeta); addIcon(getInventory().firstEmpty(), voucherItemStack, event -> new OptionMenu(instance, voucher).open(event.getPlayer())); } @@ -42,19 +42,23 @@ public class VoucherMenu extends IconInv { gui.setTitle("Insert id"); gui.setAction(aEvent -> { final String msg = gui.getInputText().trim(); + aEvent.player.setLevel(aEvent.player.getLevel()+1); + aEvent.player.updateInventory(); + aEvent.player.setLevel(aEvent.player.getLevel()-1); + aEvent.player.updateInventory(); if (instance.getVoucherManager().getVoucher(msg) != null) { event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg)); new VoucherMenu(instance).open(event.getPlayer()); return; } - - Voucher voucher = new Voucher(msg, instance); - voucher.setMaterial(PAPER); - voucher.setName("&f" + msg); - voucher.setTexture(""); - - instance.getVoucherManager().addVoucher(voucher); - event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully created voucher with id &r" + msg + "&7.")); + if (!msg.isEmpty()) { + Voucher voucher = new Voucher(msg, instance); + voucher.setMaterial(PAPER); + voucher.setName("&f" + msg); + voucher.setTexture(""); + instance.getVoucherManager().addVoucher(voucher); + event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully created voucher with id &r" + msg + "&7.")); + } new VoucherMenu(instance).open(event.getPlayer()); }); instance.getGuiManager().showGUI(event.getPlayer(), gui); @@ -65,3 +69,4 @@ public class VoucherMenu extends IconInv { new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7)).name(ChatColor.RESET.toString()).build())); } } +