Add SQLITE & Bugfix
Add: SQLITE as storage medium Change: The MYSQL connection has been slightly optimized Fix: The command 'gui-item slot <number>' dat not set the item to the right place?
This commit is contained in:
@@ -17,6 +17,9 @@ import de.jatitv.commandguiv2.Spigot.Main;
|
||||
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
|
||||
import de.jatitv.commandguiv2.Spigot.config.config.ConfigCreate;
|
||||
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.SQLITE;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.YML;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||
@@ -26,6 +29,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class Load {
|
||||
@@ -108,7 +112,8 @@ public class Load {
|
||||
}
|
||||
|
||||
send.console(prefix + " §8-------------------------------");
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
MySQL.main();
|
||||
send.console(prefix + " §2Storage medium §6MySQL §2is used.");
|
||||
try {
|
||||
@@ -126,9 +131,26 @@ public class Load {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
break;
|
||||
case YML:
|
||||
send.console(prefix + " §2Storage medium §6YML §2is used.");
|
||||
break;
|
||||
default:
|
||||
case SQLITE:
|
||||
try {
|
||||
SQLITE.main();
|
||||
send.console(prefix + " §2Storage medium §6SQLITE §2is used.");
|
||||
SQLITE.query("CREATE TABLE IF NOT EXISTS `gui-item` (" +
|
||||
"UUID TEXT NOT NULL," +
|
||||
"Name TEXT NOT NULL," +
|
||||
"Status INTEGER NOT NULL DEFAULT 1," +
|
||||
"Slot INTEGER," +
|
||||
"PRIMARY KEY(UUID)" +
|
||||
");");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (Main.PaPi) {
|
||||
send.console(prefix + " §2PlaceholderAPI successfully connected!");
|
||||
|
@@ -35,7 +35,6 @@ public class Metrics {
|
||||
int pluginId = Util.getBstatsID(); // <-- Replace with the id of your plugin!
|
||||
Metrics metrics = new Metrics(Main.plugin, pluginId);
|
||||
metrics.addCustomChart(new Metrics.SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin)));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("storage_type_mysql", () -> SelectConfig.Storage));
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
|
@@ -0,0 +1,135 @@
|
||||
package de.jatitv.commandguiv2.Spigot.system.database;
|
||||
|
||||
import de.jatitv.commandguiv2.Spigot.Main;
|
||||
import de.jatitv.commandguiv2.Util;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SQLITE {
|
||||
protected static String url;
|
||||
private static Connection con;
|
||||
|
||||
public static void main() throws SQLException {
|
||||
long long_ = System.currentTimeMillis();
|
||||
File directory = new File(Main.getPath() + "/Storage");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdir();
|
||||
}
|
||||
url = "jdbc:sqlite:" + Main.plugin.getDataFolder() + "/Storage/data.db";
|
||||
con = DriverManager.getConnection(url);
|
||||
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Datenbank erfolgreich verbunden." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
DatabaseMetaData dbmd = con.getMetaData();
|
||||
}
|
||||
|
||||
public static void query(String query) {
|
||||
|
||||
send.debug(Main.plugin, query);
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute(query);
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void query(ArrayList<String> queryList) {
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
for (String query : queryList) {
|
||||
send.debug(Main.plugin, query);
|
||||
stmt.addBatch(query);
|
||||
}
|
||||
stmt.executeBatch();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static HashMap<String, ArrayList<String>> selectAll(String query) {
|
||||
send.debug(Main.plugin, query);
|
||||
HashMap<String, ArrayList<String>> Result = new HashMap<>();
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query);
|
||||
int columns = rs.getMetaData().getColumnCount();
|
||||
while (rs.next()) {
|
||||
ArrayList<String> columnList = new ArrayList<>();
|
||||
for (int i = 1; i <= columns; i++) {
|
||||
columnList.add(rs.getString(i));
|
||||
}
|
||||
Result.put(rs.getString(1), columnList);
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
public static String select(String query) {
|
||||
send.debug(Main.plugin, query);
|
||||
String Ausgabe = "";
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
Ausgabe = String.valueOf(rs.getString(1));
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
return Ausgabe;
|
||||
}
|
||||
|
||||
public static int count(String query) {
|
||||
send.debug(Main.plugin, query);
|
||||
int count = 0;
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static ArrayList<String> selectRow(String query) {
|
||||
send.debug(Main.plugin, query);
|
||||
ArrayList<String> Result = new ArrayList<>();
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query);
|
||||
int columns = rs.getMetaData().getColumnCount();
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= columns; i++) {
|
||||
Result.add(rs.getString(i));
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
public static void close() throws SQLException {
|
||||
if (con != null) con.close();
|
||||
}
|
||||
}
|
@@ -7,65 +7,112 @@ import org.bukkit.entity.Player;
|
||||
public class Select_Database {
|
||||
|
||||
public static void nameCheck(Player player) {
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
|
||||
}
|
||||
switch (SelectConfig.Storage){
|
||||
case MYSQL:
|
||||
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
|
||||
break;
|
||||
case YML:
|
||||
|
||||
break;
|
||||
case SQLITE:
|
||||
default:
|
||||
SQLITE.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void setSlot(Player player, Integer slot) {
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
|
||||
} else {
|
||||
YML.setGuiitemSlot(player, slot);
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
|
||||
break;
|
||||
case YML:
|
||||
YML.setGuiitemSlot(player, slot);
|
||||
break;
|
||||
case SQLITE:
|
||||
default:
|
||||
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "','" + slot + "') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setItemStatusTrue(Player player) {
|
||||
Events.useItemHashMap.replace(player, true);
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';");
|
||||
} else {
|
||||
YML.setGuiitemOn(player);
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';");
|
||||
break;
|
||||
case YML:
|
||||
YML.setGuiitemOn(player);
|
||||
break;
|
||||
case SQLITE:
|
||||
default:
|
||||
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Status` = '1';");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setItemStatusFalse(Player player) {
|
||||
Events.useItemHashMap.replace(player, false);
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';");
|
||||
} else {
|
||||
YML.setGuiitemOff(player);
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';");
|
||||
break;
|
||||
case YML:
|
||||
YML.setGuiitemOff(player);
|
||||
break;
|
||||
case SQLITE:
|
||||
default:
|
||||
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
|
||||
+ "', '0') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Status` = '0';");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean selectItemStatus(Player player) {
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) {
|
||||
if (MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';").equals("1")) {
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
String result = MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result == null || result.equals("")){
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return YML.selectGuiitemOn(player);
|
||||
}
|
||||
return result.equals("1");
|
||||
case YML:
|
||||
return YML.selectGuiitemOn(player);
|
||||
case SQLITE:
|
||||
default:
|
||||
String result2 = SQLITE.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result2 == null || result2.equals("")){
|
||||
return true;
|
||||
}
|
||||
return result2.equals("1");
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer selectSlot(Player player) {
|
||||
if (SelectConfig.Storage.equals("MYSQL")) {
|
||||
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) {
|
||||
if (MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';") != "null") {
|
||||
return Integer.valueOf(MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';"));
|
||||
} else return null;
|
||||
} else return null;
|
||||
|
||||
} else {
|
||||
return YML.selectSlot(player);
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
String result = MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result == null || result.equals("")|| result.equals("null")){
|
||||
return null;
|
||||
}
|
||||
return Integer.parseInt(result);
|
||||
case YML:
|
||||
return YML.selectSlot(player);
|
||||
case SQLITE:
|
||||
default:
|
||||
String result2 = SQLITE.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result2 == null || result2.equals("") || result2.equals("null")){
|
||||
return null;
|
||||
}
|
||||
return Integer.parseInt(result2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,7 @@
|
||||
package de.jatitv.commandguiv2.Spigot.system.database;
|
||||
|
||||
public enum StorageType {
|
||||
MYSQL,
|
||||
SQLITE,
|
||||
YML
|
||||
}
|
Reference in New Issue
Block a user