Added basic database (untested)
This commit is contained in:
parent
c538a68160
commit
f09061f6b6
|
|
@ -2,6 +2,7 @@ package com.alttd;
|
||||||
|
|
||||||
import com.alttd.GUI.GUIListener;
|
import com.alttd.GUI.GUIListener;
|
||||||
import com.alttd.commands.CommandManager;
|
import com.alttd.commands.CommandManager;
|
||||||
|
import com.alttd.commands.database.Database;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
import com.alttd.config.VillagerConfig;
|
import com.alttd.config.VillagerConfig;
|
||||||
import com.alttd.config.WorthConfig;
|
import com.alttd.config.WorthConfig;
|
||||||
|
|
@ -28,6 +29,7 @@ public class VillagerUI extends JavaPlugin {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
VillagerConfig.reload();
|
VillagerConfig.reload();
|
||||||
WorthConfig.reload();
|
WorthConfig.reload();
|
||||||
|
Database.init();
|
||||||
getLogger().info("--------------------------------------------------");
|
getLogger().info("--------------------------------------------------");
|
||||||
getLogger().info("Villager UI started");
|
getLogger().info("Villager UI started");
|
||||||
getLogger().info("--------------------------------------------------");
|
getLogger().info("--------------------------------------------------");
|
||||||
|
|
|
||||||
49
src/main/java/com/alttd/commands/database/Database.java
Normal file
49
src/main/java/com/alttd/commands/database/Database.java
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.alttd.commands.database;
|
||||||
|
|
||||||
|
import com.alttd.VillagerUI;
|
||||||
|
import com.alttd.config.Config;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
|
||||||
|
public static Connection connection = null;
|
||||||
|
|
||||||
|
public static void init() { //Not static so we know for sure it loads on time
|
||||||
|
String url = "jdbc:" + Config.DRIVER +
|
||||||
|
"://" + Config.IP +
|
||||||
|
":" + Config.PORT +
|
||||||
|
"/" + Config.DATABASE_NAME +
|
||||||
|
"?autoReconnect=true&useSSL=false";
|
||||||
|
try {
|
||||||
|
connection = DriverManager.getConnection(url, Config.USERNAME, Config.PASSWORD);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
VillagerUI.getInstance().getLogger().severe("Connection to database failed!");
|
||||||
|
connection = null;
|
||||||
|
VillagerUI.getInstance().getLogger().severe("Shutting down VillagerUI");
|
||||||
|
Bukkit.getPluginManager().disablePlugin(VillagerUI.getInstance());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tables
|
||||||
|
createUserPointsTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void createUserPointsTable() {
|
||||||
|
try {
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS user_points(" +
|
||||||
|
"UUID varchar 36 NOT NULL, " +
|
||||||
|
"Points int NOT NULL, " +
|
||||||
|
"PRIMARY KEY (UUID)" +
|
||||||
|
")";
|
||||||
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@ public final class Config extends AbstractConfig {
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
static int version;
|
static int version;
|
||||||
|
|
||||||
public Config() {
|
public Config() {
|
||||||
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "config.yml");
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "config.yml");
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +27,22 @@ public final class Config extends AbstractConfig {
|
||||||
config.readConfig(Config.class, null);
|
config.readConfig(Config.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String DRIVER = "mysql";
|
||||||
|
public static String IP = "localhost";
|
||||||
|
public static String PORT = "3306";
|
||||||
|
public static String DATABASE_NAME = "VillagerShopUI";
|
||||||
|
public static String USERNAME = "";
|
||||||
|
public static String PASSWORD = "";
|
||||||
|
|
||||||
|
private static void loadDatabase() {
|
||||||
|
DRIVER = config.getString("database.driver", DRIVER);
|
||||||
|
IP = config.getString("database.ip", IP);
|
||||||
|
PORT = config.getString("database.port", PORT);
|
||||||
|
DATABASE_NAME = config.getString("database.name", DATABASE_NAME);
|
||||||
|
USERNAME = config.getString("database.username", USERNAME);
|
||||||
|
PASSWORD = config.getString("database.password", PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
public static String INITIAL_VILLAGER_WINDOW = "<trader> price: <percentage>%";
|
public static String INITIAL_VILLAGER_WINDOW = "<trader> price: <percentage>%";
|
||||||
public static String BUY_WINDOW = "<trader> price: <percentage>%";
|
public static String BUY_WINDOW = "<trader> price: <percentage>%";
|
||||||
public static String SELL_WINDOW = "<trader> price: <percentage>%";
|
public static String SELL_WINDOW = "<trader> price: <percentage>%";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user