mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-05 01:59:35 +01:00
Add support for SaneEconomyTransactionEvent.
This commit is contained in:
parent
39e010a659
commit
d95d55c4f4
@ -5,6 +5,7 @@ import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
||||
import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
||||
import org.appledash.saneeconomy.event.SaneEconomyTransactionEvent;
|
||||
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -164,6 +165,12 @@ public class EconomyManager {
|
||||
Economable receiver = transaction.getReceiver();
|
||||
double amount = transaction.getAmount(); // This amount is validated upon creation of Transaction
|
||||
|
||||
SaneEconomyTransactionEvent evt = new SaneEconomyTransactionEvent(transaction);
|
||||
Bukkit.getServer().getPluginManager().callEvent(evt);
|
||||
if (evt.isCancelled()) {
|
||||
return new TransactionResult(transaction, TransactionResult.Status.CANCELLED_BY_PLUGIN);
|
||||
}
|
||||
|
||||
if (transaction.isSenderAffected()) { // Sender should have balance taken from them
|
||||
if (!hasBalance(sender, amount)) {
|
||||
return new TransactionResult(transaction, TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS);
|
||||
|
@ -40,6 +40,7 @@ public class TransactionResult {
|
||||
|
||||
public enum Status {
|
||||
SUCCESS("Success."),
|
||||
CANCELLED_BY_PLUGIN("That transaction was cancelled by a plugin."), // In theory this message should never be shown.
|
||||
ERR_NOT_ENOUGH_FUNDS("Not enough money is available for you to complete that transaction.");
|
||||
|
||||
private final String message;
|
||||
|
@ -0,0 +1,45 @@
|
||||
package org.appledash.saneeconomy.event;
|
||||
|
||||
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Created by appledash on 7/5/17.
|
||||
* Blackjack is best pony.
|
||||
*
|
||||
* This event is called whenever a Transaction occurs in the plugin. If you cancel this event, the transaction will be cancelled as well.
|
||||
*/
|
||||
public class SaneEconomyTransactionEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlerList = new HandlerList();
|
||||
private final Transaction transaction;
|
||||
private boolean isCancelled;
|
||||
|
||||
public SaneEconomyTransactionEvent(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
public Transaction getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user