mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-06 17:36:43 +00:00
packs is going to yell at me
Added custom Config classes Added Mongo / SQLite / SQL switches Setup main config.yml
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
package me.totalfreedom.plex.storage;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientURI;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.Morphia;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
|
||||
public class MongoConnection
|
||||
{
|
||||
|
||||
// USE MORPHIA API FOR MONGO <3
|
||||
|
||||
private Plex plugin = Plex.get();
|
||||
|
||||
public Datastore getDatastore()
|
||||
{
|
||||
if (!plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mongodb"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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");
|
||||
String database = plugin.getConfig().getString("data.central.database");
|
||||
|
||||
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
|
||||
|
||||
MongoClient client = new MongoClient(new MongoClientURI(connectionString));
|
||||
|
||||
Morphia morphia = new Morphia();
|
||||
Datastore datastore = morphia.createDatastore(client, database);
|
||||
|
||||
datastore.getMapper().addMappedClass(PlexPlayer.class);
|
||||
datastore.ensureIndexes();
|
||||
|
||||
plugin.setStorageType(StorageType.MONGO);
|
||||
|
||||
return datastore;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
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");
|
||||
String database = plugin.getConfig().getString("data.central.database");
|
||||
|
||||
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);
|
||||
Plex.get().setStorageType(StorageType.MONGO);
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package me.totalfreedom.plex.storage;
|
||||
|
||||
public enum StorageType
|
||||
{
|
||||
MONGO, SQL, SQLITE;
|
||||
|
||||
}
|
Reference in New Issue
Block a user