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>
<artifactId>CommandGUI_V2</artifactId>
<version>2.7.3</version>
<version>2.7.4</version>
<packaging>jar</packaging>
<name>CommandGUI</name>

View File

@ -1,5 +1,7 @@
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.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -33,6 +35,7 @@ public class BListener implements Listener {
}
}
} catch (IOException e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
e.printStackTrace();
}
}

View File

@ -27,6 +27,9 @@ import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
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.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
@ -291,6 +294,7 @@ public class BMetrics {
// Send the data
sendData(data);
} catch (Exception e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
// Something went wrong! :(
if (logErrors) {
errorLogger.accept("Could not submit bStats metrics data", e);

View File

@ -50,18 +50,25 @@ public class GUIListener implements Listener {
|| (Main.PaPi && player.getOpenInventory().getTitle().equals(Replace.replace(prefix, player, GUICode + gui.guiName)))) {
e.setCancelled(true);
for (Slot slot : gui.slots) {
execute(e,slot,player, gui);
}
}
}
}
private static void execute(InventoryClickEvent e, Slot slot, Player player, Gui gui){
Function function = Main.functionHashMap.get(slot.function);
if (e.getSlot() != slot.slot) continue;
if (slot.permission && !player.hasPermission(slot.permissionToSee)) continue;
if (e.getSlot() != slot.slot) return;
if (slot.permission && !player.hasPermission(slot.permissionToSee)) return;
if (slot.permission && !player.hasPermission(slot.permissionToUse)) {
player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, function.name))
.replace("[perm]", slot.permissionToUse));
continue;
return;
}
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 (!slot.enable) return;
if (function.cost_Enable) {
if (function.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) {
@ -86,9 +93,6 @@ public class GUIListener implements Listener {
}
}
}
}
}
}
private static void execute(Function function, Slot slot, Player player, InventoryClickEvent e, Gui gui) {
if (function.togglePermission) togglePerm(function, gui, player);

View File

@ -61,24 +61,6 @@ public class CmdExecuter_GUITab implements CommandExecutor, TabCompleter {
} else sender.sendMessage(SelectMessages.NoPermissionForCommand
.replace("[cmd]", "/commandgui admin").replace("[perm]", "commandgui.admin"));
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":
if (args.length == 3) {
if (sender.hasPermission("commandgui.giveitem.other")) {

View File

@ -70,7 +70,7 @@ public class Commands {
Main.plugin.reloadConfig();
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!");
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();

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.guis.Gui;
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.minecraftVersion.MCVersion;
import org.bukkit.configuration.file.YamlConfiguration;
@ -28,6 +29,8 @@ public class Obj_Select {
File[] fileArray = f.listFiles();
for (File config_gui : fileArray) {
try {
String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
if (sub.equals(".yml")) {
String key = config_gui.getName().replace(".yml", "");
@ -67,9 +70,9 @@ public class Obj_Select {
String permUse = yamlConfiguration_gui.getString("Slots." + slotKey + ".Permission.Use");
Slot slot = new Slot(slotNumber, enable, function, permRequired,
Objects.requireNonNull(permSee).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
permSee.replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
.replace("[slotname]", slotKey.toLowerCase()),
Objects.requireNonNull(permUse).replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
permUse.replace("[function]", key).replace("[slot]", String.valueOf(slotNumber + 1))
.replace("[slotname]", slotKey.toLowerCase()));
slots.add(slot);
}
@ -80,11 +83,12 @@ public class Obj_Select {
CmdExecuter_GUITab.arg1.put(config_gui.getName()
.replace(".yml", ""), "commandgui.gui." + key);
try {
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 {
private static Plugin plugin = Main.plugin;
private static final Plugin plugin = Main.plugin;
public static void debugmsg() {
send.debug(plugin,"§5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
send.debug(plugin,"§3Bukkit Version: §e" + Bukkit.getBukkitVersion());
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
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.SelectDatabase;
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.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -182,10 +183,14 @@ public class Load {
"COLLATE='utf8mb4_general_ci'" +
"ENGINE=InnoDB" +
";");
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN IF NOT EXISTS `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
} catch (Exception e) {
Util.sendTryCatch(Load.class, e.getStackTrace()[0]);
e.printStackTrace();
}
try {
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
} catch (SQLException e) {
}
break;
case YML:
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");

View File

@ -3,7 +3,9 @@ package de.jatitv.commandguiv2.Spigot.system.database;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.Bukkit;
import java.sql.*;
import java.time.ZoneId;
@ -40,27 +42,40 @@ public class MySQL {
send.console(Main.prefix + " §4MYSQL not connected." + " §7- §e" + (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");
}
public static void query(String query) {
public static void query(String query) throws SQLException {
if (ds == null) {
return;
}
send.debug(Main.plugin, query);
try (Connection con = ds.getConnection()) {
Connection con = ds.getConnection();
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 (Connection con = ds.getConnection()) {
public static void query(ArrayList<String> queryList) throws SQLException {
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
for (String query : queryList) {
send.debug(Main.plugin, query);
@ -68,9 +83,6 @@ public class MySQL {
}
stmt.executeBatch();
stmt.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
}
}

View File

@ -1,9 +1,15 @@
package de.jatitv.commandguiv2.Spigot.system.database;
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.system.Load;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.entity.Player;
import java.sql.SQLException;
public class SelectDatabase {
private static StorageType Storage;
@ -19,7 +25,12 @@ public class SelectDatabase {
public static void nameCheck(Player player) {
switch (Storage) {
case MYSQL:
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;
case YML:
@ -34,8 +45,13 @@ public class SelectDatabase {
public static void setSlot(Player player, Integer slot) {
switch (Storage) {
case MYSQL:
try {
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;
case YML:
YML.setGuiitemSlot(player, slot);
@ -52,8 +68,13 @@ public class SelectDatabase {
Events.useItemHashMap.replace(player.getName(), true);
switch (Storage) {
case MYSQL:
try {
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;
case YML:
YML.setGuiitemOn(player);
@ -70,8 +91,13 @@ public class SelectDatabase {
Events.useItemHashMap.replace(player.getName(), false);
switch (Storage) {
case MYSQL:
try {
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;
case YML:
YML.setGuiitemOff(player);

View File

@ -1,6 +1,8 @@
package de.jatitv.commandguiv2.Spigot.system.database;
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 org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -45,6 +47,7 @@ public class YML {
try {
yamlConfigurationStorage.save(storage);
} catch (IOException e) {
Util.sendTryCatch(Obj_Select.class, e.getStackTrace()[0]);
e.printStackTrace();
}
}

View File

@ -1,5 +1,8 @@
package de.jatitv.commandguiv2;
import de.jatitv.commandguiv2.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send;
public class Util {
private static Integer configVersion = 5;
private static double requiredT2CodeLibVersion = 11.8;
@ -36,4 +39,8 @@ public class Util {
public static Integer getConfigVersion() {
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]
commandgui-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