Skip to content

Commit

Permalink
Rebased and accounted for recent changes in TownyAdminCommand, also add
Browse files Browse the repository at this point in the history
annotations and helper methods to Transaction.
  • Loading branch information
LlmDl committed Jun 3, 2024
1 parent a205e12 commit e88ba0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e88ba0c

Please sign in to comment.