12
0

Add BauweltMemberConfig #102

Manuell gemergt
Lixfel hat 9 Commits von BauweltMemberConfig nach master 2021-05-14 15:45:59 +02:00 zusammengeführt
2 geänderte Dateien mit 82 neuen und 78 gelöschten Zeilen
Nur Änderungen aus Commit c62c2990c0 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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 {
YoyoNow markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Ungeil, da geht der ursprüngliche Fehler verloren => Stacktrace hat keine aussagekraft mehr. Pack noch einen String mit kurzbeschreibung und daran anhängend die Exception dran aka. new SecException("Bla", e);

Ungeil, da geht der ursprüngliche Fehler verloren => Stacktrace hat keine aussagekraft mehr. Pack noch einen String mit kurzbeschreibung und daran anhängend die Exception dran aka. new SecException("Bla", e);
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) {
YoyoNow markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Können wir konsistent zu den Spalten bleiben und das durchgehend config und value nennen?

Können wir konsistent zu den Spalten bleiben und das durchgehend config und value nennen?
Veraltet
Review

Ja habe ich.

Ja habe ich.
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) {
YoyoNow markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Üblicherweise haben wir keine Player-Methoden in den Datenbankmethoden, sondern nur UUID und id-Support.

Üblicherweise haben wir keine Player-Methoden in den Datenbankmethoden, sondern nur UUID und id-Support.
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);
}
}