mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-21 07:59:19 +00:00
Initial MySQL data work
This commit is contained in:
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
||||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||||
@@ -78,6 +79,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
Settings.load(loader.load().node(""));
|
Settings.load(loader.load().node(""));
|
||||||
WardrobeSettings.load(loader.load().node("wardrobe"));
|
WardrobeSettings.load(loader.load().node("wardrobe"));
|
||||||
|
DatabaseSettings.load(loader.load().node("database-settings"));
|
||||||
} catch (ConfigurateException e) {
|
} catch (ConfigurateException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.config;
|
||||||
|
|
||||||
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
public class DatabaseSettings {
|
||||||
|
|
||||||
|
//private static final String DATABASE_SETTINGS_PATH = "cosmetic-settings";
|
||||||
|
private static final String DATABASE_TYPE_PATH = "type";
|
||||||
|
private static final String MYSQL_DATABASE_SETTINGS = "mysql";
|
||||||
|
|
||||||
|
private static final String MYSQL_DATABASE = "database";
|
||||||
|
private static final String MYSQL_PASSWORD = "password";
|
||||||
|
private static final String MYSQL_HOST = "host";
|
||||||
|
private static final String MYSQL_USER = "user";
|
||||||
|
private static final String MYSQL_PORT = "port";
|
||||||
|
|
||||||
|
private static String databaseType;
|
||||||
|
private static String database;
|
||||||
|
private static String password;
|
||||||
|
private static String host;
|
||||||
|
private static String username;
|
||||||
|
private static int port;
|
||||||
|
|
||||||
|
public static void load(ConfigurationNode source) {
|
||||||
|
//ConfigurationNode databaseSettings = source.node(DATABASE_SETTINGS_PATH);
|
||||||
|
|
||||||
|
databaseType = source.node(DATABASE_TYPE_PATH).getString();
|
||||||
|
|
||||||
|
ConfigurationNode mySql = source.node(MYSQL_DATABASE_SETTINGS);
|
||||||
|
|
||||||
|
database = mySql.node(MYSQL_DATABASE).getString();
|
||||||
|
password = mySql.node(MYSQL_PASSWORD).getString();
|
||||||
|
host = mySql.node(MYSQL_HOST).getString();
|
||||||
|
username = mySql.node(MYSQL_USER).getString();
|
||||||
|
port = mySql.node(MYSQL_PORT).getInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDatabaseType() {
|
||||||
|
return databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.database;
|
package com.hibiscusmc.hmccosmetics.database;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
||||||
import com.hibiscusmc.hmccosmetics.database.types.InternalData;
|
import com.hibiscusmc.hmccosmetics.database.types.InternalData;
|
||||||
|
import com.hibiscusmc.hmccosmetics.database.types.MySQLData;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -11,10 +14,20 @@ public class Database {
|
|||||||
private static Data data;
|
private static Data data;
|
||||||
|
|
||||||
private static InternalData INTERNAL_DATA = new InternalData();
|
private static InternalData INTERNAL_DATA = new InternalData();
|
||||||
|
private static MySQLData MYSQL_DATA = new MySQLData();
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
this.data = INTERNAL_DATA;
|
String databaseType = DatabaseSettings.getDatabaseType();
|
||||||
// To be replaced when multiple systems exist
|
switch (databaseType) {
|
||||||
|
case "INTERNAL_DATA":
|
||||||
|
data = INTERNAL_DATA;
|
||||||
|
case "MYSQL":
|
||||||
|
data = MYSQL_DATA;
|
||||||
|
default:
|
||||||
|
data = INTERNAL_DATA;
|
||||||
|
HMCCosmeticsPlugin.getInstance().getLogger().severe("No Valid Datatype detected! Defaulting to internal data...");
|
||||||
|
}
|
||||||
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.database.types;
|
package com.hibiscusmc.hmccosmetics.database.types;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Data {
|
public class Data {
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
// Override
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(CosmeticUser user) {
|
public void save(CosmeticUser user) {
|
||||||
// Override
|
// Override
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public CosmeticUser get(UUID uniqueId) {
|
||||||
// Override
|
// Override
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.database.types;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MySQLData extends Data {
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
// TODO
|
||||||
|
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(CosmeticUser user) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CosmeticUser get(UUID uniqueId) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
default-menu: main
|
default-menu: main
|
||||||
|
database-settings:
|
||||||
|
type: INTERNAL # INTERNAL, MYSQL
|
||||||
|
mysql:
|
||||||
|
database: database
|
||||||
|
password: cherryBomb
|
||||||
|
port: 3306
|
||||||
|
host: localhost
|
||||||
|
user: username
|
||||||
cosmetic-settings:
|
cosmetic-settings:
|
||||||
require-empty-helmet: false
|
require-empty-helmet: false
|
||||||
require-empty-off-hand: false
|
require-empty-off-hand: false
|
||||||
|
|||||||
Reference in New Issue
Block a user