mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-25 11:35:33 +01:00
Clean up code a bit
This commit is contained in:
parent
854c2f5f10
commit
afa4e9d36e
@ -36,7 +36,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
private TransactionLogger transactionLogger;
|
||||
private GithubVersionChecker versionChecker;
|
||||
|
||||
private final Map<String, SaneCommand> COMMANDS = new HashMap<String, SaneCommand>() {
|
||||
private final Map<String, SaneCommand> commands = new HashMap<String, SaneCommand>() {
|
||||
{
|
||||
this.put("balance", new BalanceCommand(SaneEconomy.this));
|
||||
this.put("ecoadmin", new EconomyAdminCommand(SaneEconomy.this));
|
||||
@ -184,7 +184,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
|
||||
private void loadCommands() {
|
||||
this.getLogger().info("Initializing commands...");
|
||||
this.COMMANDS.forEach((name, command) -> this.getCommand(name).setExecutor(command));
|
||||
this.commands.forEach((name, command) -> this.getCommand(name).setExecutor(command));
|
||||
this.getLogger().info("Initialized commands.");
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/13/2016.
|
||||
|
@ -44,9 +44,9 @@ public abstract class EconomyStorageBackendCaching implements EconomyStorageBack
|
||||
public void reloadTopPlayerBalances() {
|
||||
Map<String, BigDecimal> balances = new HashMap<>();
|
||||
|
||||
this.balances.forEach((identifier, balance) -> {
|
||||
balances.put(this.uuidToName.get(identifier), balance);
|
||||
});
|
||||
this.balances.forEach((identifier, balance) ->
|
||||
balances.put(this.uuidToName.get(identifier), balance)
|
||||
);
|
||||
|
||||
this.topBalances = MapUtil.sortByValue(balances);
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void reloadDatabase() {
|
||||
if (!this.file.exists()) {
|
||||
return;
|
||||
@ -43,9 +42,9 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
this.balances = new ConcurrentHashMap<>();
|
||||
this.uuidToName = new ConcurrentHashMap<>(dataHolder.uuidToName);
|
||||
|
||||
dataHolder.balances.forEach((s, bal) -> {
|
||||
this.balances.put(s, new BigDecimal(bal));
|
||||
});
|
||||
dataHolder.balances.forEach((s, bal) ->
|
||||
this.balances.put(s, new BigDecimal(bal))
|
||||
);
|
||||
|
||||
this.saveDatabase();
|
||||
} catch (FileNotFoundException e) {
|
||||
@ -56,7 +55,7 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
this.balances = new ConcurrentHashMap<>(dataHolder.balances);
|
||||
this.uuidToName = new ConcurrentHashMap<>(dataHolder.uuidToName);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("Failed to load database!", e);
|
||||
throw new RuntimeException("Failed to load database!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +74,7 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@SuppressWarnings({"FieldMayBeFinal", "CanBeFinal"})
|
||||
private static class DataHolderOld {
|
||||
@SerializedName("balances")
|
||||
private Map<String, Double> balances;
|
||||
|
@ -16,7 +16,7 @@ public class EconomableConsole implements Economable {
|
||||
|
||||
@Override
|
||||
public String getUniqueIdentifier() {
|
||||
return "console:" + CONSOLE_UUID.toString();
|
||||
return "console:" + CONSOLE_UUID;
|
||||
}
|
||||
|
||||
public static boolean isConsole(Economable economable) {
|
||||
|
@ -18,6 +18,6 @@ public class EconomableGeneric implements Economable {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.uniqueIdentifier.substring(16);
|
||||
return this.uniqueIdentifier.substring(16); // FIXME: Why 16?
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ public final class PlayerUtils {
|
||||
return player;
|
||||
}
|
||||
|
||||
//noinspection ReuseOfLocalVariable
|
||||
player = Bukkit.getServer().getPlayer(playerNameOrUUID);
|
||||
|
||||
if (player == null) {
|
||||
|
@ -105,13 +105,15 @@ public class SaneEconomyConfiguration {
|
||||
/**
|
||||
* Convert one EconomyStorageBackend to another.
|
||||
* Right now, this just consists of converting all player balances. Data in the old backend is kept.
|
||||
* Why is this in here?
|
||||
* @param oldBackend Old backend
|
||||
* @param newBackend New backend
|
||||
*/
|
||||
private void convertBackends(EconomyStorageBackend oldBackend, EconomyStorageBackend newBackend) {
|
||||
oldBackend.getAllBalances().forEach((uniqueId, balance) -> {
|
||||
newBackend.setBalance(new EconomableGeneric(uniqueId), balance);
|
||||
});
|
||||
oldBackend.getAllBalances().forEach((uniqueId, balance) ->
|
||||
newBackend.setBalance(new EconomableGeneric(uniqueId), balance)
|
||||
);
|
||||
|
||||
newBackend.waitUntilFlushed();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ public final class WebUtils {
|
||||
|
||||
return out.toString();
|
||||
} catch (IOException e) {
|
||||
SaneEconomy.logger().warning("Failed to get contents of URL " + url);
|
||||
throw new RuntimeException("Failed to get URL contents!", e);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class MySQLConnection {
|
||||
private static final Logger LOGGER = Logger.getLogger("MySQLConnection");
|
||||
public static final int FIVE_SECONDS = 5000;
|
||||
private final DatabaseCredentials dbCredentials;
|
||||
private final SaneDatabase saneDatabase;
|
||||
|
||||
@ -79,7 +80,7 @@ public class MySQLConnection {
|
||||
public void waitUntilFlushed() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (!this.saneDatabase.areAllTransactionsDone()) {
|
||||
if ((System.currentTimeMillis() - startTime) > 5000) {
|
||||
if ((System.currentTimeMillis() - startTime) > FIVE_SECONDS) {
|
||||
LOGGER.warning("Took too long to flush all transactions - something has probably hung :(");
|
||||
break;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class CurrencyTest {
|
||||
@Test
|
||||
public void testCurrencyFormat() {
|
||||
Currency currency = new Currency("test dollar", "test dollars", new DecimalFormat("0.00"));
|
||||
Assert.assertEquals(currency.formatAmount(new BigDecimal(1.0D)), "1.00 test dollar");
|
||||
Assert.assertEquals(currency.formatAmount(new BigDecimal(1337.0D)), "1337.00 test dollars");
|
||||
Assert.assertEquals(currency.formatAmount(new BigDecimal("1.0")), "1.00 test dollar");
|
||||
Assert.assertEquals(currency.formatAmount(new BigDecimal("1337.0")), "1337.00 test dollars");
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ public class EconomableTest {
|
||||
@Test
|
||||
public void testWrapFaction() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Economable economable = Economable.wrap(String.format("faction-%s", uuid.toString()));
|
||||
Economable economable = Economable.wrap(String.format("faction-%s", uuid));
|
||||
Assert.assertEquals(economable.getClass(), EconomableFaction.class);
|
||||
Assert.assertEquals(economable.getUniqueIdentifier(), String.format("faction:%s", uuid.toString()));
|
||||
Assert.assertEquals(economable.getUniqueIdentifier(), String.format("faction:%s", uuid));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,7 +45,7 @@ public class EconomyManagerTest {
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerOne));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
|
||||
this.economyManager.setBalance(playerOne, new BigDecimal(100.0));
|
||||
this.economyManager.setBalance(playerOne, new BigDecimal("100.0"));
|
||||
|
||||
// Now one should have an account, but two should not
|
||||
Assert.assertTrue(this.economyManager.accountExists(playerOne));
|
||||
@ -56,7 +56,7 @@ public class EconomyManagerTest {
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
|
||||
// One should be able to transfer to two
|
||||
Assert.assertSame(this.economyManager.transact(new Transaction(this.economyManager.getCurrency(), playerOne, playerTwo, new BigDecimal(50.0), TransactionReason.PLAYER_PAY)).getStatus(), TransactionResult.Status.SUCCESS);
|
||||
Assert.assertSame(this.economyManager.transact(new Transaction(this.economyManager.getCurrency(), playerOne, playerTwo, new BigDecimal("50.0"), TransactionReason.PLAYER_PAY)).getStatus(), TransactionResult.Status.SUCCESS);
|
||||
|
||||
// One should now have only 50 left, two should have 50 now
|
||||
SaneEcoAssert.assertEquals("Player one should have 50 dollars", new BigDecimal("50.00"), this.economyManager.getBalance(playerOne));
|
||||
|
@ -34,6 +34,7 @@ import java.util.logging.Logger;
|
||||
* Created by appledash on 7/15/17.
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class MockServer implements Server {
|
||||
public static MockServer instance;
|
||||
|
||||
@ -501,12 +502,12 @@ public class MockServer implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedServerIcon loadServerIcon(File file) throws Exception {
|
||||
public CachedServerIcon loadServerIcon(File file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) throws Exception {
|
||||
public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user