diff --git a/src/main/java/io/github/townyadvanced/townymenus/menu/NationMenu.java b/src/main/java/io/github/townyadvanced/townymenus/menu/NationMenu.java index 0903791..819a33d 100644 --- a/src/main/java/io/github/townyadvanced/townymenus/menu/NationMenu.java +++ b/src/main/java/io/github/townyadvanced/townymenus/menu/NationMenu.java @@ -45,22 +45,19 @@ public static MenuInventory createNationMenu(@NotNull Player player) { .title(Component.text("Nation Menu")) .rows(6) .addItem(MenuHelper.backButton().build()) - .addItem(MenuItem.builder(Material.WRITABLE_BOOK) - .name(Component.text("Transaction History", NamedTextColor.GREEN)) - .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(4))) + .addItem(MenuItem.builder(Material.EMERALD_BLOCK) + .name(Component.text("Nation Bank", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(3))) .lore(() -> { if (nation == null) return Component.text("You are not part of a nation.", NamedTextColor.GRAY); - else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode())) - return Component.text("You do not have permission to view the nations's transaction history.", NamedTextColor.GRAY); else - return Component.text("Click to view the nations's transaction history.", NamedTextColor.GRAY); + return Component.text("Click to view the nation bank menu.", NamedTextColor.GRAY); }) - .action(nation == null || !player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()) ? ClickAction.NONE : - ClickAction.openInventory(() -> TownMenu.createBankHistoryMenu(nation))) + .action(nation == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatNationBankMenu(player))) .build()) .addItem(MenuItem.builder(Material.RED_BED) - .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2))) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(1))) .name(Component.text("Nation Spawn", NamedTextColor.GREEN)) .lore(() -> { if (nation == null) @@ -85,7 +82,7 @@ else if (!player.hasPermission("towny.nation.spawn.nation")) .build()) .addItem(MenuItem.builder(Material.LEVER) .name(Component.text("Nation Toggle", NamedTextColor.GREEN)) - .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2))) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(1))) .lore(() -> { if (nation == null) return Component.text("You must be in a nation in order to view the toggle menu.", NamedTextColor.GRAY); @@ -96,13 +93,13 @@ else if (!player.hasPermission("towny.nation.spawn.nation")) .build()) .addItem(MenuItem.builder(Material.GRASS_BLOCK) .name(Component.text("Nation Set", NamedTextColor.GREEN)) - .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromRight(2))) + .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromRight(3))) .lore(Component.text("Click to open the nation set menu.", NamedTextColor.GRAY)) .action(ClickAction.openInventory(() -> formatNationSetMenu(player))) .build()) .addItem(MenuItem.builder(Material.ENDER_EYE) .name(Component.text("Online in Nation", NamedTextColor.GREEN)) - .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromLeft(2))) + .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromLeft(1))) .lore(() -> { if (nation == null) return Component.text("You are not part of a nation.", NamedTextColor.GRAY); @@ -129,6 +126,7 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_ONLINE.getNo .build()) .addItem(MenuItem.builder(Material.PLAYER_HEAD) .name(Component.text("Nation Resident Overview", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromRight(1))) .lore(() -> { if (nation == null) return Component.text("You are not part of a nation.", NamedTextColor.GRAY); @@ -137,19 +135,6 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_ONLINE.getNo }) .action(nation == null ? ClickAction.NONE : ClickAction.openInventory(() -> createResidentOverview(player))) .build()) - .addItem(MenuItem.builder(Material.EMERALD_BLOCK) - .name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN)) - .slot(1) - .lore(() -> { - if (nation == null) - return Component.text("You are not part of a nation.", NamedTextColor.GRAY); - else if (!TownyEconomyHandler.isActive()) - return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY); - else - return Component.text("Click to deposit to or withdraw from the nation bank.", NamedTextColor.GRAY); - }) - .action(nation == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, nation))) - .build()) .build(); } @@ -460,4 +445,48 @@ public static MenuInventory formatRankManagementMenu(Player player, Nation natio return paginator.build(); } + + public static MenuInventory formatNationBankMenu(final Player player) { + final Nation nation = TownyAPI.getInstance().getNation(player); + + final MenuInventory.Builder builder = MenuInventory.builder() + .title(Component.text("Nation Bank")) + .rows(3) + .addItem(MenuHelper.backButton().build()) + .addItem(MenuItem.builder(Material.EMERALD_BLOCK) + .name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2))) + .lore(() -> { + if (nation == null) + return Component.text("You are not part of a nation.", NamedTextColor.GRAY); + else if (!TownyEconomyHandler.isActive()) + return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY); + else + return Component.text("Click to deposit to or withdraw from the nation bank.", NamedTextColor.GRAY); + }) + .action(nation == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, nation))) + .build()) + .addItem(MenuItem.builder(Material.WRITABLE_BOOK) + .name(Component.text("Transaction History", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2))) + .lore(() -> { + if (nation == null) + return Component.text("You are not part of a nation.", NamedTextColor.GRAY); + else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode())) + return Component.text("You do not have permission to view the nations's transaction history.", NamedTextColor.GRAY); + else + return Component.text("Click to view the nations's transaction history.", NamedTextColor.GRAY); + }) + .action(nation == null || !player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()) ? ClickAction.NONE : + ClickAction.openInventory(() -> TownMenu.createBankHistoryMenu(nation))) + .build()); + + if (nation != null && TownyEconomyHandler.isActive()) { + builder.addItem(TownMenu.formatBankStatus(player, nation.getAccount(), false) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(0), HorizontalAnchor.fromLeft(4))) + .build()); + } + + return builder.build(); + } } diff --git a/src/main/java/io/github/townyadvanced/townymenus/menu/TownMenu.java b/src/main/java/io/github/townyadvanced/townymenus/menu/TownMenu.java index 1c0bc3e..e49671e 100644 --- a/src/main/java/io/github/townyadvanced/townymenus/menu/TownMenu.java +++ b/src/main/java/io/github/townyadvanced/townymenus/menu/TownMenu.java @@ -22,6 +22,7 @@ import com.palmergames.bukkit.towny.object.TownBlockTypeHandler; import com.palmergames.bukkit.towny.object.TransactionType; import com.palmergames.bukkit.towny.object.Translatable; +import com.palmergames.bukkit.towny.object.economy.Account; import com.palmergames.bukkit.towny.object.economy.BankTransaction; import com.palmergames.bukkit.towny.permissions.PermissionNodes; import com.palmergames.bukkit.towny.permissions.TownyPerms; @@ -60,19 +61,16 @@ public static MenuInventory createTownMenu(@NotNull Player player) { .addItem(formatTownInfo(town) .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(4))) .build()) - .addItem(MenuItem.builder(Material.WRITABLE_BOOK) - .name(Component.text("Transaction History", NamedTextColor.GREEN)) + .addItem(MenuItem.builder(Material.EMERALD_BLOCK) + .name(Component.text("Town Bank", NamedTextColor.GREEN)) .slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(3))) .lore(() -> { if (town == null) return Component.text("You are not part of a town.", NamedTextColor.GRAY); - else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode())) - return Component.text("You do not have permission to view the town's transaction history.", NamedTextColor.GRAY); else - return Component.text("Click to view the town's transaction history.", NamedTextColor.GRAY); + return Component.text("Click to view the town bank menu.", NamedTextColor.GRAY); }) - .action(town != null && player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode()) - ? ClickAction.openInventory(() -> createBankHistoryMenu(town)) : ClickAction.NONE) + .action(town == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatTownBankMenu(player))) .build()) .addItem(MenuItem.builder(Material.GRASS_BLOCK) .name(Component.text("Town Plots", NamedTextColor.GREEN)) @@ -201,19 +199,6 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_ONLINE.getNode }) .action(town == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatTownManagementMenu(player))) .build()) - .addItem(MenuItem.builder(Material.EMERALD_BLOCK) - .name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN)) - .slot(0) - .lore(() -> { - if (town == null) - return Component.text("You are not part of a town.", NamedTextColor.GRAY); - else if (!TownyEconomyHandler.isActive()) - return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY); - else - return Component.text("Click to deposit to or withdraw from the town bank.", NamedTextColor.GRAY); - }) - .action(town == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, town))) - .build()) .build(); } @@ -630,6 +615,68 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_SET_SPAWN.getN .build(); } + public static MenuInventory formatTownBankMenu(final Player player) { + final Town town = TownyAPI.getInstance().getTown(player); + + final MenuInventory.Builder builder = MenuInventory.builder() + .title(Component.text("Town Bank")) + .rows(3) + .addItem(MenuHelper.backButton().build()) + .addItem(MenuItem.builder(Material.EMERALD_BLOCK) + .name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2))) + .lore(() -> { + if (town == null) + return Component.text("You are not part of a town.", NamedTextColor.GRAY); + else if (!TownyEconomyHandler.isActive()) + return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY); + else + return Component.text("Click to deposit to or withdraw from the town bank.", NamedTextColor.GRAY); + }) + .action(town == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, town))) + .build()) + .addItem(MenuItem.builder(Material.WRITABLE_BOOK) + .name(Component.text("Transaction History", NamedTextColor.GREEN)) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2))) + .lore(() -> { + if (town == null) + return Component.text("You are not part of a town.", NamedTextColor.GRAY); + else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode())) + return Component.text("You do not have permission to view the town's transaction history.", NamedTextColor.GRAY); + else + return Component.text("Click to view the town's transaction history.", NamedTextColor.GRAY); + }) + .action(town != null && player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode()) + ? ClickAction.openInventory(() -> createBankHistoryMenu(town)) : ClickAction.NONE) + .build()); + + if (town != null && TownyEconomyHandler.isActive()) { + builder.addItem(formatBankStatus(player, town.getAccount(), true) + .slot(SlotAnchor.anchor(VerticalAnchor.fromTop(0), HorizontalAnchor.fromLeft(4))) + .build()); + } + + return builder.build(); + } + + public static MenuItem.Builder formatBankStatus(final Player player, final Account account, final boolean town) { + return MenuItem.builder(Material.OAK_SIGN) + .name(Component.text("Bank Status", NamedTextColor.GREEN)) + .lore(Component.text("Balance: ", NamedTextColor.DARK_GREEN).append(Component.text(TownyEconomyHandler.getFormattedBalance(account.getCachedBalance()), NamedTextColor.GREEN))) + .lore(() -> { + if (!player.hasPermission((town ? PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY : PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY).getNode())) + return Component.empty(); + + final List transactions = account.getAuditor().getTransactions(); + + if (transactions.isEmpty()) + return Component.text("Last transaction: ", NamedTextColor.DARK_GREEN).append(Component.text("no recent transactions", NamedTextColor.GREEN)); + else + // TODO: format as time ago when raw time is exposed in BankTransaction + return Component.text("Last transaction: ", NamedTextColor.DARK_GREEN).append(Component.text(transactions.get(transactions.size() - 1).getTime(), NamedTextColor.GREEN)); + }); + } + public static MenuItem.Builder formatTownInfo(Town town) { if (town == null) return MenuItem.builder(Material.GRASS_BLOCK) diff --git a/src/main/resources/Changelog.txt b/src/main/resources/Changelog.txt index 3fcd6f7..3034f98 100644 --- a/src/main/resources/Changelog.txt +++ b/src/main/resources/Changelog.txt @@ -6,11 +6,14 @@ - Closes #6 - Use a CompletableFuture for the menu scheduler instead of the Bukkit scheduler. - Initial resident management menu for nations - - Nation rank menu - - Use correct perm node for bank history + - Added a nation rank menu + - fix: Use the correct perm node for bank history - Use the same code for town & nation toggle creation. - Added a plot claim button to the plot menu. - Added balance line to town and resident info items. - Added button for withdrawing/depositing from/to nation or town banks. - Added plot permission override support. - Added a plot toggle menu. + - fix: User input text box is now empty by default + - Added town and nation bank menus that shows current bank balance and last transaction time + - Moved transaction history & deposit/withdraw buttons to the bank menus