diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/SaneEconomy.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/SaneEconomy.java index c4c4641..8807c53 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/SaneEconomy.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/SaneEconomy.java @@ -36,7 +36,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy { private TransactionLogger transactionLogger; private GithubVersionChecker versionChecker; - private final Map COMMANDS = new HashMap() { + private final Map commands = new HashMap() { { 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."); } diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/Currency.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/Currency.java index d402a10..c474ea6 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/Currency.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/Currency.java @@ -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. diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendCaching.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendCaching.java index 6899f70..6a407ee 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendCaching.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendCaching.java @@ -44,9 +44,9 @@ public abstract class EconomyStorageBackendCaching implements EconomyStorageBack public void reloadTopPlayerBalances() { Map 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); } diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendJSON.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendJSON.java index d85cfc6..eefff68 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendJSON.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendJSON.java @@ -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 balances; diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableConsole.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableConsole.java index 4873788..ea1eb02 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableConsole.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableConsole.java @@ -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) { diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableGeneric.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableGeneric.java index 0116e92..8e24870 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableGeneric.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/economable/EconomableGeneric.java @@ -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? } } diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/PlayerUtils.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/PlayerUtils.java index bbf9f5b..2b21af1 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/PlayerUtils.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/PlayerUtils.java @@ -26,6 +26,7 @@ public final class PlayerUtils { return player; } + //noinspection ReuseOfLocalVariable player = Bukkit.getServer().getPlayer(playerNameOrUUID); if (player == null) { diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/SaneEconomyConfiguration.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/SaneEconomyConfiguration.java index 06c89f9..0dd2397 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/SaneEconomyConfiguration.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/SaneEconomyConfiguration.java @@ -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(); } diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/WebUtils.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/WebUtils.java index 4369086..e3ee139 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/WebUtils.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/WebUtils.java @@ -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); } } diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java index edcfb63..c7e3736 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java @@ -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; } diff --git a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/CurrencyTest.java b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/CurrencyTest.java index bf9ac82..acdc7c7 100644 --- a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/CurrencyTest.java +++ b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/CurrencyTest.java @@ -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"); } } diff --git a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomableTest.java b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomableTest.java index bab6e6b..e6dbb3a 100644 --- a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomableTest.java +++ b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomableTest.java @@ -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 diff --git a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomyManagerTest.java b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomyManagerTest.java index 30c3543..feb2a75 100644 --- a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomyManagerTest.java +++ b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/EconomyManagerTest.java @@ -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)); diff --git a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/mock/MockServer.java b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/mock/MockServer.java index 3e04fb5..2e600f3 100644 --- a/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/mock/MockServer.java +++ b/SaneEconomyCore/src/test/java/org/appledash/saneeconomy/test/mock/MockServer.java @@ -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; }