Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter Account & Transaction and fix TownyTransactionEvent. #7431

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change Transaction#getPlayer to address review.
LlmDl committed Jul 12, 2024
commit f5e90d01401f48fbd0f3cb17cab4e0e2fda29f84
Original file line number Diff line number Diff line change
@@ -215,8 +215,8 @@ public static boolean hasEnough(String accountName, double amount, World world)

private static boolean runPreChecks(Transaction transaction, String accountName) {
TownyPreTransactionEvent preEvent = new TownyPreTransactionEvent(transaction);
if (BukkitTools.isEventCancelled(preEvent) && transaction.getPlayer() != null) {
TownyMessaging.sendErrorMsg(transaction.getPlayer(), preEvent.getCancelMessage());
if (BukkitTools.isEventCancelled(preEvent) && transaction.getSendingPlayer() != null) {
TownyMessaging.sendErrorMsg(transaction.getSendingPlayer(), preEvent.getCancelMessage());
return false;
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.palmergames.bukkit.towny.object.economy.transaction;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.economy.Account;

public class Transaction {
@@ -57,9 +57,18 @@ public boolean hasSenderAccount() {
return sendingAccount != null;
}

/**
* In the case of a Transaction where a player deposits money into a town or
* nation bank, this will return the player, or null if it is not a transaction
* where a player sent money.
*
* @return the Player that sent money or null.
*/
@Nullable
public Player getPlayer() {
return getSendingAccount() != null ? Bukkit.getServer().getPlayerExact(getSendingAccount().getName()) : null;
public Player getSendingPlayer() {
if (hasSenderAccount() && getSendingAccount().getEconomyHandler() instanceof Resident resident)
return resident.getPlayer();
return null;
}

public double getAmount() {