From 319fcdfae056b0d4b05b0fb893c26e91d27b9429 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 11:55:39 +0200 Subject: [PATCH 1/6] Add BauweltMemberConfig --- .../de/steamwar/sql/BauweltMemberConfig.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java new file mode 100644 index 0000000..b915d78 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -0,0 +1,78 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import org.bukkit.entity.Player; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public final class BauweltMemberConfig { + + private BauweltMemberConfig() { + throw new IllegalStateException("Utility Class"); + } + + public static String getPlayerConfig(Player player) { + return getPlayerConfig(player.getUniqueId()); + } + + public static String getPlayerConfig(UUID uuid) { + return getPlayerConfig(SteamwarUser.get(uuid).getId()); + } + + public static String getPlayerConfig(int id) { + ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); + try { + if (config == null || !config.next()) { + return null; + } + return config.getString("BauConfig"); + } catch (SQLException e) { + return null; + } + } + + public static void updatePlayerConfig(Player player, String config) { + updatePlayerConfig(player.getUniqueId(), config); + } + + public static void updatePlayerConfig(UUID uuid, String config) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), config); + } + + public static void updatePlayerConfig(int id, String config) { + SQL.update("INSERT INTO MemberConfig (UserID, BauConfig) VALUES (?, ?) ON DUPLICATE KEY UPDATE BauConfig = VALUES(BauConfig)", id, config); + } + + public static void removePlayerConfig(Player player) { + removePlayerConfig(player.getUniqueId()); + } + + public static void removePlayerConfig(UUID uuid) { + removePlayerConfig(SteamwarUser.get(uuid).getId()); + } + + public static void removePlayerConfig(int id) { + updatePlayerConfig(id, null); + } + +} From ad05babe45205b26d568933825fd1e16559b4f5c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 14:57:58 +0200 Subject: [PATCH 2/6] Fix BauweltMemberConfig --- SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java index b915d78..3315e48 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -28,7 +28,7 @@ import java.util.UUID; public final class BauweltMemberConfig { private BauweltMemberConfig() { - throw new IllegalStateException("Utility Class"); + } public static String getPlayerConfig(Player player) { @@ -47,7 +47,7 @@ public final class BauweltMemberConfig { } return config.getString("BauConfig"); } catch (SQLException e) { - return null; + throw new SecurityException(); } } From d239f2cbaa6933885aebf093804f52a8a895f654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 17:48:02 +0200 Subject: [PATCH 3/6] Fix BauweltMemberConfig --- SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java index 3315e48..691cd9e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -42,7 +42,7 @@ public final class BauweltMemberConfig { public static String getPlayerConfig(int id) { ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); try { - if (config == null || !config.next()) { + if (!config.next()) { return null; } return config.getString("BauConfig"); From c62c2990c08b09eb12e30b8e3c0c22b59b1da884 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 17:56:08 +0200 Subject: [PATCH 4/6] Add UserConfig --- .../de/steamwar/sql/BauweltMemberConfig.java | 78 ------------------ .../src/de/steamwar/sql/UserConfig.java | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+), 78 deletions(-) delete mode 100644 SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java create mode 100644 SpigotCore_Main/src/de/steamwar/sql/UserConfig.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java deleted file mode 100644 index 691cd9e..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.sql; - -import org.bukkit.entity.Player; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; - -public final class BauweltMemberConfig { - - private BauweltMemberConfig() { - - } - - public static String getPlayerConfig(Player player) { - return getPlayerConfig(player.getUniqueId()); - } - - public static String getPlayerConfig(UUID uuid) { - return getPlayerConfig(SteamwarUser.get(uuid).getId()); - } - - public static String getPlayerConfig(int id) { - ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); - try { - if (!config.next()) { - return null; - } - return config.getString("BauConfig"); - } catch (SQLException e) { - throw new SecurityException(); - } - } - - public static void updatePlayerConfig(Player player, String config) { - updatePlayerConfig(player.getUniqueId(), config); - } - - public static void updatePlayerConfig(UUID uuid, String config) { - updatePlayerConfig(SteamwarUser.get(uuid).getId(), config); - } - - public static void updatePlayerConfig(int id, String config) { - SQL.update("INSERT INTO MemberConfig (UserID, BauConfig) VALUES (?, ?) ON DUPLICATE KEY UPDATE BauConfig = VALUES(BauConfig)", id, config); - } - - public static void removePlayerConfig(Player player) { - removePlayerConfig(player.getUniqueId()); - } - - public static void removePlayerConfig(UUID uuid) { - removePlayerConfig(SteamwarUser.get(uuid).getId()); - } - - public static void removePlayerConfig(int id) { - updatePlayerConfig(id, null); - } - -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java new file mode 100644 index 0000000..df199ed --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -0,0 +1,82 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import org.bukkit.entity.Player; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public class UserConfig { + + private UserConfig() { + + } + + public static String getConfig(Player player, String configType) { + return getConfig(player.getUniqueId(), configType); + } + + public static String getConfig(UUID player, String configType) { + return getConfig(SteamwarUser.get(player).getId(), configType); + } + + public static String getConfig(int player, String configType) { + ResultSet config = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, configType); + try { + if (!config.next()) { + return null; + } + return config.getString("Value"); + } catch (SQLException e) { + throw new SecurityException(); + } + } + + public static void updatePlayerConfig(Player player, String configType, String config) { + updatePlayerConfig(player.getUniqueId(), configType, config); + } + + public static void updatePlayerConfig(UUID uuid, String configType, String config) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), configType, config); + } + + public static void updatePlayerConfig(int id, String configType, String config) { + if (config == null) { + removePlayerConfig(id, configType); + return; + } + SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, configType, config); + } + + public static void removePlayerConfig(Player player, String configType) { + removePlayerConfig(player.getUniqueId(), configType); + } + + public static void removePlayerConfig(UUID uuid, String configType) { + removePlayerConfig(SteamwarUser.get(uuid).getId(), configType); + } + + public static void removePlayerConfig(int id, String configType) { + SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, configType); + } + +} From 83cc566558051e3cb3569b9673076fa54cf92b27 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 7 May 2021 09:05:28 +0200 Subject: [PATCH 5/6] Update UserConfig --- .../src/de/steamwar/sql/UserConfig.java | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java index df199ed..50d8ad3 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -19,8 +19,6 @@ package de.steamwar.sql; -import org.bukkit.entity.Player; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; @@ -31,52 +29,40 @@ public class UserConfig { } - public static String getConfig(Player player, String configType) { - return getConfig(player.getUniqueId(), configType); + public static String getConfig(UUID player, String config) { + return getConfig(SteamwarUser.get(player).getId(), config); } - public static String getConfig(UUID player, String configType) { - return getConfig(SteamwarUser.get(player).getId(), configType); - } - - public static String getConfig(int player, String configType) { - ResultSet config = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, configType); + public static String getConfig(int player, String config) { + ResultSet configResult = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, config); try { - if (!config.next()) { + if (!configResult.next()) { return null; } - return config.getString("Value"); + return configResult.getString("Value"); } catch (SQLException e) { throw new SecurityException(); } } - public static void updatePlayerConfig(Player player, String configType, String config) { - updatePlayerConfig(player.getUniqueId(), configType, config); + public static void updatePlayerConfig(UUID uuid, String config, String value) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), config, value); } - public static void updatePlayerConfig(UUID uuid, String configType, String config) { - updatePlayerConfig(SteamwarUser.get(uuid).getId(), configType, config); - } - - public static void updatePlayerConfig(int id, String configType, String config) { - if (config == null) { - removePlayerConfig(id, configType); + public static void updatePlayerConfig(int id, String config, String value) { + if (value == null) { + removePlayerConfig(id, config); return; } - SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, configType, config); + SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, config, value); } - public static void removePlayerConfig(Player player, String configType) { - removePlayerConfig(player.getUniqueId(), configType); + public static void removePlayerConfig(UUID uuid, String config) { + removePlayerConfig(SteamwarUser.get(uuid).getId(), config); } - public static void removePlayerConfig(UUID uuid, String configType) { - removePlayerConfig(SteamwarUser.get(uuid).getId(), configType); - } - - public static void removePlayerConfig(int id, String configType) { - SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, configType); + public static void removePlayerConfig(int id, String config) { + SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, config); } } From 38155f53457af1c7adb6cc90cbdb7f682a919e9a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 12 May 2021 20:40:49 +0200 Subject: [PATCH 6/6] Fix UserConfig.getConfig --- SpigotCore_Main/src/de/steamwar/sql/UserConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java index df199ed..65581b7 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -47,7 +47,7 @@ public class UserConfig { } return config.getString("Value"); } catch (SQLException e) { - throw new SecurityException(); + throw new SecurityException(e.getMessage(), e); } }