2020-10-27 18:14:34 +00:00
|
|
|
package me.totalfreedom.plex.storage;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.DriverManager;
|
|
|
|
import java.sql.SQLException;
|
2020-10-28 03:49:56 +00:00
|
|
|
import me.totalfreedom.plex.Plex;
|
2020-10-29 02:10:47 +00:00
|
|
|
import me.totalfreedom.plex.PlexBase;
|
2020-10-27 18:14:34 +00:00
|
|
|
|
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-28 03:49:56 +00:00
|
|
|
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mysql"))
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
|
|
|
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
|
2020-10-27 20:12:38 +00:00
|
|
|
Plex.get().setStorageType(StorageType.SQL);
|
2020-10-27 18:14:34 +00:00
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
catch (SQLException throwables)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
|
|
|
"\t`uuid` VARCHAR(46),\n" +
|
|
|
|
"\t`name` VARCHAR(18),\n" +
|
2020-10-29 02:10:47 +00:00
|
|
|
"\t`login_msg` VARCHAR,\n" +
|
|
|
|
"\t`prefix` VARCHAR,\n" +
|
|
|
|
"\t`rank` VARCHAR,\n" +
|
|
|
|
"\t`ips` VARCHAR,\n" +
|
|
|
|
"\t`coins` INT\n" +
|
|
|
|
//"\tPRIMARY KEY (`uuid`)\n" +
|
2020-10-28 04:11:23 +00:00
|
|
|
");").execute();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|