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
This commit is contained in:
xsmeths 2024-04-15 06:05:08 +01:00
parent c76cbe8de8
commit 70cc75b27f

View File

@ -29,7 +29,7 @@ public class VoucherMenu extends IconInv {
if (getInventory().firstEmpty() != -1) { if (getInventory().firstEmpty() != -1) {
ItemStack voucherItemStack = voucher.toItemStack(); ItemStack voucherItemStack = voucher.toItemStack();
ItemMeta voucherItemMeta = voucherItemStack.getItemMeta(); ItemMeta voucherItemMeta = voucherItemStack.getItemMeta();
voucherItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', voucher.getName())); voucherItemMeta.setDisplayName(TextUtils.formatText(voucher.getName()));
voucherItemStack.setItemMeta(voucherItemMeta); voucherItemStack.setItemMeta(voucherItemMeta);
addIcon(getInventory().firstEmpty(), voucherItemStack, event -> new OptionMenu(instance, voucher).open(event.getPlayer())); 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.setTitle("Insert id");
gui.setAction(aEvent -> { gui.setAction(aEvent -> {
final String msg = gui.getInputText().trim(); 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) { if (instance.getVoucherManager().getVoucher(msg) != null) {
event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg)); event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg));
new VoucherMenu(instance).open(event.getPlayer()); new VoucherMenu(instance).open(event.getPlayer());
return; return;
} }
if (!msg.isEmpty()) {
Voucher voucher = new Voucher(msg, instance); Voucher voucher = new Voucher(msg, instance);
voucher.setMaterial(PAPER); voucher.setMaterial(PAPER);
voucher.setName("&f" + msg); voucher.setName("&f" + msg);
voucher.setTexture(""); voucher.setTexture("");
instance.getVoucherManager().addVoucher(voucher);
instance.getVoucherManager().addVoucher(voucher); event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully created voucher with id &r" + msg + "&7."));
event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully created voucher with id &r" + msg + "&7.")); }
new VoucherMenu(instance).open(event.getPlayer()); new VoucherMenu(instance).open(event.getPlayer());
}); });
instance.getGuiManager().showGUI(event.getPlayer(), gui); 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())); new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7)).name(ChatColor.RESET.toString()).build()));
} }
} }