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); + } + +}