From 84eba0a156a2431f38f6edf4e6a33467141def06 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 9 Nov 2021 10:29:12 +0100 Subject: [PATCH 1/5] Fix ELO SQL --- SpigotCore_Main/src/de/steamwar/sql/Elo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Elo.java b/SpigotCore_Main/src/de/steamwar/sql/Elo.java index b52f215..f077199 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Elo.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Elo.java @@ -28,7 +28,7 @@ public class Elo { public static int getElo(int userId, String gameMode){ return get.select(rs -> { if(rs.next()) - return rs.getInt("id"); + return rs.getInt("Elo"); return 1000; }, userId, gameMode); } From 2e528918bbe9b1321bf1048da0723ccb3f100b67 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 9 Nov 2021 10:45:18 +0100 Subject: [PATCH 2/5] Reimplement auto reconnect --- SpigotCore_Main/src/de/steamwar/sql/SQL.java | 33 ++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQL.java b/SpigotCore_Main/src/de/steamwar/sql/SQL.java index 74e68b9..0cffba5 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SQL.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SQL.java @@ -19,6 +19,7 @@ package de.steamwar.sql; +import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException; import de.steamwar.core.Core; import org.bukkit.configuration.file.YamlConfiguration; @@ -33,27 +34,27 @@ public class SQL { private SQL(){} private static Connection con; - private static String url; - private static String user; - private static String password; + private static final String URL; + private static final String USER; + private static final String PASSWORD; - static{ + static { File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml"); YamlConfiguration config = YamlConfiguration.loadConfiguration(file); if(!file.exists()) throw new SecurityException("SQL-ConfigFile not found!"); - url = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE"); - user = config.getString("USER"); - password = config.getString("PASSWORD"); + URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE"); + USER = config.getString("USER"); + PASSWORD = config.getString("PASSWORD"); connect(); } private static void connect() { try { - con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password); + con = DriverManager.getConnection(URL + "?useServerPrepStmts=true", USER, PASSWORD); } catch (SQLException e) { throw new SecurityException("Could not start SQL connection", e); } @@ -95,7 +96,8 @@ public class SQL { return false; } } - + + @Deprecated static void update(String qry, Object... objects) { try { prepare(qry, objects).executeUpdate(); @@ -105,7 +107,8 @@ public class SQL { } } - static ResultSet select(String qry, Object... objects){ + @Deprecated + static ResultSet select(String qry, Object... objects) { try { return prepare(qry, objects).executeQuery(); } catch (SQLException e) { @@ -114,7 +117,8 @@ public class SQL { } } - static Blob blob(){ + @Deprecated + static Blob blob() { try { return con.createBlob(); } catch (SQLException e) { @@ -123,7 +127,8 @@ public class SQL { } } - private static PreparedStatement prepare(String qry, Object... objects) throws SQLException{ + @Deprecated + private static PreparedStatement prepare(String qry, Object... objects) throws SQLException { PreparedStatement st = con.prepareStatement(qry); for(int i = 0; i < objects.length; i++){ st.setObject(i+1, objects[i]); @@ -168,8 +173,10 @@ public class SQL { try { setObjects(objects); return runnable.run(); - } catch (SQLException e) { + } catch (CommunicationsException e) { reset(); + return prepare(runnable, objects); + } catch (SQLException e) { throw new SecurityException("Could not execute SQL statement", e); } } From d3ebbafedaa7f5b96030eac9098d8d072c58b164 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 9 Nov 2021 10:49:41 +0100 Subject: [PATCH 3/5] Prevent infinite recursion --- SpigotCore_Main/src/de/steamwar/sql/SQL.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQL.java b/SpigotCore_Main/src/de/steamwar/sql/SQL.java index 0cffba5..fc8c7a2 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SQL.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SQL.java @@ -171,11 +171,14 @@ public class SQL { private synchronized T prepare(SQLRunnable runnable, Object... objects) { try { - setObjects(objects); - return runnable.run(); - } catch (CommunicationsException e) { - reset(); - return prepare(runnable, objects); + try { + setObjects(objects); + return runnable.run(); + } catch (CommunicationsException e) { + reset(); + setObjects(objects); + return runnable.run(); + } } catch (SQLException e) { throw new SecurityException("Could not execute SQL statement", e); } From dba1df777a938da6516e83ba1344e5531a3ccebc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 Nov 2021 14:08:18 +0100 Subject: [PATCH 4/5] Update SWCommand --- .../src/de/steamwar/command/SWCommand.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index e6926da..6ea2ba4 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -51,8 +51,9 @@ public abstract class SWCommand { if (!initialized) { createMapping(); } - if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false; - commandHelpList.stream().anyMatch(s -> s.invoke(sender, args)); + if (!commandList.stream().anyMatch(s -> s.invoke(sender, args))) { + commandHelpList.stream().anyMatch(s -> s.invoke(sender, args)); + } return false; } @@ -87,13 +88,13 @@ public abstract class SWCommand { add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { if (!anno.help()) return; if (parameters.length != 2) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking parameters or has too many"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking parameters or has too many"); } if (!parameters[parameters.length - 1].isVarArgs()) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument"); } if (parameters[parameters.length - 1].getType().getComponentType() != String.class) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>())); From ad221d21f6a8af206ad98cb7e778ac6f1e095674 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 10 Nov 2021 14:10:40 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=E2=80=9ESpigotCore=5FMain/src/de/steamwar/?= =?UTF-8?q?command/SWCommand.java=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 6ea2ba4..1db2988 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -115,7 +115,7 @@ public abstract class SWCommand { } String name = mapper != null ? mapper.value() : clazz.getTypeName(); if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) { - Bukkit.getLogger().log(Level.WARNING, "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'"); + Bukkit.getLogger().log(Level.WARNING, () -> "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'"); return; } } @@ -142,15 +142,15 @@ public abstract class SWCommand { Parameter[] parameters = method.getParameters(); if (!parameterTester.test(parameters.length)) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking parameters or has too many"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking parameters or has too many"); return; } if (firstParameter && !CommandSender.class.isAssignableFrom(parameters[0].getType())) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'"); return; } if (returnType != null && method.getReturnType() != returnType) { - Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); + Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); return; } Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters));