Skip to content

Commit 28ec7c2

Browse files
Dykamkhobbits
authored andcommitted
You can now access the old balance during the UserBalanceUpdateEvent Event
1 parent ee98676 commit 28ec7c2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Essentials/src/com/earth2me/essentials/User.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public void setMoney(final BigDecimal value) throws MaxMoneyException
444444
}
445445
return;
446446
}
447+
final BigDecimal oldBalance = _getMoney();
447448
if (Methods.hasMethod())
448449
{
449450
try
@@ -461,7 +462,7 @@ public void setMoney(final BigDecimal value) throws MaxMoneyException
461462
}
462463
}
463464
super.setMoney(value, true);
464-
ess.getServer().getPluginManager().callEvent(new UserBalanceUpdateEvent(this.getBase(), value));
465+
ess.getServer().getPluginManager().callEvent(new UserBalanceUpdateEvent(this.getBase(), oldBalance, value));
465466
Trade.log("Update", "Set", "API", getName(), new Trade(value, ess), null, null, null, ess);
466467
}
467468

Essentials/src/net/ess3/api/events/UserBalanceUpdateEvent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class UserBalanceUpdateEvent extends Event
1111
{
1212
private static final HandlerList handlers = new HandlerList();
1313
private final Player player;
14+
private final BigDecimal originalBalance;
1415
private final BigDecimal balance;
1516

16-
public UserBalanceUpdateEvent(Player player, BigDecimal balance)
17+
public UserBalanceUpdateEvent(Player player, BigDecimal originalBalance, BigDecimal balance)
1718
{
1819
this.player = player;
20+
this.originalBalance = originalBalance;
1921
this.balance = balance;
2022
}
2123

@@ -39,4 +41,9 @@ public BigDecimal getNewBalance()
3941
{
4042
return balance;
4143
}
44+
45+
public BigDecimal getOldBalance()
46+
{
47+
return originalBalance;
48+
}
4249
}

0 commit comments

Comments
 (0)