From c62c2990c08b09eb12e30b8e3c0c22b59b1da884 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 17:56:08 +0200 Subject: [PATCH] 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); + } + +}