diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java b/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java index 5bf63e3..6209029 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java @@ -25,7 +25,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; import java.io.File; -import java.util.logging.Level; public class NickoBukkit extends JavaPlugin { private static NickoBukkit plugin; @@ -66,7 +65,7 @@ public class NickoBukkit extends JavaPlugin { if (!dataStore.getStorage().getProvider().init()) { dataStore.getStorage().setError(true); - getLogger().warning("Failed to open persistence, data will NOT be saved!"); + getLogger().severe("Failed to open persistence, data will NOT be saved!"); } } @@ -78,7 +77,7 @@ public class NickoBukkit extends JavaPlugin { getLogger().info("Loading internals..."); if (getInternals() == null) { - getLogger().log(Level.SEVERE, "Nicko could not find a valid implementation for this server version. Is your server supported?"); + getLogger().severe("Nicko could not find a valid implementation for this server version. Is your server supported?"); dataStore.getStorage().setError(true); getServer().getPluginManager().disablePlugin(this); } @@ -87,7 +86,7 @@ public class NickoBukkit extends JavaPlugin { getLogger().info("Loading persistence..."); if (!dataStore.getStorage().getProvider().init()) { dataStore.getStorage().setError(true); - getLogger().warning("Failed to open persistence, data will NOT be saved!"); + getLogger().severe("Failed to open persistence, data will NOT be saved!"); } mojangAPI = new MojangAPI(this); @@ -97,7 +96,7 @@ public class NickoBukkit extends JavaPlugin { if (localeFileManager.dumpFromLocale(Locale.ENGLISH)) { getLogger().info("Successfully loaded custom language file."); } else { - getLogger().warning("Failed to load custom language file!"); + getLogger().severe("Failed to load custom language file!"); } } @@ -135,7 +134,7 @@ public class NickoBukkit extends JavaPlugin { dataStore.removeAllNames(); dataStore.saveAll(); if (!dataStore.getStorage().getProvider().close()) { - getLogger().warning("Failed to close persistence!"); + getLogger().severe("Failed to close persistence!"); } } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/bungee/BungeeCordSupport.java b/nicko-core/src/main/java/net/artelnatif/nicko/bungee/BungeeCordSupport.java index 6a524ea..f9eaa45 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/bungee/BungeeCordSupport.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/bungee/BungeeCordSupport.java @@ -15,10 +15,10 @@ public class BungeeCordSupport { final Server server = instance.getServer(); final YamlConfiguration config = server.spigot().getConfig(); if (config.getConfigurationSection("settings").getBoolean("bungeecord") && instance.getNickoConfig().isBungeecordSupport()) { - instance.getLogger().severe("Hummm. Your server is hooked to BungeeCord, but it seems"); - instance.getLogger().severe("that BungeeCord support is not enabled inside Nicko."); - instance.getLogger().severe("If this is intentional, you can safely ignore this message."); - instance.getLogger().severe("Otherwise, you can enable BungeeCord support inside Nicko's configuration file."); + instance.getLogger().warning("Hummm. Your server is hooked to BungeeCord, but it seems"); + instance.getLogger().warning("that BungeeCord support is not enabled inside Nicko."); + instance.getLogger().warning("If this is intentional, you can safely ignore this message."); + instance.getLogger().warning("Otherwise, you can enable BungeeCord support inside Nicko's configuration file."); } } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorage.java b/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorage.java index 54bf671..a40673a 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorage.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorage.java @@ -50,7 +50,7 @@ public class SQLStorage extends Storage { statement.executeUpdate(); return new ActionResult<>(); } catch (SQLException e) { - instance.getLogger().warning("Unable to store player. (%s)".formatted(e.getMessage())); + instance.getLogger().warning("Couldn't send SQL Request: " + e.getMessage()); return new ActionResult<>(I18NDict.Error.SQL_ERROR); } } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorageProvider.java b/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorageProvider.java index 8aab9a8..0ac68b1 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorageProvider.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/storage/sql/SQLStorageProvider.java @@ -40,7 +40,7 @@ public class SQLStorageProvider implements StorageProvider { createTable(); return true; } catch (SQLException e) { - e.printStackTrace(); + instance.getLogger().severe("Couldn't establish a connection to the MySQL database: " + e.getMessage()); return false; } } diff --git a/nicko-core/src/test/java/net/artelnatif/nicko/test/storage/BrokenSQLTest.java b/nicko-core/src/test/java/net/artelnatif/nicko/test/storage/BrokenSQLTest.java new file mode 100644 index 0000000..c2e5486 --- /dev/null +++ b/nicko-core/src/test/java/net/artelnatif/nicko/test/storage/BrokenSQLTest.java @@ -0,0 +1,49 @@ +package net.artelnatif.nicko.test.storage; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import be.seeseemelk.mockbukkit.entity.PlayerMock; +import net.artelnatif.nicko.NickoBukkit; +import net.artelnatif.nicko.config.NickoConfiguration; +import net.artelnatif.nicko.disguise.ActionResult; +import net.artelnatif.nicko.disguise.NickoProfile; +import net.artelnatif.nicko.i18n.Locale; +import org.junit.jupiter.api.*; + +public class BrokenSQLTest { + private static ServerMock server; + private static NickoBukkit plugin; + + @BeforeAll + public static void setup() { + final NickoConfiguration config = new NickoConfiguration(null); + config.setLocalStorage(false); + config.setBungeecordSupport(false); + config.setSQLAddress("127.0.0.1"); + config.setSQLUsername("root"); + config.setSQLPassword("INVALID_PASSWORD"); + + server = MockBukkit.mock(); + plugin = MockBukkit.load(NickoBukkit.class, config); + } + + @Test + @DisplayName("Fail to create Tables") + public void createSQLTables() { + Assertions.assertTrue(plugin.getDataStore().getStorage().isError()); + } + + @Test + @DisplayName("Store Player Via SQL") + public void storePlayer() { + final PlayerMock playerMock = server.addPlayer(); + final NickoProfile profile = new NickoProfile("Notch", "Notch", Locale.ENGLISH, true); + final ActionResult storeAction = plugin.getDataStore().getStorage().store(playerMock.getUniqueId(), profile); + Assertions.assertFalse(storeAction.isError()); + } + + @AfterAll + public static void shutdown() { + MockBukkit.unmock(); + } +} \ No newline at end of file