Skip to content

Commit 12bb25e

Browse files
committed
Adjust event to extend TransactionEvent
1 parent f9c9436 commit 12bb25e

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

Essentials/src/main/java/net/essentialsx/api/v2/events/PreTransactionEvent.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,36 @@
11
package net.essentialsx.api.v2.events;
22

33
import com.earth2me.essentials.CommandSource;
4+
import com.google.common.base.Preconditions;
45
import net.ess3.api.IUser;
56
import org.bukkit.Bukkit;
67
import org.bukkit.event.Cancellable;
7-
import org.bukkit.event.Event;
88
import org.bukkit.event.HandlerList;
99

1010
import java.math.BigDecimal;
1111

1212
/**
1313
* Fired when a transaction (e.g. /pay) is about to be handled.
1414
*/
15-
public class PreTransactionEvent extends Event implements Cancellable {
15+
public class PreTransactionEvent extends TransactionEvent implements Cancellable {
1616
private static final HandlerList handlers = new HandlerList();
1717

18-
private final CommandSource requester;
19-
private final IUser target;
20-
private final BigDecimal amount;
2118
private boolean cancelled;
2219

2320
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);
2822
}
2923

3024
/**
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
3228
*/
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");
3632

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;
4934
}
5035

5136
@Override

Essentials/src/main/java/net/essentialsx/api/v2/events/TransactionEvent.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ public class TransactionEvent extends Event {
1616

1717
private final CommandSource requester;
1818
private final IUser target;
19-
private final BigDecimal amount;
19+
protected BigDecimal amount;
2020

21-
public TransactionEvent(CommandSource requester, IUser target, BigDecimal amount) {
22-
super(!Bukkit.isPrimaryThread());
21+
protected TransactionEvent(boolean async, CommandSource requester, IUser target, BigDecimal amount) {
22+
super(async);
2323
this.requester = requester;
2424
this.target = target;
2525
this.amount = amount;
2626
}
2727

28+
public TransactionEvent(CommandSource requester, IUser target, BigDecimal amount) {
29+
this(!Bukkit.isPrimaryThread(), requester, target, amount);
30+
}
31+
2832
/**
2933
* @return the user who initiated the transaction
3034
*/

0 commit comments

Comments
 (0)