english #354
44
src/de/steamwar/bungeecore/commands/LockCurrentLocaleCommand.java
Normale Datei
44
src/de/steamwar/bungeecore/commands/LockCurrentLocaleCommand.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserConfig;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class LockCurrentLocaleCommand extends BasicCommand {
|
||||
|
||||
public LockCurrentLocaleCommand() {
|
||||
super("lockcurrentlocale", "", "locklocale", "locale");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender commandSender, String[] strings) {
|
||||
if (!(commandSender instanceof ProxiedPlayer)) {
|
||||
return;
|
||||
}
|
||||
ProxiedPlayer proxiedPlayer = (ProxiedPlayer) commandSender;
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer);
|
||||
|
||||
// TODO: Hier fehlt noch eine Nachricht an den User. Sollte deswegen erst gemerged werden, wenn der branch 'english' germerged ist
|
||||
UserConfig.updatePlayerConfig(steamwarUser.getId(), "language", proxiedPlayer.getLocale().getLanguage());
|
||||
}
|
||||
}
|
62
src/de/steamwar/bungeecore/sql/UserConfig.java
Normale Datei
62
src/de/steamwar/bungeecore/sql/UserConfig.java
Normale Datei
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.bungeecore.sql;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserConfig {
|
||||
private UserConfig() {}
|
||||
|
||||
private static final Statement getConfig = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
|
||||
private static final Statement setConfig = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
|
||||
private static final Statement deleteConfig = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
|
||||
|
||||
public static String getConfig(UUID player, String config) {
|
||||
return getConfig(SteamwarUser.get(player).getId(), config);
|
||||
}
|
||||
|
||||
public static String getConfig(int player, String config) {
|
||||
return getConfig.select(rs -> {
|
||||
if(rs.next())
|
||||
return rs.getString("Value");
|
||||
return null;
|
||||
}, player, config);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
setConfig.update(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) {
|
||||
deleteConfig.update(id, config);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ package de.steamwar.messages;
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.bot.listeners.DiscordChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserConfig;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -150,6 +151,9 @@ public interface ChatSender {
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
String dbLocale = UserConfig.getConfig(user().getId(), "language");
|
||||
if (dbLocale != null)
|
||||
return new Locale(dbLocale);
|
||||
Locale locale = player.getLocale();
|
||||
if(locale == null)
|
||||
locale = Locale.getDefault();
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren