2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.storage;
|
2020-10-27 18:14:34 +00:00
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.Plex;
|
|
|
|
import dev.plex.PlexBase;
|
2020-10-27 18:14:34 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.DriverManager;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2020-10-29 02:10:47 +00:00
|
|
|
public class SQLConnection extends PlexBase
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
|
|
|
private Connection connection;
|
|
|
|
|
|
|
|
public Connection getCon()
|
|
|
|
{
|
2020-10-28 03:49:56 +00:00
|
|
|
String host = plugin.config.getString("data.central.hostname");
|
|
|
|
int port = plugin.config.getInt("data.central.port");
|
|
|
|
String username = plugin.config.getString("data.central.user");
|
|
|
|
String password = plugin.config.getString("data.central.password");
|
|
|
|
String database = plugin.config.getString("data.central.db");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite"))
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
|
|
|
connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
|
2020-10-29 02:10:47 +00:00
|
|
|
plugin.setStorageType(StorageType.SQLITE);
|
2020-10-27 18:14:34 +00:00
|
|
|
}
|
2020-10-29 02:35:14 +00:00
|
|
|
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
2020-10-29 02:35:14 +00:00
|
|
|
Class.forName("org.mariadb.jdbc.Driver");
|
|
|
|
connection = DriverManager.getConnection("jdbc:mariadb://" + host + ":" + port + "/" + database, username, password);
|
2021-01-03 07:21:15 +00:00
|
|
|
Plex.get().setStorageType(StorageType.MARIADB);
|
2020-10-27 18:14:34 +00:00
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
2020-10-29 02:35:14 +00:00
|
|
|
catch (SQLException | ClassNotFoundException throwables)
|
2020-10-28 03:49:56 +00:00
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
throwables.printStackTrace();
|
|
|
|
}
|
2020-10-27 20:12:38 +00:00
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
try
|
|
|
|
{
|
2020-10-28 04:11:23 +00:00
|
|
|
if (connection != null)
|
|
|
|
{
|
2020-11-10 04:53:45 +00:00
|
|
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (" +
|
|
|
|
"`uuid` VARCHAR(46) NOT NULL, " +
|
|
|
|
"`name` VARCHAR(18), " +
|
|
|
|
"`login_msg` VARCHAR(70), " +
|
|
|
|
"`prefix` VARCHAR(45), " +
|
|
|
|
"`rank` VARCHAR(20), " +
|
|
|
|
"`ips` VARCHAR(2000), " +
|
|
|
|
"`coins` BIGINT, " +
|
|
|
|
"`vanished` BOOLEAN, " +
|
2022-02-07 05:53:57 +00:00
|
|
|
"`commandspy` BOOLEAN, " +
|
2020-11-10 04:53:45 +00:00
|
|
|
"PRIMARY KEY (`uuid`));").execute();
|
|
|
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `bans` (" +
|
2022-02-04 21:25:40 +00:00
|
|
|
"`banID` VARCHAR(46), " +
|
|
|
|
"`uuid` VARCHAR(46) NOT NULL, " +
|
|
|
|
"`banner` VARCHAR(46), " +
|
|
|
|
"`ip` VARCHAR(2000), " +
|
|
|
|
"`reason` VARCHAR(256), " +
|
|
|
|
"`enddate` BIGINT, " +
|
|
|
|
"`active` BOOLEAN, " +
|
|
|
|
"PRIMARY KEY (`banID`)" +
|
2020-11-10 02:47:03 +00:00
|
|
|
");").execute();
|
2020-10-28 04:11:23 +00:00
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
catch (SQLException throwables)
|
|
|
|
{
|
2020-10-27 20:12:38 +00:00
|
|
|
throwables.printStackTrace();
|
|
|
|
}
|
2020-10-27 18:14:34 +00:00
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
}
|