From e88ba0ce05f94ef012bc02a7d12c8ef4b510feea Mon Sep 17 00:00:00 2001 From: LlmDl Date: Mon, 3 Jun 2024 12:06:43 -0500 Subject: [PATCH] Rebased and accounted for recent changes in TownyAdminCommand, also add annotations and helper methods to Transaction. --- .../bukkit/towny/command/TownyAdminCommand.java | 11 +++++------ .../object/economy/transaction/Transaction.java | 12 +++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownyAdminCommand.java b/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownyAdminCommand.java index 50db6569d0..03abc25cca 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownyAdminCommand.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownyAdminCommand.java @@ -41,10 +41,9 @@ import com.palmergames.bukkit.towny.object.TownBlockType; import com.palmergames.bukkit.towny.object.TownBlockTypeHandler; import com.palmergames.bukkit.towny.object.TownyWorld; -import com.palmergames.bukkit.towny.object.Transaction; -import com.palmergames.bukkit.towny.object.TransactionType; import com.palmergames.bukkit.towny.object.Translatable; import com.palmergames.bukkit.towny.object.WorldCoord; +import com.palmergames.bukkit.towny.object.economy.transaction.Transaction; import com.palmergames.bukkit.towny.object.jail.UnJailReason; import com.palmergames.bukkit.towny.object.metadata.CustomDataField; import com.palmergames.bukkit.towny.permissions.PermissionNodes; @@ -1293,7 +1292,7 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T int deposit = MathUtil.getIntOrThrow(split[2]); if (town.getAccount().deposit(deposit, "Admin Deposit")) { - BukkitTools.fireEvent(new TownTransactionEvent(town, new Transaction(TransactionType.DEPOSIT, sender, deposit))); + BukkitTools.fireEvent(new TownTransactionEvent(town, Transaction.deposit(deposit).paidTo(town).build())); // Send notifications Translatable depositMessage = Translatable.of("msg_xx_deposited_xx", getSenderFormatted(sender), deposit, Translatable.of("town_sing")); TownyMessaging.sendMsg(sender, depositMessage); @@ -1314,7 +1313,7 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T int withdraw = MathUtil.getIntOrThrow(split[2]); if (town.getAccount().withdraw(withdraw, "Admin Withdraw")) { - BukkitTools.fireEvent(new TownTransactionEvent(town, new Transaction(TransactionType.WITHDRAW, sender, withdraw))); + BukkitTools.fireEvent(new TownTransactionEvent(town, Transaction.withdraw(withdraw).paidBy(town).build())); // Send notifications Translatable withdrawMessage = Translatable.of("msg_xx_withdrew_xx", getSenderFormatted(sender), withdraw, Translatable.of("town_sing")); TownyMessaging.sendMsg(sender, withdrawMessage); @@ -1735,7 +1734,7 @@ public void parseAdminNationCommand(CommandSender sender, String[] split) throws int deposit = MathUtil.getPositiveIntOrThrow(split[2]); - BukkitTools.fireEvent(new NationTransactionEvent(nation, new Transaction(TransactionType.DEPOSIT, sender, deposit))); + BukkitTools.fireEvent(new NationTransactionEvent(nation, Transaction.deposit(deposit).paidTo(nation).build())); nation.getAccount().deposit(deposit, "Admin Deposit"); // Send notifications @@ -1753,7 +1752,7 @@ public void parseAdminNationCommand(CommandSender sender, String[] split) throws int withdraw = MathUtil.getPositiveIntOrThrow(split[2]); - BukkitTools.fireEvent(new NationTransactionEvent(nation, new Transaction(TransactionType.WITHDRAW, sender, withdraw))); + BukkitTools.fireEvent(new NationTransactionEvent(nation, Transaction.withdraw(withdraw).paidBy(nation).build())); nation.getAccount().withdraw(withdraw, "Admin Withdraw"); // Send notifications diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/transaction/Transaction.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/transaction/Transaction.java index 0cf264e380..db6c02a8c4 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/transaction/Transaction.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/transaction/Transaction.java @@ -39,17 +39,27 @@ public TransactionType getType() { return type; } + @Nullable public Account getReceivingAccount() { return receivingAccount; } + public boolean hasReceiverAccount() { + return receivingAccount != null; + } + + @Nullable public Account getSendingAccount() { return sendingAccount; } + public boolean hasSenderAccount() { + return sendingAccount != null; + } + @Nullable public Player getPlayer() { - return Bukkit.getServer().getPlayerExact(getSendingAccount().getName()); + return getSendingAccount() != null ? Bukkit.getServer().getPlayerExact(getSendingAccount().getName()) : null; } public double getAmount() {