Skip to content

Commit dff7e23

Browse files
committed
Town & nation bank menus
1 parent 45fcc10 commit dff7e23

File tree

3 files changed

+126
-47
lines changed

3 files changed

+126
-47
lines changed

src/main/java/io/github/townyadvanced/townymenus/menu/NationMenu.java

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,19 @@ public static MenuInventory createNationMenu(@NotNull Player player) {
4545
.title(Component.text("Nation Menu"))
4646
.rows(6)
4747
.addItem(MenuHelper.backButton().build())
48-
.addItem(MenuItem.builder(Material.WRITABLE_BOOK)
49-
.name(Component.text("Transaction History", NamedTextColor.GREEN))
50-
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(4)))
48+
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
49+
.name(Component.text("Nation Bank", NamedTextColor.GREEN))
50+
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(3)))
5151
.lore(() -> {
5252
if (nation == null)
5353
return Component.text("You are not part of a nation.", NamedTextColor.GRAY);
54-
else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()))
55-
return Component.text("You do not have permission to view the nations's transaction history.", NamedTextColor.GRAY);
5654
else
57-
return Component.text("Click to view the nations's transaction history.", NamedTextColor.GRAY);
55+
return Component.text("Click to view the nation bank menu.", NamedTextColor.GRAY);
5856
})
59-
.action(nation == null || !player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()) ? ClickAction.NONE :
60-
ClickAction.openInventory(() -> TownMenu.createBankHistoryMenu(nation)))
57+
.action(nation == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatNationBankMenu(player)))
6158
.build())
6259
.addItem(MenuItem.builder(Material.RED_BED)
63-
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2)))
60+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(1)))
6461
.name(Component.text("Nation Spawn", NamedTextColor.GREEN))
6562
.lore(() -> {
6663
if (nation == null)
@@ -85,7 +82,7 @@ else if (!player.hasPermission("towny.nation.spawn.nation"))
8582
.build())
8683
.addItem(MenuItem.builder(Material.LEVER)
8784
.name(Component.text("Nation Toggle", NamedTextColor.GREEN))
88-
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2)))
85+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(1)))
8986
.lore(() -> {
9087
if (nation == null)
9188
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"))
9693
.build())
9794
.addItem(MenuItem.builder(Material.GRASS_BLOCK)
9895
.name(Component.text("Nation Set", NamedTextColor.GREEN))
99-
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromRight(2)))
96+
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromRight(3)))
10097
.lore(Component.text("Click to open the nation set menu.", NamedTextColor.GRAY))
10198
.action(ClickAction.openInventory(() -> formatNationSetMenu(player)))
10299
.build())
103100
.addItem(MenuItem.builder(Material.ENDER_EYE)
104101
.name(Component.text("Online in Nation", NamedTextColor.GREEN))
105-
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromLeft(2)))
102+
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromLeft(1)))
106103
.lore(() -> {
107104
if (nation == null)
108105
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
129126
.build())
130127
.addItem(MenuItem.builder(Material.PLAYER_HEAD)
131128
.name(Component.text("Nation Resident Overview", NamedTextColor.GREEN))
129+
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(2), HorizontalAnchor.fromRight(1)))
132130
.lore(() -> {
133131
if (nation == null)
134132
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
137135
})
138136
.action(nation == null ? ClickAction.NONE : ClickAction.openInventory(() -> createResidentOverview(player)))
139137
.build())
140-
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
141-
.name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN))
142-
.slot(1)
143-
.lore(() -> {
144-
if (nation == null)
145-
return Component.text("You are not part of a nation.", NamedTextColor.GRAY);
146-
else if (!TownyEconomyHandler.isActive())
147-
return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY);
148-
else
149-
return Component.text("Click to deposit to or withdraw from the nation bank.", NamedTextColor.GRAY);
150-
})
151-
.action(nation == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, nation)))
152-
.build())
153138
.build();
154139
}
155140

@@ -460,4 +445,48 @@ public static MenuInventory formatRankManagementMenu(Player player, Nation natio
460445

461446
return paginator.build();
462447
}
448+
449+
public static MenuInventory formatNationBankMenu(final Player player) {
450+
final Nation nation = TownyAPI.getInstance().getNation(player);
451+
452+
final MenuInventory.Builder builder = MenuInventory.builder()
453+
.title(Component.text("Nation Bank"))
454+
.rows(3)
455+
.addItem(MenuHelper.backButton().build())
456+
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
457+
.name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN))
458+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2)))
459+
.lore(() -> {
460+
if (nation == null)
461+
return Component.text("You are not part of a nation.", NamedTextColor.GRAY);
462+
else if (!TownyEconomyHandler.isActive())
463+
return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY);
464+
else
465+
return Component.text("Click to deposit to or withdraw from the nation bank.", NamedTextColor.GRAY);
466+
})
467+
.action(nation == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, nation)))
468+
.build())
469+
.addItem(MenuItem.builder(Material.WRITABLE_BOOK)
470+
.name(Component.text("Transaction History", NamedTextColor.GREEN))
471+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2)))
472+
.lore(() -> {
473+
if (nation == null)
474+
return Component.text("You are not part of a nation.", NamedTextColor.GRAY);
475+
else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()))
476+
return Component.text("You do not have permission to view the nations's transaction history.", NamedTextColor.GRAY);
477+
else
478+
return Component.text("Click to view the nations's transaction history.", NamedTextColor.GRAY);
479+
})
480+
.action(nation == null || !player.hasPermission(PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY.getNode()) ? ClickAction.NONE :
481+
ClickAction.openInventory(() -> TownMenu.createBankHistoryMenu(nation)))
482+
.build());
483+
484+
if (nation != null && TownyEconomyHandler.isActive()) {
485+
builder.addItem(TownMenu.formatBankStatus(player, nation.getAccount(), false)
486+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(0), HorizontalAnchor.fromLeft(4)))
487+
.build());
488+
}
489+
490+
return builder.build();
491+
}
463492
}

src/main/java/io/github/townyadvanced/townymenus/menu/TownMenu.java

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.palmergames.bukkit.towny.object.TownBlockTypeHandler;
2323
import com.palmergames.bukkit.towny.object.TransactionType;
2424
import com.palmergames.bukkit.towny.object.Translatable;
25+
import com.palmergames.bukkit.towny.object.economy.Account;
2526
import com.palmergames.bukkit.towny.object.economy.BankTransaction;
2627
import com.palmergames.bukkit.towny.permissions.PermissionNodes;
2728
import com.palmergames.bukkit.towny.permissions.TownyPerms;
@@ -60,19 +61,16 @@ public static MenuInventory createTownMenu(@NotNull Player player) {
6061
.addItem(formatTownInfo(town)
6162
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(4)))
6263
.build())
63-
.addItem(MenuItem.builder(Material.WRITABLE_BOOK)
64-
.name(Component.text("Transaction History", NamedTextColor.GREEN))
64+
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
65+
.name(Component.text("Town Bank", NamedTextColor.GREEN))
6566
.slot(SlotAnchor.anchor(VerticalAnchor.fromBottom(1), HorizontalAnchor.fromLeft(3)))
6667
.lore(() -> {
6768
if (town == null)
6869
return Component.text("You are not part of a town.", NamedTextColor.GRAY);
69-
else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode()))
70-
return Component.text("You do not have permission to view the town's transaction history.", NamedTextColor.GRAY);
7170
else
72-
return Component.text("Click to view the town's transaction history.", NamedTextColor.GRAY);
71+
return Component.text("Click to view the town bank menu.", NamedTextColor.GRAY);
7372
})
74-
.action(town != null && player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode())
75-
? ClickAction.openInventory(() -> createBankHistoryMenu(town)) : ClickAction.NONE)
73+
.action(town == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatTownBankMenu(player)))
7674
.build())
7775
.addItem(MenuItem.builder(Material.GRASS_BLOCK)
7876
.name(Component.text("Town Plots", NamedTextColor.GREEN))
@@ -201,19 +199,6 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_ONLINE.getNode
201199
})
202200
.action(town == null ? ClickAction.NONE : ClickAction.openInventory(() -> formatTownManagementMenu(player)))
203201
.build())
204-
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
205-
.name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN))
206-
.slot(0)
207-
.lore(() -> {
208-
if (town == null)
209-
return Component.text("You are not part of a town.", NamedTextColor.GRAY);
210-
else if (!TownyEconomyHandler.isActive())
211-
return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY);
212-
else
213-
return Component.text("Click to deposit to or withdraw from the town bank.", NamedTextColor.GRAY);
214-
})
215-
.action(town == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, town)))
216-
.build())
217202
.build();
218203
}
219204

@@ -630,6 +615,68 @@ else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_SET_SPAWN.getN
630615
.build();
631616
}
632617

618+
public static MenuInventory formatTownBankMenu(final Player player) {
619+
final Town town = TownyAPI.getInstance().getTown(player);
620+
621+
final MenuInventory.Builder builder = MenuInventory.builder()
622+
.title(Component.text("Town Bank"))
623+
.rows(3)
624+
.addItem(MenuHelper.backButton().build())
625+
.addItem(MenuItem.builder(Material.EMERALD_BLOCK)
626+
.name(Component.text("Deposit or Withdraw", NamedTextColor.GREEN))
627+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromLeft(2)))
628+
.lore(() -> {
629+
if (town == null)
630+
return Component.text("You are not part of a town.", NamedTextColor.GRAY);
631+
else if (!TownyEconomyHandler.isActive())
632+
return Translatable.of("msg_err_no_economy").locale(player).component().color(NamedTextColor.GRAY);
633+
else
634+
return Component.text("Click to deposit to or withdraw from the town bank.", NamedTextColor.GRAY);
635+
})
636+
.action(town == null || !TownyEconomyHandler.isActive() ? ClickAction.NONE : ClickAction.openInventory(() -> GovernmentMenus.createDepositWithdrawMenu(player, town)))
637+
.build())
638+
.addItem(MenuItem.builder(Material.WRITABLE_BOOK)
639+
.name(Component.text("Transaction History", NamedTextColor.GREEN))
640+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(1), HorizontalAnchor.fromRight(2)))
641+
.lore(() -> {
642+
if (town == null)
643+
return Component.text("You are not part of a town.", NamedTextColor.GRAY);
644+
else if (!player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode()))
645+
return Component.text("You do not have permission to view the town's transaction history.", NamedTextColor.GRAY);
646+
else
647+
return Component.text("Click to view the town's transaction history.", NamedTextColor.GRAY);
648+
})
649+
.action(town != null && player.hasPermission(PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY.getNode())
650+
? ClickAction.openInventory(() -> createBankHistoryMenu(town)) : ClickAction.NONE)
651+
.build());
652+
653+
if (town != null && TownyEconomyHandler.isActive()) {
654+
builder.addItem(formatBankStatus(player, town.getAccount(), true)
655+
.slot(SlotAnchor.anchor(VerticalAnchor.fromTop(0), HorizontalAnchor.fromLeft(4)))
656+
.build());
657+
}
658+
659+
return builder.build();
660+
}
661+
662+
public static MenuItem.Builder formatBankStatus(final Player player, final Account account, final boolean town) {
663+
return MenuItem.builder(Material.OAK_SIGN)
664+
.name(Component.text("Bank Status", NamedTextColor.GREEN))
665+
.lore(Component.text("Balance: ", NamedTextColor.DARK_GREEN).append(Component.text(TownyEconomyHandler.getFormattedBalance(account.getCachedBalance()), NamedTextColor.GREEN)))
666+
.lore(() -> {
667+
if (!player.hasPermission((town ? PermissionNodes.TOWNY_COMMAND_TOWN_BANKHISTORY : PermissionNodes.TOWNY_COMMAND_NATION_BANKHISTORY).getNode()))
668+
return Component.empty();
669+
670+
final List<BankTransaction> transactions = account.getAuditor().getTransactions();
671+
672+
if (transactions.isEmpty())
673+
return Component.text("Last transaction: ", NamedTextColor.DARK_GREEN).append(Component.text("no recent transactions", NamedTextColor.GREEN));
674+
else
675+
// TODO: format as time ago when raw time is exposed in BankTransaction
676+
return Component.text("Last transaction: ", NamedTextColor.DARK_GREEN).append(Component.text(transactions.get(transactions.size() - 1).getTime(), NamedTextColor.GREEN));
677+
});
678+
}
679+
633680
public static MenuItem.Builder formatTownInfo(Town town) {
634681
if (town == null)
635682
return MenuItem.builder(Material.GRASS_BLOCK)

src/main/resources/Changelog.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
- Closes #6
77
- Use a CompletableFuture for the menu scheduler instead of the Bukkit scheduler.
88
- Initial resident management menu for nations
9-
- Nation rank menu
10-
- Use correct perm node for bank history
9+
- Added a nation rank menu
10+
- fix: Use the correct perm node for bank history
1111
- Use the same code for town & nation toggle creation.
1212
- Added a plot claim button to the plot menu.
1313
- Added balance line to town and resident info items.
1414
- Added button for withdrawing/depositing from/to nation or town banks.
1515
- Added plot permission override support.
1616
- Added a plot toggle menu.
17+
- fix: User input text box is now empty by default
18+
- Added town and nation bank menus that shows current bank balance and last transaction time
19+
- Moved transaction history & deposit/withdraw buttons to the bank menus

0 commit comments

Comments
 (0)