mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2025-02-21 06:11:33 +01:00
Fix a bug where the CONSOLE account does not have an infinite balance on databases upgraded from older versions.
This commit is contained in:
parent
eab4b59501
commit
2856305330
@ -4,6 +4,7 @@ import org.appledash.saneeconomy.ISaneEconomy;
|
|||||||
import org.appledash.saneeconomy.SaneEconomy;
|
import org.appledash.saneeconomy.SaneEconomy;
|
||||||
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
||||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||||
|
import org.appledash.saneeconomy.economy.economable.EconomableConsole;
|
||||||
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
||||||
import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
||||||
import org.appledash.saneeconomy.event.SaneEconomyTransactionEvent;
|
import org.appledash.saneeconomy.event.SaneEconomyTransactionEvent;
|
||||||
@ -67,7 +68,7 @@ public class EconomyManager {
|
|||||||
* @return Player's balance
|
* @return Player's balance
|
||||||
*/
|
*/
|
||||||
public BigDecimal getBalance(Economable targetPlayer) {
|
public BigDecimal getBalance(Economable targetPlayer) {
|
||||||
if (targetPlayer == Economable.CONSOLE) {
|
if (EconomableConsole.isConsole(targetPlayer)) {
|
||||||
return new BigDecimal(Double.MAX_VALUE);
|
return new BigDecimal(Double.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ public class EconomyManager {
|
|||||||
* @return True if they have requiredBalance or more, false otherwise
|
* @return True if they have requiredBalance or more, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasBalance(Economable targetPlayer, BigDecimal requiredBalance) {
|
public boolean hasBalance(Economable targetPlayer, BigDecimal requiredBalance) {
|
||||||
return (targetPlayer == Economable.CONSOLE) || (this.getBalance(targetPlayer).compareTo(requiredBalance) >= 0);
|
return (EconomableConsole.isConsole(targetPlayer)) || (this.getBalance(targetPlayer).compareTo(requiredBalance) >= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ public class EconomyManager {
|
|||||||
public void setBalance(Economable targetPlayer, BigDecimal amount) {
|
public void setBalance(Economable targetPlayer, BigDecimal amount) {
|
||||||
amount = NumberUtils.filterAmount(this.currency, amount);
|
amount = NumberUtils.filterAmount(this.currency, amount);
|
||||||
|
|
||||||
if (targetPlayer == Economable.CONSOLE) {
|
if (EconomableConsole.isConsole(targetPlayer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package org.appledash.saneeconomy.economy.economable;
|
package org.appledash.saneeconomy.economy.economable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by appledash on 9/21/16.
|
* Created by appledash on 9/21/16.
|
||||||
* Blackjack is best pony.
|
* Blackjack is best pony.
|
||||||
*/
|
*/
|
||||||
public class EconomableConsole implements Economable {
|
public class EconomableConsole implements Economable {
|
||||||
|
public static final UUID CONSOLE_UUID = new UUID( 0xf88708c237d84a0bL, 0x944259c68e517557L); // Pregenerated for performance
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "CONSOLE";
|
return "CONSOLE";
|
||||||
@ -12,6 +16,17 @@ public class EconomableConsole implements Economable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUniqueIdentifier() {
|
public String getUniqueIdentifier() {
|
||||||
return "CONSOLE";
|
return "console:" + CONSOLE_UUID.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isConsole(Economable economable) {
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(economable.getUniqueIdentifier().split(":")[1]);
|
||||||
|
|
||||||
|
// Fast comparison + fix for bugs with older databases
|
||||||
|
return economable == Economable.CONSOLE || (uuid.getLeastSignificantBits() == CONSOLE_UUID.getLeastSignificantBits() || uuid.getMostSignificantBits() == CONSOLE_UUID.getMostSignificantBits());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.appledash.saneeconomy.economy.transaction;
|
|||||||
|
|
||||||
import org.appledash.saneeconomy.economy.Currency;
|
import org.appledash.saneeconomy.economy.Currency;
|
||||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||||
|
import org.appledash.saneeconomy.economy.economable.EconomableConsole;
|
||||||
import org.appledash.saneeconomy.economy.transaction.TransactionReason.AffectedParties;
|
import org.appledash.saneeconomy.economy.transaction.TransactionReason.AffectedParties;
|
||||||
import org.appledash.saneeconomy.utils.NumberUtils;
|
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSenderAffected() {
|
public boolean isSenderAffected() {
|
||||||
if (this.sender == Economable.CONSOLE) {
|
if (EconomableConsole.isConsole(this.sender)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReceiverAffected() {
|
public boolean isReceiverAffected() {
|
||||||
if (this.receiver == Economable.CONSOLE) {
|
if (EconomableConsole.isConsole(this.receiver)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user