From c1a4a91bb9ca6b6ed47031bb9ddbefe644369dcf Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 16 Dec 2021 17:27:08 +0100 Subject: [PATCH] Bugfixes --- SpigotCore_Main/src/SpigotCore.properties | 86 ++++++++---- .../src/de/steamwar/sql/Punishment.java | 8 +- .../src/de/steamwar/sql/Statement.java | 130 ------------------ 3 files changed, 62 insertions(+), 162 deletions(-) delete mode 100644 SpigotCore_Main/src/de/steamwar/sql/Statement.java diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties index 28628df..b22cee3 100644 --- a/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -17,47 +17,77 @@ # along with this program. If not, see . # -SCHEM_SELECTOR_TITLE={0} auswählen: {1} -SCHEM_SELECTOR_BACK=§eZurück -SCHEM_SELECTOR_DIR=§9Ordner -SCHEM_SELECTOR_RANK=§8Rang {0} -SCHEM_SELECTOR_OWN=§7Eigene Schematics -SCHEM_SELECTOR_PUB=§7Public Schematics -SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen -SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner -SCHEM_SELECTOR_FILTER=§7Filter -SCHEM_SELECTOR_SORTING=§7Sortierung -SCHEM_SELECTOR_SORTING_CURRENT=§7Aktuell: §e{0} +SCHEM_SELECTOR_TITLE={0} ausw�hlen: {1} +SCHEM_SELECTOR_BACK=�eZur�ck +SCHEM_SELECTOR_DIR=�9Ordner +SCHEM_SELECTOR_RANK=�8Rang {0} +SCHEM_SELECTOR_OWN=�7Eigene Schematics +SCHEM_SELECTOR_PUB=�7Public Schematics +SCHEM_SELECTOR_SEL_DIR=�7Ordner ausw�hlen +SCHEM_SELECTOR_NEW_DIR=�7Neuer Ordner +SCHEM_SELECTOR_FILTER=�7Filter +SCHEM_SELECTOR_SORTING=�7Sortierung +SCHEM_SELECTOR_SORTING_CURRENT=�7Aktuell: �e{0} SCHEM_SELECTOR_SORTING_NAME=Name SCHEM_SELECTOR_SORTING_TYPE=Schematic-Typ SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update -SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0} +SCHEM_SELECTOR_SORTING_DIRECTION=�7Richtung: �e{0} SCHEM_SELECTOR_SORTING_ASC=Aufsteigend SCHEM_SELECTOR_SORTING_DSC=Absteigend -SCHEM_SELECTOR_ITEM_NAME=§e{0} -SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0} -SCHEM_SELECTOR_ITEM_REPLACE=§e{0}§7 -SCHEM_SELECTOR_ITEM_LORE_TYPE=§7{0} +SCHEM_SELECTOR_ITEM_NAME=�e{0} +SCHEM_SELECTOR_ITEM_NAME_FILTER=�7{0} +SCHEM_SELECTOR_ITEM_REPLACE=�e{0}�7 +SCHEM_SELECTOR_ITEM_LORE_TYPE=�7{0} SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen SCHEM_SELECTOR_FILTER_TITLE=Filter SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben -SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen... -SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchbegriff: §e{0} +SCHEM_SELECTOR_FILTER_NAME=�7Nach Namen suchen... +SCHEM_SELECTOR_FILTER_NAME_SEARCH=�7Suchbegriff: �e{0} SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben -SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen... -SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0} -SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen... -SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ filtern... -SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0} -SCHEM_SELECTOR_FILTER_MAT=§7Nach Item filtern... -SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0} -SCHEM_SELECTOR_CANCEL=§eAbbrechen -SCHEM_SELECTOR_GO=§eSuchen... +SCHEM_SELECTOR_FILTER_OWNER=�7Nach Besitzer suchen... +SCHEM_SELECTOR_FILTER_OWNER_SEARCH=�7Besitzer: �e{0} +SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ w�hlen... +SCHEM_SELECTOR_FILTER_TYPE=�7Nach Typ filtern... +SCHEM_SELECTOR_FILTER_TYPE_SEARCH=�7Typ: �e{0} +SCHEM_SELECTOR_FILTER_MAT=�7Nach Item filtern... +SCHEM_SELECTOR_FILTER_MAT_SEARCH=�7Item: �e{0} +SCHEM_SELECTOR_CANCEL=�eAbbrechen +SCHEM_SELECTOR_GO=�eSuchen... SCHEM_SELECTOR_SCHEMATIC=Schematic SCHEM_SELECTOR_DIRECTORY=Ordner SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner -MATERIAL_SELECTOR_TITLE=Material auswählen \ No newline at end of file +MATERIAL_SELECTOR_TITLE=Material ausw�hlen + +BAN_TEAM={0} §e{1} §7wurde von §e{2} {3} §e§lgebannt§8. §7Grund§8: §f{4} +BAN_PERMA=§7Du bist §epermanent §e§lgebannt§8. §7Grund§8: §e{0} +BAN_UNTIL=§7Du bist §ebis zum {0} §e§lgebannt§8. §7Grund§8: §e{1} +UNBAN_ERROR=§cDer Spieler ist nicht gebannt. +UNBAN=§7Du hast §e{0} §e§lentbannt. + +MUTE_TEAM={0} §e{1} §7wurde von §e{2} {3} §e§lgemuted§8. §7Grund§8: §f{4} +MUTE_PERMA=§7Du bist §epermanent §e§lgemuted§8. §7Grund§8: §e{0} +MUTE_UNTIL=§7Du bist §ebis zum {0} §e§lgemuted§8. §7Grund§8: §e{1} +UNMUTE_ERROR=§cDer Spieler ist nicht gemuted. +UNMUTE=§7Du hast §e{0} §e§lentmuted. + +NOSCHEMSHARING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicverteilen ausgeschlossen§8. §7Grund§8: §f{4} +NOSCHEMSHARING_PERMA=§7Du bist §epermanent §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0} +NOSCHEMSHARING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1} +UNNOSCHEMSHARING_ERROR=§cDer Spieler ist nicht vom Verteilen von Schematics ausgeschlossen. +UNNOSCHEMSHARING=§e{0} §7darf nun wieder §e§lSchematics verteilen§8. + +NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematiceinsenden ausgeschlossen§8. §7Grund§8: §f{4} +NOSCHEMSUBMITTING_PERMA=§7Du bist §epermanent §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0} +NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1} +UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen. +UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis einsenden§8. + +NODEVSERVER_TEAM={0} §e{1} §7hat §e{2} §7mit Grund §f{4}§7 zu generft und hat daher §e§lDevserververbot §7erhalten§8, §e{3} +NODEVSERVER_PERMA=§7Du bist §epermanent §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{0} +NODEVSERVER_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{1} +UNNODEVSERVER_ERROR=§cDer Spieler ist nicht vom Devserver ausgeschlossen. +UNNODEVSERVER=§e{0} §7darf nun wieder dem §e§lDevserver beitreten§8. \ No newline at end of file diff --git a/SpigotCore_Main/src/de/steamwar/sql/Punishment.java b/SpigotCore_Main/src/de/steamwar/sql/Punishment.java index 19b0296..70caaed 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Punishment.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Punishment.java @@ -30,10 +30,10 @@ import java.util.*; public class Punishment { - private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1"); - private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)"); - private static final Statement getAllPunishments = new Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC"); - private static final Statement insert = new Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)"); + private static final SQL.Statement getPunishment = new SQL.Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1"); + private static final SQL.Statement getPunishments = new SQL.Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)"); + private static final SQL.Statement getAllPunishments = new SQL.Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC"); + private static final SQL.Statement insert = new SQL.Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)"); public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { return getPunishment.select(rs -> { diff --git a/SpigotCore_Main/src/de/steamwar/sql/Statement.java b/SpigotCore_Main/src/de/steamwar/sql/Statement.java deleted file mode 100644 index db75983..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/Statement.java +++ /dev/null @@ -1,130 +0,0 @@ -package de.steamwar.sql; - -import de.steamwar.core.Core; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class Statement { - - private static final List statements = new ArrayList<>(); - - private static Connection con; - private static String url; - private static String user; - private static String password; - - public static void connect(String url, String user, String password) { - Statement.url = url; - Statement.user = user; - Statement.password = password; - try { - con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password); - } catch (SQLException e) { - throw new SecurityException("Could not start SQL-Connection", e); - } - } - - private static void reset() { - close(); - connect(url, user, password); - try { - for (Statement statement : statements) { - statement.init(); - } - } catch (SQLException e) { - throw new SecurityException("Could not reprepare SQL statements", e); - } - } - - public static void close() { - synchronized (statements) { - for (Statement statement : statements) { - try { - statement.st.close(); - } catch (SQLException e) { - Core.getInstance().getLogger().log(Level.INFO, "Could not close statement", e); - } - } - - try { - con.close(); - } catch (SQLException e) { - Core.getInstance().getLogger().log(Level.INFO, "Could not close SQL connection", e); - } - } - } - - public static boolean connectionStable() { - try { - return !con.isClosed(); - } catch (SQLException e) { - return false; - } - } - - private final String sql; - private PreparedStatement st; - - public Statement(String sql) { - this.sql = sql; - statements.add(this); - try { - init(); - } catch (SQLException e) { - throw new SecurityException("Could not init SQL statement", e); - } - } - - private void init() throws SQLException { - st = con.prepareStatement(sql); - } - - public T select(ResultSetUser user, Object... objects) { - synchronized (statements) { - return prepare(() -> { - ResultSet rs = st.executeQuery(); - T result = user.use(rs); - rs.close(); - return result; - }, objects); - } - } - - public void update(Object... objects) { - synchronized (statements) { - prepare(st::executeUpdate, objects); - } - } - - private T prepare(SQLRunnable runnable, Object... objects) { - try { - setObjects(objects); - return runnable.run(); - } catch (SQLException e) { - reset(); - throw new SecurityException("Could not execute SQL statement", e); - } - } - - private void setObjects(Object... objects) throws SQLException { - for (int i = 0; i < objects.length; i++) { - st.setObject(i + 1, objects[i]); - } - } - - public interface ResultSetUser { - T use(ResultSet rs) throws SQLException; - } - - private interface SQLRunnable { - T run() throws SQLException; - } - -}