mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-12-22 11:37:38 +00:00
Atomicize balance field in SimpleUserData
This commit is contained in:
parent
0e31bea33f
commit
bdd8c1fb68
@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class SimpleUserData implements UserData
|
||||
{
|
||||
@ -26,7 +27,7 @@ public class SimpleUserData implements UserData
|
||||
private boolean frozen;
|
||||
private boolean canInteract;
|
||||
private boolean caged;
|
||||
private long balance;
|
||||
private AtomicLong balance;
|
||||
private boolean transactionsFrozen;
|
||||
|
||||
public SimpleUserData(final Player player)
|
||||
@ -56,7 +57,7 @@ public class SimpleUserData implements UserData
|
||||
this.frozen = frozen;
|
||||
this.canInteract = canInteract;
|
||||
this.caged = caged;
|
||||
this.balance = balance;
|
||||
this.balance = new AtomicLong(balance);
|
||||
this.transactionsFrozen = transactionsFrozen;
|
||||
}
|
||||
|
||||
@ -215,24 +216,24 @@ public class SimpleUserData implements UserData
|
||||
@Override
|
||||
public long getBalance()
|
||||
{
|
||||
return balance;
|
||||
return balance.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToBalance(long amount)
|
||||
{
|
||||
this.balance += amount;
|
||||
this.balance.addAndGet(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromBalance(long amount)
|
||||
{
|
||||
this.balance -= amount;
|
||||
this.balance.addAndGet(-amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBalance(long newBalance)
|
||||
{
|
||||
this.balance = newBalance;
|
||||
this.balance.set(newBalance);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user