2020-10-27 18:14:34 +00:00
|
|
|
package me.totalfreedom.plex.storage;
|
|
|
|
|
|
|
|
import me.totalfreedom.plex.Plex;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.DriverManager;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
public class SQLConnection
|
|
|
|
{
|
|
|
|
private Plex plugin = Plex.get();
|
|
|
|
|
|
|
|
private Connection connection;
|
|
|
|
|
|
|
|
public Connection getCon()
|
|
|
|
{
|
|
|
|
String host = plugin.getConfig().getString("data.central.hostname");
|
|
|
|
int port = plugin.getConfig().getInt("data.central.port");
|
|
|
|
String username = plugin.getConfig().getString("data.central.user");
|
|
|
|
String password = plugin.getConfig().getString("data.central.password");
|
2020-10-27 20:12:38 +00:00
|
|
|
String database = plugin.getConfig().getString("data.central.db");
|
2020-10-27 18:14:34 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("sqlite"))
|
|
|
|
{
|
|
|
|
connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
|
|
|
|
Plex.get().setStorageType(StorageType.SQLITE);
|
|
|
|
}
|
|
|
|
else if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mysql"))
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
} catch (SQLException throwables) {
|
|
|
|
throwables.printStackTrace();
|
|
|
|
}
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
|
|
|
"\t`uuid` VARCHAR(46),\n" +
|
|
|
|
"\t`name` VARCHAR(18),\n" +
|
|
|
|
"\t`login_msg` VARCHAR(256),\n" +
|
|
|
|
"\t`prefix` VARCHAR(30),\n" +
|
|
|
|
"\t`rank` VARCHAR(256),\n" +
|
|
|
|
"\t`ips` VARCHAR(65535),\n" +
|
2020-10-27 21:30:57 +00:00
|
|
|
"\t`coins` BIGINT,\n" +
|
2020-10-27 20:12:38 +00:00
|
|
|
"\tPRIMARY KEY (`uuid`)\n" +
|
|
|
|
");").execute();
|
|
|
|
} catch (SQLException throwables) {
|
|
|
|
throwables.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:14:34 +00:00
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|