Merge branch 'master' into CommandFramework
Dieser Commit ist enthalten in:
Commit
21c7fe7dbb
68
SpigotCore_Main/src/de/steamwar/sql/UserConfig.java
Normale Datei
68
SpigotCore_Main/src/de/steamwar/sql/UserConfig.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserConfig {
|
||||||
|
|
||||||
|
private UserConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getConfig(UUID player, String config) {
|
||||||
|
return getConfig(SteamwarUser.get(player).getId(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getConfig(int player, String config) {
|
||||||
|
ResultSet configResult = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, config);
|
||||||
|
try {
|
||||||
|
if (!configResult.next()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return configResult.getString("Value");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePlayerConfig(UUID uuid, String config, String value) {
|
||||||
|
updatePlayerConfig(SteamwarUser.get(uuid).getId(), config, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, config, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlayerConfig(UUID uuid, String config) {
|
||||||
|
removePlayerConfig(SteamwarUser.get(uuid).getId(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlayerConfig(int id, String config) {
|
||||||
|
SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren