SteamWar/BungeeCore
Archiviert
13
2

english #354

Zusammengeführt
Lixfel hat 21 Commits von english nach master 2022-05-24 10:15:41 +02:00 zusammengeführt
7 geänderte Dateien mit 85 neuen und 76 gelöschten Zeilen
Nur Änderungen aus Commit df310716d8 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.UserConfig;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -40,12 +40,12 @@ public class LockCurrentLocaleCommand extends BasicCommand {
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
Locale locale = proxiedPlayer.getLocale();
if (locale == null) {
// TODO: Fehlermeldung
ChatSender.of(proxiedPlayer).system("LOCK_LOCALE_ERROR");
return;
}
UserConfig.updatePlayerConfig(steamwarUser.getId(), "language", proxiedPlayer.getLocale().getLanguage());
steamwarUser.setLocale(locale, true);
ChatSender.of(proxiedPlayer).system("LOCK_LOCALE_CHANGED");
}
}

Datei anzeigen

@ -28,6 +28,8 @@ public class PacketIdManager {
public static final byte BAUMEMBER_UPDATE = 0x04;
public static final byte EXECUTE_COMMAND = 0x05;
public static final byte LOCALE_INVALIDATION = 0x06;
//0x1(X) Bungee Inventory
public static final byte INVENTORY_PACKET = 0x10;
public static final byte INVENTORY_CALLBACK_PACKET = 0x11;

Datei anzeigen

@ -0,0 +1,43 @@
/*
* 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
public class LocaleInvalidationPacket extends BungeePacket {
private int userId;
public LocaleInvalidationPacket(int userId) {
this.userId = userId;
}
@Override
public int getId() {
return PacketIdManager.LOCALE_INVALIDATION;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(userId);
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.google.gson.JsonParser;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand;
import de.steamwar.bungeecore.comms.packets.LocaleInvalidationPacket;
import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.ProxyServer;
@ -45,6 +46,7 @@ public class SteamwarUser {
private static final Statement updateName = new Statement("UPDATE UserData SET UserName = ? WHERE id = ?");
private static final Statement updateBedrock = new Statement("UPDATE UserData SET Bedrock = ? WHERE id = ?");
private static final Statement updateLocale = new Statement("UPDATE UserData SET Locale = ?, ManualLocale = ? WHERE id = ?");
private static final Statement insert = new Statement("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')");
private static final Statement byUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
private static final Statement byName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
@ -74,6 +76,9 @@ public class SteamwarUser {
private final Map<Punishment.PunishmentType, Punishment> punishments;
private Long discordId;
private Locale locale;
private boolean manualLocale;
static {
try {
LIXFEL_DE = InetAddress.getByAddress(new byte[]{(byte) 195, (byte) 201, (byte) 242, 43});
@ -94,6 +99,15 @@ public class SteamwarUser {
if(rs.wasNull()) {
discordId = null;
}
String dbLocale = rs.getString("Locale");
if (dbLocale == null) {
locale = null;
} else {
locale = new Locale(dbLocale);
}
YoyoNow markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

SO GEHT DAS NICHT.

SO GEHT DAS NICHT.
manualLocale = rs.getBoolean("ManualLocale");
usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this);
@ -101,6 +115,7 @@ public class SteamwarUser {
usersByDiscord.put(discordId, this);
}
punishments = Punishment.getPunishmentsOfPlayer(id);
}
public static SteamwarUser getOrCreate(PendingConnection connection) {
@ -364,4 +379,19 @@ public class SteamwarUser {
this.leader = leader;
updateLeader.update(leader, id);
}
public Locale getLocale() {
return locale;
}
public boolean isManualLocale() {
return manualLocale;
}
public void setLocale(Locale locale, boolean manualLocale) {
this.locale = locale;
this.manualLocale = manualLocale;
updateLocale.update(locale.getLanguage(), manualLocale, id);
new LocaleInvalidationPacket(id).send(getPlayer());
}
}

Datei anzeigen

@ -1,62 +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.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);
}
}

Datei anzeigen

@ -619,4 +619,8 @@ FIGHT_MERGE_DECLINE=Launch new arena
FIGHT_MERGE_ACCEPT=Join fight
FIGHT_MERGE_INFO_LORE_1=§8By: §e{0}
FIGHT_MERGE_OFFLINE=§7The proposed arena has been terminated in the meantime, a new arena will be started.
FIGHT_MERGE_INFO=§e{0}§8: §e{1}
FIGHT_MERGE_INFO=§e{0}§8: §e{1}
#Locale Locking
LOCK_LOCALE_ERROR=§cError while locking your language
LOCK_LOCALE_CHANGED=§aLanguage locked to your current minecraft language

Datei anzeigen

@ -22,7 +22,6 @@ 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;
@ -47,14 +46,7 @@ import java.util.stream.Stream;
public interface ChatSender {
static Locale getLocale(ProxiedPlayer player) {
String dbLocale = UserConfig.getConfig(SteamwarUser.get(player).getId(), "language");
if (dbLocale != null) {
return new Locale(dbLocale);
}
Locale locale = player.getLocale();
if(locale == null)
locale = Locale.getDefault();
return locale;
return SteamwarUser.get(player).getLocale();
}
static Stream<ProxiedPlayer> all() {