|
1 | 1 | package net.essentialsx.api.v2.events; |
2 | 2 |
|
3 | 3 | import com.earth2me.essentials.CommandSource; |
| 4 | +import com.google.common.base.Preconditions; |
4 | 5 | import net.ess3.api.IUser; |
5 | 6 | import org.bukkit.Bukkit; |
6 | 7 | import org.bukkit.event.Cancellable; |
7 | | -import org.bukkit.event.Event; |
8 | 8 | import org.bukkit.event.HandlerList; |
9 | 9 |
|
10 | 10 | import java.math.BigDecimal; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Fired when a transaction (e.g. /pay) is about to be handled. |
14 | 14 | */ |
15 | | -public class PreTransactionEvent extends Event implements Cancellable { |
| 15 | +public class PreTransactionEvent extends TransactionEvent implements Cancellable { |
16 | 16 | private static final HandlerList handlers = new HandlerList(); |
17 | 17 |
|
18 | | - private final CommandSource requester; |
19 | | - private final IUser target; |
20 | | - private final BigDecimal amount; |
21 | 18 | private boolean cancelled; |
22 | 19 |
|
23 | 20 | public PreTransactionEvent(final CommandSource requester, final IUser target, final BigDecimal amount) { |
24 | | - super(!Bukkit.isPrimaryThread()); |
25 | | - this.requester = requester; |
26 | | - this.target = target; |
27 | | - this.amount = amount; |
| 21 | + super(!Bukkit.isPrimaryThread(), requester, target, amount); |
28 | 22 | } |
29 | 23 |
|
30 | 24 | /** |
31 | | - * @return the user who initiated the transaction |
| 25 | + * Sets the new amount of this transaction event. |
| 26 | + * Note that the new amount will still be subtracted from the requester's bank. |
| 27 | + * @param decimal the new amount |
32 | 28 | */ |
33 | | - public CommandSource getRequester() { |
34 | | - return requester; |
35 | | - } |
| 29 | + public void setAmount(final BigDecimal decimal) { |
| 30 | + Preconditions.checkNotNull(decimal, "decimal cannot be null"); |
| 31 | + Preconditions.checkArgument(decimal.compareTo(BigDecimal.ZERO) >= 0, "decimal cannot be negative"); |
36 | 32 |
|
37 | | - /** |
38 | | - * @return the user who received the money |
39 | | - */ |
40 | | - public IUser getTarget() { |
41 | | - return target; |
42 | | - } |
43 | | - |
44 | | - /** |
45 | | - * @return the amount of money transacted |
46 | | - */ |
47 | | - public BigDecimal getAmount() { |
48 | | - return amount; |
| 33 | + this.amount = decimal; |
49 | 34 | } |
50 | 35 |
|
51 | 36 | @Override |
|
0 commit comments