mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +00:00
Add TransactionEvent for successful transactions (#3649)
This commit is contained in:
parent
d78832498e
commit
a20d20574e
2 changed files with 60 additions and 0 deletions
|
@ -15,6 +15,7 @@ import net.ess3.api.events.AfkStatusChangeEvent;
|
|||
import net.ess3.api.events.JailStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import net.essentialsx.api.v2.events.TransactionEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -199,6 +200,8 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
reciever.setMoney(reciever.getMoney().add(value), cause);
|
||||
sendMessage(tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()));
|
||||
reciever.sendMessage(tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()));
|
||||
final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value);
|
||||
ess.getServer().getPluginManager().callEvent(transactionEvent);
|
||||
} else {
|
||||
throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(value, ess)));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package net.essentialsx.api.v2.events;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Fired when a transaction (e.g. /pay) is successfully handled.
|
||||
*/
|
||||
public class TransactionEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final CommandSource requester;
|
||||
private final IUser target;
|
||||
private final BigDecimal amount;
|
||||
|
||||
public TransactionEvent(CommandSource requester, IUser target, BigDecimal amount) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user who initiated the transaction
|
||||
*/
|
||||
public CommandSource getRequester() {
|
||||
return requester;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user who received the money
|
||||
*/
|
||||
public IUser getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount of money transacted
|
||||
*/
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue