2.7.4 | MySQL Bugfix

MySQL Bugfix
```
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`' at line 1
```
And minor code changes
This commit is contained in:
JaTiTV 2022-05-28 21:46:04 +02:00
parent ed810f31d7
commit 19822f7024
14 changed files with 194 additions and 242 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId> <artifactId>CommandGUI_V2</artifactId>
<version>2.7.3</version> <version>2.7.4</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandGUI</name> <name>CommandGUI</name>

View File

@ -1,5 +1,7 @@
package de.jatitv.commandguiv2.Bungee; package de.jatitv.commandguiv2.Bungee;
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
import de.jatitv.commandguiv2.Util;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -33,6 +35,7 @@ public class BListener implements Listener {
} }
} }
} catch (IOException e) { } catch (IOException e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -27,6 +27,9 @@ import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
import de.jatitv.commandguiv2.Util;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.ConfigurationProvider;
@ -291,6 +294,7 @@ public class BMetrics {
// Send the data // Send the data
sendData(data); sendData(data);
} catch (Exception e) { } catch (Exception e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
// Something went wrong! :( // Something went wrong! :(
if (logErrors) { if (logErrors) {
errorLogger.accept("Could not submit bStats metrics data", e); errorLogger.accept("Could not submit bStats metrics data", e);

View File

@ -50,42 +50,46 @@ public class GUIListener implements Listener {
|| (Main.PaPi && player.getOpenInventory().getTitle().equals(Replace.replace(prefix, player, GUICode + gui.guiName)))) { || (Main.PaPi && player.getOpenInventory().getTitle().equals(Replace.replace(prefix, player, GUICode + gui.guiName)))) {
e.setCancelled(true); e.setCancelled(true);
for (Slot slot : gui.slots) { for (Slot slot : gui.slots) {
Function function = Main.functionHashMap.get(slot.function); execute(e,slot,player, gui);
if (e.getSlot() != slot.slot) continue; }
if (slot.permission && !player.hasPermission(slot.permissionToSee)) continue; }
if (slot.permission && !player.hasPermission(slot.permissionToUse)) { }
player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, function.name)) }
.replace("[perm]", slot.permissionToUse));
continue;
}
if (e.getCurrentItem().getType() == ItemVersion.getHead() || e.getCurrentItem().getType() == ItemVersion.getGreenWool().getType() ||
e.getCurrentItem().getType() == ItemVersion.getRedWool().getType() ||
e.getCurrentItem().getType() == Material.valueOf(function.item.toUpperCase().replace(".", "_"))) {
if (!slot.enable) continue;
if (function.cost_Enable) {
if (function.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) {
if (!Vault.buy(prefix, player, function.price)) { private static void execute(InventoryClickEvent e, Slot slot, Player player, Gui gui){
new BukkitRunnable() { Function function = Main.functionHashMap.get(slot.function);
@Override if (e.getSlot() != slot.slot) return;
public void run() { if (slot.permission && !player.hasPermission(slot.permissionToSee)) return;
player.closeInventory(); if (slot.permission && !player.hasPermission(slot.permissionToUse)) {
} player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, function.name))
}.runTaskLater(plugin, 1L); .replace("[perm]", slot.permissionToUse));
player.sendMessage(SelectMessages.No_money); return;
if (SelectConfig.Sound_NoMoney_Enable && SelectConfig.Sound_Enable) }
player.playSound(player.getLocation(), SelectConfig.Sound_NoMoney, 3, 1); if (e.getCurrentItem().getType() == ItemVersion.getHead() || e.getCurrentItem().getType() == ItemVersion.getGreenWool().getType() ||
} else { e.getCurrentItem().getType() == ItemVersion.getRedWool().getType() ||
player.sendMessage(SelectMessages.Buy_msg.replace("[itemname]", Replace.replace(prefix, function.name)) e.getCurrentItem().getType() == Material.valueOf(function.item.toUpperCase().replace(".", "_"))) {
.replace("[price]", function.price + " " + SelectConfig.Currency)); if (!slot.enable) return;
execute(function, slot, player, e, gui); if (function.cost_Enable) {
} if (function.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) {
if (!Vault.buy(prefix, player, function.price)) {
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
} }
} else { }.runTaskLater(plugin, 1L);
execute(function, slot, player, e, gui); player.sendMessage(SelectMessages.No_money);
} if (SelectConfig.Sound_NoMoney_Enable && SelectConfig.Sound_Enable)
player.playSound(player.getLocation(), SelectConfig.Sound_NoMoney, 3, 1);
} else {
player.sendMessage(SelectMessages.Buy_msg.replace("[itemname]", Replace.replace(prefix, function.name))
.replace("[price]", function.price + " " + SelectConfig.Currency));
execute(function, slot, player, e, gui);
} }
} }
} else {
execute(function, slot, player, e, gui);
} }
} }
} }

View File

@ -61,24 +61,6 @@ public class CmdExecuter_GUITab implements CommandExecutor, TabCompleter {
} else sender.sendMessage(SelectMessages.NoPermissionForCommand } else sender.sendMessage(SelectMessages.NoPermissionForCommand
.replace("[cmd]", "/commandgui admin").replace("[perm]", "commandgui.admin")); .replace("[cmd]", "/commandgui admin").replace("[perm]", "commandgui.admin"));
break; break;
case "debug":
if (sender.hasPermission("commandgui.admin")) {
Debug.onDebugFile(sender);
/*if (args.length == 2) {
if (args[1].equals("config")) {
Debug.debugmsg();
}
if (args[1].equals("2")) {
send.debug("2");
}
break;
} else Debug.debugmsg();
*/
} else sender.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui admin").replace("[perm]", "commandgui.admin"));
break;
case "give": case "give":
if (args.length == 3) { if (args.length == 3) {
if (sender.hasPermission("commandgui.giveitem.other")) { if (sender.hasPermission("commandgui.giveitem.other")) {

View File

@ -70,7 +70,7 @@ public class Commands {
Main.plugin.reloadConfig(); Main.plugin.reloadConfig();
if (!Objects.equals(SelectDatabase.getStorage().toString(), SelectConfig.storage)) { if (!Objects.equals(SelectDatabase.getStorage().toString(), SelectConfig.storage)) {
if (sender instanceof Player) send.sender(sender, "You have changed the storage medium! To apply this change, you must restart the server!"); if (sender instanceof Player) send.sender(sender, "You have changed the storage medium! To apply this change, you must restart the server!");
send.console("You have changed the storage medium! To apply this change, you must restart the server!"); send.warning(Main.plugin, "You have changed the storage medium! To apply this change, you must restart the server!");
} }
LanguagesCreate.langCreate(); LanguagesCreate.langCreate();

View File

@ -5,6 +5,7 @@ import de.jatitv.commandguiv2.Spigot.cmdManagement.CmdExecuter_GUITab;
import de.jatitv.commandguiv2.Spigot.objects.functions.Function; import de.jatitv.commandguiv2.Spigot.objects.functions.Function;
import de.jatitv.commandguiv2.Spigot.objects.guis.Gui; import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
import de.jatitv.commandguiv2.Spigot.objects.slots.Slot; import de.jatitv.commandguiv2.Spigot.objects.slots.Slot;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion; import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -28,63 +29,66 @@ public class Obj_Select {
File[] fileArray = f.listFiles(); File[] fileArray = f.listFiles();
for (File config_gui : fileArray) { for (File config_gui : fileArray) {
String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
if (sub.equals(".yml")) {
String key = config_gui.getName().replace(".yml", "");
Main.allAliases.add(key);
YamlConfiguration yamlConfiguration_gui = YamlConfiguration.loadConfiguration(config_gui);
Boolean guiEnable = yamlConfiguration_gui.getBoolean("GUI.Enable"); try {
Integer guiLines = yamlConfiguration_gui.getInt("GUI.Lines"); String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
if (yamlConfiguration_gui.getInt("GUI.Lines") > 6) { if (sub.equals(".yml")) {
yamlConfiguration_gui.set("GUI.Lines", 6); String key = config_gui.getName().replace(".yml", "");
} Main.allAliases.add(key);
if (yamlConfiguration_gui.getInt("GUI.Lines") < 1) { YamlConfiguration yamlConfiguration_gui = YamlConfiguration.loadConfiguration(config_gui);
yamlConfiguration_gui.set("GUI.Lines", 1);
}
String guiName = yamlConfiguration_gui.getString("GUI.Name"); Boolean guiEnable = yamlConfiguration_gui.getBoolean("GUI.Enable");
Boolean guiFillItemEnable = yamlConfiguration_gui.getBoolean("GUI.FillItem.Enable"); Integer guiLines = yamlConfiguration_gui.getInt("GUI.Lines");
String guiFillItemItem; if (yamlConfiguration_gui.getInt("GUI.Lines") > 6) {
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) { yamlConfiguration_gui.set("GUI.Lines", 6);
guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.GlassPaneColor"); }
} else guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.Item"); if (yamlConfiguration_gui.getInt("GUI.Lines") < 1) {
yamlConfiguration_gui.set("GUI.Lines", 1);
Boolean commandAliasEnable = yamlConfiguration_gui.getBoolean("Command.Alias");
Boolean commandPermission = yamlConfiguration_gui.getBoolean("Command.Permission.Required");
ArrayList<Slot> slots = new ArrayList<>();
for (String slotKey : yamlConfiguration_gui.getConfigurationSection("Slots").getKeys(false)) {
Integer slotNumber = yamlConfiguration_gui.getInt("Slots." + slotKey + ".Slot") - 1;
Boolean enable = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Enable");
String function = yamlConfiguration_gui.getString("Slots." + slotKey + ".Function");
Function functionCheck = Main.functionHashMap.get(function);
if (functionCheck == null) {
send.error(Main.plugin, "The Function " + function + " in the GUI " + key + " does not exist!");
} }
Boolean permRequired = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Permission.Required");
String permSee = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.See");
String permUse = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.Use");
Slot slot = new Slot(slotNumber, enable, function, permRequired, String guiName = yamlConfiguration_gui.getString("GUI.Name");
Objects.requireNonNull(permSee).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1)) Boolean guiFillItemEnable = yamlConfiguration_gui.getBoolean("GUI.FillItem.Enable");
.replace("[slotname]", slotKey.toLowerCase()), String guiFillItemItem;
Objects.requireNonNull(permUse).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1)) if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
.replace("[slotname]", slotKey.toLowerCase())); guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.GlassPaneColor");
slots.add(slot); } else guiFillItemItem = yamlConfiguration_gui.getString("GUI.FillItem.Item");
}
Gui gui = new Gui(guiEnable, guiLines, guiName, guiFillItemEnable, guiFillItemItem, Boolean commandAliasEnable = yamlConfiguration_gui.getBoolean("Command.Alias");
key, commandAliasEnable, commandPermission, slots); Boolean commandPermission = yamlConfiguration_gui.getBoolean("Command.Permission.Required");
ArrayList<Slot> slots = new ArrayList<>();
for (String slotKey : yamlConfiguration_gui.getConfigurationSection("Slots").getKeys(false)) {
Integer slotNumber = yamlConfiguration_gui.getInt("Slots." + slotKey + ".Slot") - 1;
Boolean enable = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Enable");
String function = yamlConfiguration_gui.getString("Slots." + slotKey + ".Function");
Function functionCheck = Main.functionHashMap.get(function);
if (functionCheck == null) {
send.error(Main.plugin, "The Function " + function + " in the GUI " + key + " does not exist!");
}
Boolean permRequired = yamlConfiguration_gui.getBoolean("Slots." + slotKey + ".Permission.Required");
String permSee = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.See");
String permUse = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.Use");
Slot slot = new Slot(slotNumber, enable, function, permRequired,
permSee.replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
.replace("[slotname]", slotKey.toLowerCase()),
permUse.replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
.replace("[slotname]", slotKey.toLowerCase()));
slots.add(slot);
}
Gui gui = new Gui(guiEnable, guiLines, guiName, guiFillItemEnable, guiFillItemItem,
key, commandAliasEnable, commandPermission, slots);
Main.guiHashMap.put(key, gui);
CmdExecuter_GUITab.arg1.put(config_gui.getName()
.replace(".yml", ""), "commandgui.gui." + key);
Main.guiHashMap.put(key, gui);
CmdExecuter_GUITab.arg1.put(config_gui.getName()
.replace(".yml", ""), "commandgui.gui." + key);
try {
yamlConfiguration_gui.save(config_gui); yamlConfiguration_gui.save(config_gui);
} catch (IOException e) {
e.printStackTrace();
} }
} catch (Exception e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
e.printStackTrace();
} }
} }
} }

View File

@ -15,10 +15,8 @@ import java.util.List;
public class Debug { public class Debug {
private static Plugin plugin = Main.plugin; private static final Plugin plugin = Main.plugin;
public static void debugmsg() { public static void debugmsg() {
send.debug(plugin,"§5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); send.debug(plugin,"§5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
send.debug(plugin,"§3Bukkit Version: §e" + Bukkit.getBukkitVersion()); send.debug(plugin,"§3Bukkit Version: §e" + Bukkit.getBukkitVersion());
send.debug(plugin,"§3NMS Version: §e" + Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit.", "")); send.debug(plugin,"§3NMS Version: §e" + Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit.", ""));
@ -45,52 +43,5 @@ public class Debug {
} }
} }
send.debug(plugin,"§5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); send.debug(plugin,"§5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
public static void onDebugFile(CommandSender sender){
String timeStamp = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss").format(Calendar.getInstance().getTime());
String timeStampcfg = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(Calendar.getInstance().getTime());
send.sender(sender, Main.prefix + " §5Debug file was createt: §e" + Main.getPath() + "\\debug\\commandgui_debug_"+ timeStamp +".yml");
File debug = new File(Main.getPath(), "debug/commandgui_debug_"+ timeStamp +".yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(debug);
set("Time", timeStampcfg, yamlConfiguration);
set("CommandGUI.Version", String.valueOf(plugin.getDescription().getVersion()), yamlConfiguration);
set("Server.Bukkit_Version", String.valueOf(Bukkit.getBukkitVersion()), yamlConfiguration);
set("Server.NMS_Version", String.valueOf(Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit.", "")), yamlConfiguration);
set("Server.Version", String.valueOf(Bukkit.getVersion()), yamlConfiguration);
set("Server.Java", String.valueOf(System.getProperty("java.version")), yamlConfiguration);
set("Server.Worlds", String.valueOf(Bukkit.getServer().getWorlds()), yamlConfiguration);
set("Server.Plugins", String.valueOf(Main.plugins) , yamlConfiguration);
try {
yamlConfiguration.save(debug);
} catch (IOException e) {
send.warning(plugin,e.getMessage());
e.printStackTrace();
}
}
private static void set(String path, String value, YamlConfiguration config){
if (!config.contains(path)) {
config.set(path, value);
}
}
private static void set(String path, Integer value, YamlConfiguration config){
if (!config.contains(path)) {
config.set(path, value);
}
}
private static void set(String path, Boolean value, YamlConfiguration config){
if (!config.contains(path)) {
config.set(path, value);
}
}
private static void set(String path, List value, YamlConfiguration config){
if (!config.contains(path)) {
config.set(path, value);
}
} }
} }

View File

@ -20,6 +20,7 @@ import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.database.SQLITE; import de.jatitv.commandguiv2.Spigot.system.database.SQLITE;
import de.jatitv.commandguiv2.Spigot.system.database.SelectDatabase; import de.jatitv.commandguiv2.Spigot.system.database.SelectDatabase;
import de.jatitv.commandguiv2.Spigot.system.database.StorageType; import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion; import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -177,15 +178,19 @@ public class Load {
" `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," + " `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," +
" `Status` INT(1) NOT NULL DEFAULT '1'," + " `Status` INT(1) NOT NULL DEFAULT '1'," +
" `Slot` INT(1) NULL DEFAULT NULL," + " `Slot` INT(1) NULL DEFAULT NULL," +
" UNIQUE INDEX `UUID` (`UUID`)" + " UNIQUE INDEX `UUID` (`UUID`)" +
")" + ")" +
"COLLATE='utf8mb4_general_ci'" + "COLLATE='utf8mb4_general_ci'" +
"ENGINE=InnoDB" + "ENGINE=InnoDB" +
";"); ";");
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN IF NOT EXISTS `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
} catch (Exception e) { } catch (Exception e) {
Util.sendTryCatch(Load.class, e.getStackTrace()[0]);
e.printStackTrace(); e.printStackTrace();
} }
try {
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
} catch (SQLException e) {
}
break; break;
case YML: case YML:
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used."); send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");
@ -194,17 +199,17 @@ public class Load {
case SQLITE: case SQLITE:
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used."); send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");
try { try {
SQLITE.main(); SQLITE.main();
SQLITE.query("CREATE TABLE IF NOT EXISTS `gui-item` (" + SQLITE.query("CREATE TABLE IF NOT EXISTS `gui-item` (" +
"UUID TEXT NOT NULL," + "UUID TEXT NOT NULL," +
"Name TEXT NOT NULL," + "Name TEXT NOT NULL," +
"Status INTEGER NOT NULL DEFAULT 1," + "Status INTEGER NOT NULL DEFAULT 1," +
"Slot INTEGER," + "Slot INTEGER," +
"PRIMARY KEY(UUID)" + "PRIMARY KEY(UUID)" +
");"); ");");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
break; break;
} }
} }

View File

@ -3,7 +3,9 @@ package de.jatitv.commandguiv2.Spigot.system.database;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.Bukkit;
import java.sql.*; import java.sql.*;
import java.time.ZoneId; import java.time.ZoneId;
@ -40,37 +42,47 @@ public class MySQL {
send.console(Main.prefix + " §4MYSQL not connected." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms"); send.console(Main.prefix + " §4MYSQL not connected." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
send.error(Main.plugin, ex.getMessage() + " --- " + (System.currentTimeMillis() - long_) + "ms"); send.error(Main.plugin, ex.getMessage() + " --- " + (System.currentTimeMillis() - long_) + "ms");
} }
if (SelectConfig.Debug || Main.version.contains("DEV")){
try {
send.warning(Main.plugin, "MySQL DEBUG:");
Connection con = ds.getConnection();
DatabaseMetaData dbmd = con.getMetaData();
Bukkit.getConsoleSender().sendMessage("Metadata of the database:");
Bukkit.getConsoleSender().sendMessage("DB :" + dbmd.getDatabaseProductName());
Bukkit.getConsoleSender().sendMessage("Version :" + dbmd.getDatabaseProductVersion());
Bukkit.getConsoleSender().sendMessage("Driver :" + dbmd.getDriverName());
Bukkit.getConsoleSender().sendMessage(" :" + dbmd.getDriverMajorVersion() + "." + dbmd.getDriverMinorVersion());
Bukkit.getConsoleSender().sendMessage(" :" + dbmd.getDriverVersion());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//Bukkit.getConsoleSender().sendMessage((System.currentTimeMillis() - long_) + "ms"); //Bukkit.getConsoleSender().sendMessage((System.currentTimeMillis() - long_) + "ms");
} }
public static void query(String query) { public static void query(String query) throws SQLException {
if (ds == null) {
if (ds == null){
return; return;
} }
send.debug(Main.plugin, query); send.debug(Main.plugin, query);
try (Connection con = ds.getConnection()) { Connection con = ds.getConnection();
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
stmt.execute(query); stmt.execute(query);
stmt.close(); stmt.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
}
} }
public static void query(ArrayList<String> queryList) { public static void query(ArrayList<String> queryList) throws SQLException {
try (Connection con = ds.getConnection()) { Connection con = ds.getConnection();
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
for (String query : queryList) { for (String query : queryList) {
send.debug(Main.plugin, query); send.debug(Main.plugin, query);
stmt.addBatch(query); stmt.addBatch(query);
}
stmt.executeBatch();
stmt.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
} }
stmt.executeBatch();
stmt.close();
} }

View File

@ -1,9 +1,15 @@
package de.jatitv.commandguiv2.Spigot.system.database; package de.jatitv.commandguiv2.Spigot.system.database;
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events; import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig; import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.Load;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.sql.SQLException;
public class SelectDatabase { public class SelectDatabase {
private static StorageType Storage; private static StorageType Storage;
@ -19,7 +25,12 @@ public class SelectDatabase {
public static void nameCheck(Player player) { public static void nameCheck(Player player) {
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';"); try {
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
} catch (SQLException e) {
Util.sendTryCatch(SelectDatabase.class, e.getStackTrace()[0]);
e.printStackTrace();
}
break; break;
case YML: case YML:
@ -34,8 +45,13 @@ public class SelectDatabase {
public static void setSlot(Player player, Integer slot) { public static void setSlot(Player player, Integer slot) {
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() try {
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';"); MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
} catch (SQLException e) {
Util.sendTryCatch(SelectDatabase.class, e.getStackTrace()[0]);
e.printStackTrace();
}
break; break;
case YML: case YML:
YML.setGuiitemSlot(player, slot); YML.setGuiitemSlot(player, slot);
@ -52,8 +68,13 @@ public class SelectDatabase {
Events.useItemHashMap.replace(player.getName(), true); Events.useItemHashMap.replace(player.getName(), true);
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() try {
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';"); MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';");
} catch (SQLException e) {
Util.sendTryCatch(SelectDatabase.class, e.getStackTrace()[0]);
e.printStackTrace();
}
break; break;
case YML: case YML:
YML.setGuiitemOn(player); YML.setGuiitemOn(player);
@ -70,8 +91,13 @@ public class SelectDatabase {
Events.useItemHashMap.replace(player.getName(), false); Events.useItemHashMap.replace(player.getName(), false);
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() try {
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';"); MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';");
} catch (SQLException e) {
Util.sendTryCatch(SelectDatabase.class, e.getStackTrace()[0]);
e.printStackTrace();
}
break; break;
case YML: case YML:
YML.setGuiitemOff(player); YML.setGuiitemOff(player);

View File

@ -1,6 +1,8 @@
package de.jatitv.commandguiv2.Spigot.system.database; package de.jatitv.commandguiv2.Spigot.system.database;
import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -45,6 +47,7 @@ public class YML {
try { try {
yamlConfigurationStorage.save(storage); yamlConfigurationStorage.save(storage);
} catch (IOException e) { } catch (IOException e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -1,5 +1,8 @@
package de.jatitv.commandguiv2; package de.jatitv.commandguiv2;
import de.jatitv.commandguiv2.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send;
public class Util { public class Util {
private static Integer configVersion = 5; private static Integer configVersion = 5;
private static double requiredT2CodeLibVersion = 11.8; private static double requiredT2CodeLibVersion = 11.8;
@ -36,4 +39,8 @@ public class Util {
public static Integer getConfigVersion() { public static Integer getConfigVersion() {
return configVersion; return configVersion;
} }
public static void sendTryCatch(Class c, StackTraceElement line){
send.error(Main.plugin, c.getName() + " Line: " + line.getLineNumber());
}
} }

View File

@ -21,52 +21,3 @@ commands:
aliases: [cguihelp, guihelp] aliases: [cguihelp, guihelp]
commandgui-item: commandgui-item:
aliases: [gui-item] aliases: [gui-item]
#permissions:
# commandgui.admin:
# description: All permissions from CommandGUI
# default: op
# children:
# commandgui.command: true
# commandgui.get.guiitem.at.login: true
# commandgui.useitem: true
# commandgui.useitem.toggle: true
# commandgui.updatemsg: true
# commandgui.bypass: true
# commandgui.command.info: true
# commandgui.command.give: true
#
# commandgui.player:
# description: All permissions from CommandGUI
# default: op
# children:
# commandgui.command: true
# commandgui.get.guiitem.at.login: true
# commandgui.useitem: true
# commandgui.useitem.toggle: true
#
# commandgui.updatemsg:
# description: Players with this permission get the update message when joining if an update is available
# default: op
# commandgui.command:
# description: Required permission to open GUIs via command
# default: op
# commandgui.get.guiitem.at.login:
# description: Only players with this permission will receive the GUI item
# default: op
# commandgui.useitem:
# description: Required permission to use the GUI Item
# default: op
# commandgui.useitem.toggle:
# description: Required permission to enable/disable the GUI Item for itself (if the function UseItem/AllowToggle is set to true)
# default: op
# commandgui.bypass:
# description: Bypass to open disabled GUIs
# default: op
# commandgui.command.info:
# description: Permission to view CommandGUI info
# default: not op
# commandgui.command.give:
# description: Kommend in V2.1.0
# default: op