mirror of https://github.com/MilkBowl/VaultAPI.git
Remove previous variable and add EconomyResponse variable, call event in EconomyReponse
This commit is contained in:
parent
95720a8700
commit
d190b22ce9
|
@ -15,6 +15,10 @@
|
|||
*/
|
||||
package net.milkbowl.vault.economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import net.milkbowl.vault.events.BalanceUpdateEvent;
|
||||
|
||||
/**
|
||||
* Indicates a typical Return for an Economy method.
|
||||
* It includes a {@link ResponseType} indicating whether the plugin currently being used for Economy actually allows
|
||||
|
@ -72,6 +76,7 @@ public class EconomyResponse {
|
|||
this.balance = balance;
|
||||
this.type = type;
|
||||
this.errorMessage = errorMessage;
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BalanceUpdateEvent(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,35 +1,24 @@
|
|||
package net.milkbowl.vault.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
|
||||
public class BalanceUpdateEvent extends Event {
|
||||
|
||||
//For implements personnal Economy Class :
|
||||
//Call this event BEFORE the update
|
||||
//And don't forget "if (!event.isCancelled())" if you want to can cancel the event
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player; //The player
|
||||
private double previousBalance; //The balance before update
|
||||
private double newBalance; //The balance after update
|
||||
private double amountDifference; //The difference beetween previous and new balance. For example when /eco give Player 10, amount difference is 10.
|
||||
private Cause cause;
|
||||
private boolean cancelled;
|
||||
private EconomyResponse response;
|
||||
|
||||
public BalanceUpdateEvent(Player player, double previousBalance, double newBalance, double amountDifference) {
|
||||
public BalanceUpdateEvent(EconomyResponse response) {
|
||||
|
||||
this.player = player;
|
||||
this.previousBalance = previousBalance;
|
||||
this.newBalance = newBalance;
|
||||
this.amountDifference = amountDifference;
|
||||
this.previousBalance = response.balance + response.amount;
|
||||
this.response = response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -38,43 +27,13 @@ public class BalanceUpdateEvent extends Event {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public double getPreviousBalance() {
|
||||
return previousBalance;
|
||||
}
|
||||
|
||||
public double getNewBalance() {
|
||||
return newBalance;
|
||||
}
|
||||
|
||||
public double getAmountDifference() {
|
||||
return amountDifference;
|
||||
}
|
||||
|
||||
public Cause getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The cause of the balance update.
|
||||
*/
|
||||
public enum Cause {
|
||||
WITHDRAW,
|
||||
DEPOSIT,
|
||||
UNKNOWN
|
||||
public EconomyResponse getEconomyResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue