Added accountName in BalanceUpateEvent and EconomyResponse for get the account, and add isPlayer in BalanceUpdateEvent to check if accountName is a player account

This commit is contained in:
hbarreau 2020-12-17 11:57:55 +01:00
parent d190b22ce9
commit ef2e2e0dae
2 changed files with 19 additions and 2 deletions

View File

@ -63,6 +63,11 @@ public class EconomyResponse {
* Error message if the variable 'type' is ResponseType.FAILURE
*/
public final String errorMessage;
/**
* Name of account
*/
public final String accountName;
/**
* Constructor for EconomyResponse
@ -71,7 +76,8 @@ public class EconomyResponse {
* @param type Success or failure type of the operation
* @param errorMessage Error message if necessary (commonly null)
*/
public EconomyResponse(double amount, double balance, ResponseType type, String errorMessage) {
public EconomyResponse(String accountName, double amount, double balance, ResponseType type, String errorMessage) {
this.accountName = accountName;
this.amount = amount;
this.balance = balance;
this.type = type;

View File

@ -1,5 +1,6 @@
package net.milkbowl.vault.events;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -11,11 +12,13 @@ public class BalanceUpdateEvent extends Event {
private double previousBalance; //The balance before update
private EconomyResponse response;
private String accountName;
public BalanceUpdateEvent(EconomyResponse response) {
this.previousBalance = response.balance + response.amount;
this.response = response;
this.previousBalance = response.balance + response.amount;
this.accountName = response.accountName;
}
@ -35,5 +38,13 @@ public class BalanceUpdateEvent extends Event {
public EconomyResponse getEconomyResponse() {
return response;
}
public String getAccountName() {
return accountName;
}
public boolean isPlayer(String player) {
return Bukkit.getOfflinePlayer(player).isOnline();
}
}