diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
index b591cdc..da8b3fe 100644
--- a/.idea/sqldialects.xml
+++ b/.idea/sqldialects.xml
@@ -2,7 +2,9 @@
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9817b38..c9b48a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,13 +6,13 @@
2.0-BETA-SNAPSHOT
- scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git
- scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git
- git@github.com:GeorgH93/Bukkit_Minepacks.git
+ scm:git:git@github.com:GeorgH93/Minepacks.git
+ scm:git:git@github.com:GeorgH93/Minepacks.git
+ git@github.com:GeorgH93/Minepacks.git
GitHub
- https://github.com/GeorgH93/Bukkit_Minepacks/issues
+ https://github.com/GeorgH93/Minepacks/issues
jenkins
diff --git a/resources/config.yml b/resources/config.yml
index 211d75c..bf9dd77 100644
--- a/resources/config.yml
+++ b/resources/config.yml
@@ -29,7 +29,7 @@ AllowedGameModes: [ "SURVIVAL" ]
# Defines how long a player have to wait till he can reopen his backpack.
# Time is in seconds. Values < 1 disable the cooldown.
CommandCooldown: -1
-# If enabled whe cooldown will be synced between servers (bungeecord network). It will also prevent players from leaving and joining to bypass the cooldown.
+# If enabled whe cooldown will be synced between servers (BungeeCord network). It will also prevent players from leaving and joining to bypass the cooldown.
SyncCooldown: false
# Controls for the auto pickup on full inventory function
diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java
index 66bf9f2..166328d 100644
--- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java
+++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java
@@ -17,11 +17,14 @@
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
+import at.pcgamingfreaks.ConsoleColor;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.OnDisconnect;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.UnCacheStrategie;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
+import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
+import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -69,20 +72,36 @@ public void close()
unCacheStrategie.close();
}
- public static Database getDatabase(Minepacks Plugin)
+ public static Database getDatabase(Minepacks plugin)
{
Database database;
- switch(Plugin.config.getDatabaseType().toLowerCase())
+ switch(plugin.config.getDatabaseType().toLowerCase())
{
case "mysql":
- database = new MySQL(Plugin); break;
+ database = new MySQL(plugin); break;
case "flat":
case "file":
case "files":
- database = new Files(Plugin); break;
+ database = new Files(plugin); break;
+ case "external":
+ case "global":
+ case "shared":
+ DatabaseConnectionPool pool = PluginLib.getInstance().getDatabaseConnectionPool();
+ if(pool == null)
+ {
+ plugin.getLogger().warning(ConsoleColor.RED + "The shared connection pool is not initialized correctly!" + ConsoleColor.RESET);
+ return null;
+ }
+ switch(pool.getDatabaseType().toLowerCase())
+ {
+ case "mysql": database = new MySQLShared(plugin, pool); break;
+ case "sqlite": database = new SQLiteShared(plugin, pool); break;
+ default: plugin.getLogger().warning(ConsoleColor.RED + "The database type of the shared pool is currently not supported!" + ConsoleColor.RESET); return null;
+ }
+ break;
case "sqlite":
default:
- database = new SQLite(Plugin);
+ database = new SQLite(plugin);
}
database.init();
return database;
diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java
new file mode 100644
index 0000000..348a07e
--- /dev/null
+++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 GeorgH93
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package at.pcgamingfreaks.Minepacks.Bukkit.Database;
+
+import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
+import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
+
+import com.zaxxer.hikari.HikariConfig;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class MySQLShared extends MySQL
+{
+ private DatabaseConnectionPool pool;
+
+ protected MySQLShared(Minepacks minepacks, DatabaseConnectionPool pool)
+ {
+ super(minepacks);
+ this.pool = pool;
+ }
+
+ @Override
+ protected HikariConfig getPoolConfig()
+ {
+ return null;
+ }
+
+ @Override
+ @NotNull
+ public Connection getConnection() throws SQLException
+ {
+ return pool.getConnection();
+ }
+}
\ No newline at end of file
diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java
new file mode 100644
index 0000000..f5d48c2
--- /dev/null
+++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2018 GeorgH93
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package at.pcgamingfreaks.Minepacks.Bukkit.Database;
+
+import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
+import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
+
+import com.zaxxer.hikari.HikariConfig;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SQLiteShared extends SQLite
+{
+ private DatabaseConnectionPool pool;
+
+ protected SQLiteShared(Minepacks minepacks, DatabaseConnectionPool pool)
+ {
+ super(minepacks);
+ this.pool = pool;
+ }
+
+ @Override
+ protected HikariConfig getPoolConfig()
+ {
+ return null;
+ }
+
+ @Override
+ public @NotNull Connection getConnection() throws SQLException
+ {
+ Connection connection = pool.getConnection();
+ try(Statement statement = connection.createStatement())
+ {
+ statement.execute("PRAGMA foreign_keys = ON"); // We need foreign keys!
+ }
+ return connection;
+ }
+}
\ No newline at end of file