you can call me a god
mongodb storing is done
This commit is contained in:
spacerocket62
2020-10-27 13:12:38 -07:00
parent 5162f3fcfb
commit d4cf8b7414
13 changed files with 353 additions and 12 deletions

View File

@ -24,7 +24,7 @@ public class MongoConnection
int port = plugin.getConfig().getInt("data.central.port");
String username = plugin.getConfig().getString("data.central.user");
String password = plugin.getConfig().getString("data.central.password");
String database = plugin.getConfig().getString("data.central.database");
String database = plugin.getConfig().getString("data.central.db");
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;

View File

@ -0,0 +1,33 @@
package me.totalfreedom.plex.storage;
import me.totalfreedom.plex.Plex;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class RedisConnection
{
private JedisPool pool;
private Jedis jedis;
public JedisPool openPool()
{
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
this.pool = new JedisPool(new JedisPoolConfig(), Plex.get().getConfig().getString("data.side.hostname"), Plex.get().getConfig().getInt("data.side.port"));
Thread.currentThread().setContextClassLoader(previous);
return pool;
}
public Jedis getJedis()
{
this.jedis = pool.getResource();
if (Plex.get().getConfig().getBoolean("data.side.auth"))
{
jedis.auth(Plex.get().getConfig().getString("data.side.password"));
}
return jedis;
}
}

View File

@ -1,6 +1,7 @@
package me.totalfreedom.plex.storage;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.util.PlexLog;
import java.io.File;
import java.sql.Connection;
@ -19,7 +20,7 @@ public class SQLConnection
int port = plugin.getConfig().getInt("data.central.port");
String username = plugin.getConfig().getString("data.central.user");
String password = plugin.getConfig().getString("data.central.password");
String database = plugin.getConfig().getString("data.central.database");
String database = plugin.getConfig().getString("data.central.db");
try {
if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("sqlite"))
@ -30,11 +31,27 @@ public class SQLConnection
else if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mysql"))
{
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
Plex.get().setStorageType(StorageType.MONGO);
Plex.get().setStorageType(StorageType.SQL);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
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" +
"\tPRIMARY KEY (`uuid`)\n" +
");").execute();
PlexLog.log("Successfully created table `players`!");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return connection;
}