From a8b9524238b59b23bcae2cd14a9add802a48682a Mon Sep 17 00:00:00 2001 From: Butzlabben Date: Fri, 23 Aug 2019 15:17:10 +0200 Subject: [PATCH] Fixed #34 --- pom.xml | 2 +- .../java/de/butzlabben/world/WorldSystem.java | 17 +++++++++++------ .../butzlabben/world/util/PlayerPositions.java | 6 +++--- ...aseRepository.java => DatabaseProvider.java} | 6 +++--- .../world/util/database/MysqlConnection.java | 7 +++++-- .../world/util/database/SqliteConnection.java | 1 + ...bben.world.wrapper.GeneratorSettingsTest.xml | 16 ++++++++-------- 7 files changed, 32 insertions(+), 23 deletions(-) rename src/main/java/de/butzlabben/world/util/database/{DatabaseRepository.java => DatabaseProvider.java} (78%) diff --git a/pom.xml b/pom.xml index 11fa957..5a4a32e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.butzlabben.world WorldSystem - 2.4.7 + 2.4.7.1 UTF-8 diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index 434a8fe..7df4a3c 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -7,8 +7,9 @@ import de.butzlabben.world.command.WorldSettingsCommands; import de.butzlabben.world.config.*; import de.butzlabben.world.listener.*; import de.butzlabben.world.util.PapiExtension; +import de.butzlabben.world.util.PlayerPositions; import de.butzlabben.world.util.VersionUtil; -import de.butzlabben.world.util.database.DatabaseRepository; +import de.butzlabben.world.util.database.DatabaseProvider; import de.butzlabben.world.wrapper.AsyncCreatorAdapter; import de.butzlabben.world.wrapper.CreatorAdapter; import de.butzlabben.world.wrapper.SystemWorld; @@ -90,12 +91,19 @@ public class WorldSystem extends JavaPlugin { @Override public void onEnable() { - //Set right version + // Set right version if (VersionUtil.getVersion() >= 13) is1_13Plus = true; createConfigs(); + // Establish database connection + DatabaseProvider.getInstance().getUtil().connect(); + + // Fix for #34 + // Check if tables exist and create them if necessary. + PlayerPositions.getInstance().checkTables(); + PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new PlayerListener(), this); pm.registerEvents(new BlockListener(), this); @@ -137,9 +145,6 @@ public class WorldSystem extends JavaPlugin { framework.registerCommands(new WorldAdministrateCommand()); - // Establish database connection - DatabaseRepository.getInstance().getUtil().connect(); - System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID)); @@ -184,7 +189,7 @@ public class WorldSystem extends JavaPlugin { } // Close database connection - DatabaseRepository.getInstance().getUtil().close(); + DatabaseProvider.getInstance().getUtil().close(); Bukkit.getConsoleSender() .sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version); diff --git a/src/main/java/de/butzlabben/world/util/PlayerPositions.java b/src/main/java/de/butzlabben/world/util/PlayerPositions.java index c157ceb..309e8b3 100644 --- a/src/main/java/de/butzlabben/world/util/PlayerPositions.java +++ b/src/main/java/de/butzlabben/world/util/PlayerPositions.java @@ -3,7 +3,7 @@ package de.butzlabben.world.util; import com.google.common.base.Preconditions; import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.util.database.DatabaseRepository; +import de.butzlabben.world.util.database.DatabaseProvider; import de.butzlabben.world.util.database.DatabaseUtil; import lombok.Getter; import org.bukkit.Bukkit; @@ -24,7 +24,7 @@ public class PlayerPositions { @Getter private static PlayerPositions instance = new PlayerPositions(); - private final DatabaseUtil util = DatabaseRepository.getInstance().getUtil(); + private final DatabaseUtil util = DatabaseProvider.getInstance().getUtil(); private PlayerPositions() { @@ -190,7 +190,7 @@ public class PlayerPositions { } } - private void checkTables() { + public void checkTables() { if (!util.isConnectionAvailable()) return; diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseRepository.java b/src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java similarity index 78% rename from src/main/java/de/butzlabben/world/util/database/DatabaseRepository.java rename to src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java index a868a92..8c05f01 100644 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseRepository.java +++ b/src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java @@ -3,14 +3,14 @@ package de.butzlabben.world.util.database; import de.butzlabben.world.config.PluginConfig; import lombok.Getter; -public class DatabaseRepository { +public class DatabaseProvider { @Getter - private static DatabaseRepository instance = new DatabaseRepository(); + private static DatabaseProvider instance = new DatabaseProvider(); @Getter private final DatabaseUtil util; - private DatabaseRepository() { + private DatabaseProvider() { String dbType = PluginConfig.getDatabaseType(); if (dbType.equalsIgnoreCase("sqlite")) util = new SqliteConnection(); diff --git a/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java b/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java index ff95c8e..5e57d86 100644 --- a/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java +++ b/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java @@ -1,9 +1,11 @@ package de.butzlabben.world.util.database; import de.butzlabben.world.config.PluginConfig; +import org.bukkit.Bukkit; import java.sql.DriverManager; import java.sql.SQLException; +import java.util.logging.Level; public class MysqlConnection extends DatabaseConnection { @@ -12,14 +14,15 @@ public class MysqlConnection extends DatabaseConnection { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { - System.out.println("[WorldSystem | MySQL] Drivers are not working properly"); + Bukkit.getLogger().log(Level.SEVERE,"[WorldSystem | MySQL] Drivers are not working properly"); return; } try { connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + user + "&password=" + password); + Bukkit.getLogger().log(Level.INFO, "[WorldSystem | MySQL] Connected to remote MySQL database"); } catch (SQLException e) { - System.out.println("[WorldSystem | MySQL] Failed to connect with given server:"); + Bukkit.getLogger().log(Level.SEVERE,"[WorldSystem | MySQL] Failed to connect with given server:"); e.printStackTrace(); } } diff --git a/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java b/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java index 9080d1c..c481f9a 100644 --- a/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java +++ b/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java @@ -29,6 +29,7 @@ public class SqliteConnection extends DatabaseConnection { } try { connection = DriverManager.getConnection("jdbc:sqlite:" + file); + Bukkit.getLogger().log(Level.INFO, "[WorldSystem | SQLite] Connected to local file database"); } catch (SQLException e) { Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Failed to connect with given server:"); e.printStackTrace(); diff --git a/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml b/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml index 3cdc368..3b8cd33 100644 --- a/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml +++ b/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml @@ -1,5 +1,5 @@ - + @@ -7,7 +7,7 @@ - + @@ -18,20 +18,20 @@ - - + + - + - + @@ -47,7 +47,7 @@ - + @@ -61,5 +61,5 @@ - + \ No newline at end of file