Add language via db #194
@ -23,6 +23,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.steamwar.comms.handlers.BungeeHandler;
|
||||
import de.steamwar.comms.handlers.InventoryHandler;
|
||||
import de.steamwar.comms.handlers.LocaleInvalidationHandler;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
@ -57,6 +58,7 @@ public class BungeeReceiver implements PluginMessageListener {
|
||||
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||
player.closeInventory();
|
||||
});
|
||||
registerHandler(PacketIdManager.LOCALE_INVALIDATION, new LocaleInvalidationHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,8 @@ public class PacketIdManager {
|
||||
public static final byte PREPARE_SCHEM = 0x03;
|
||||
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;
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.comms.handlers;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
|
||||
public class LocaleInvalidationHandler implements BungeeHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ByteArrayDataInput byteArrayDataInput) {
|
||||
SteamwarUser.invalidate(byteArrayDataInput.readInt());
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ package de.steamwar.message;
|
||||
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.WorldOfColorWrapper;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
@ -75,11 +75,12 @@ public class Message {
|
||||
}
|
||||
|
||||
private Locale getLocale(Player player){
|
||||
String dbLocale = UserConfig.getConfig(player.getUniqueId(), "language");
|
||||
if (dbLocale != null) {
|
||||
return new Locale(dbLocale);
|
||||
}
|
||||
return WorldOfColorWrapper.impl.getLocale(player);
|
||||
Locale locale = SteamwarUser.get(player).getLocale();
|
||||
if (locale == null)
|
||||
locale = WorldOfColorWrapper.impl.getLocale(player);
|
||||
if (locale == null)
|
||||
locale = Locale.getDefault();
|
||||
return locale;
|
||||
}
|
||||
|
||||
/* Send a message to one player */
|
||||
|
@ -331,7 +331,12 @@ public class SQLProvider implements Provider {
|
||||
}
|
||||
|
||||
private SteamwarUser newSteamwarUser(ResultSet rs) throws SQLException {
|
||||
return new SteamwarUser(rs.getInt("id"), UUID.fromString(rs.getString("UUID")), rs.getString("UserName"), UserGroup.getUsergroup(rs.getString("UserGroup")), rs.getInt("Team"), rs.getBoolean("Bedrock"));
|
||||
String dbLocale = rs.getString("Locale");
|
||||
Locale locale = null;
|
||||
if (dbLocale != null) {
|
||||
locale = new Locale(dbLocale);
|
||||
|
||||
}
|
||||
return new SteamwarUser(rs.getInt("id"), UUID.fromString(rs.getString("UUID")), rs.getString("UserName"), UserGroup.getUsergroup(rs.getString("UserGroup")), rs.getInt("Team"), rs.getBoolean("Bedrock"), locale);
|
||||
}
|
||||
|
||||
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import de.steamwar.core.WorldOfColorWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -168,12 +169,12 @@ public class StandaloneProvider implements Provider {
|
||||
Player player = Bukkit.getPlayer(userName);
|
||||
if(player == null)
|
||||
return null;
|
||||
return usersByUUID.computeIfAbsent(player.getUniqueId(), uuid -> new SteamwarUser(userId++, uuid, userName, UserGroup.Member, 0, false));
|
||||
return usersByUUID.computeIfAbsent(player.getUniqueId(), uuid -> new SteamwarUser(userId++, uuid, userName, UserGroup.Member, 0, false, WorldOfColorWrapper.impl.getLocale(player)));
|
||||
Lixfel
hat
Locale.getDefault() statt null zurückliefern, ggf. falls online-User aktuelle Locale (genauso im byUUID) Locale.getDefault() statt null zurückliefern, ggf. falls online-User aktuelle Locale (genauso im byUUID)
YoyoNow
hat
Deswegen giobt es den Spezial wert 'null', damit er dann die locale des users nimmt. Das ist absicht. Deswegen auch oben wenn die dbLocale null ist wird die locale null bleiben womit einfach erstmal die locale des spielers genutzt wird. Ist primär dafür da das wir das im Livebetrieb mergen können. Deswegen giobt es den Spezial wert 'null', damit er dann die locale des users nimmt. Das ist absicht. Deswegen auch oben wenn die dbLocale null ist wird die locale null bleiben womit einfach erstmal die locale des spielers genutzt wird. Ist primär dafür da das wir das im Livebetrieb mergen können.
|
||||
}
|
||||
|
||||
@Override
|
||||
public SteamwarUser getUserByUUID(UUID uuid) {
|
||||
return usersByUUID.computeIfAbsent(uuid, uuid1 -> new SteamwarUser(userId++, uuid1, Objects.requireNonNull(Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid1)).getName()), UserGroup.Member, 0, false));
|
||||
return usersByUUID.computeIfAbsent(uuid, uuid1 -> new SteamwarUser(userId++, uuid1, Objects.requireNonNull(Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid1)).getName()), UserGroup.Member, 0, false, Locale.getDefault()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,10 +23,7 @@ import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class SteamwarUser {
|
||||
|
||||
@ -43,20 +40,31 @@ public class SteamwarUser {
|
||||
}, 72000, 72000);
|
||||
}
|
||||
|
||||
public static void invalidate(int userId) {
|
||||
if (!byId.containsKey(userId))
|
||||
return;
|
||||
SteamwarUser user = byId.get(userId);
|
||||
byId.remove(userId);
|
||||
byName.remove(user.getUserName());
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Lixfel
hat
Ein Aufruf zu remove gibt das entfernte Objekt (oder null) direkt zurück, ein containsKey und get-Aufruf ist also unnötig. Ein Aufruf zu remove gibt das entfernte Objekt (oder null) direkt zurück, ein containsKey und get-Aufruf ist also unnötig.
|
||||
byUUID.remove(user.getUUID());
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final UUID uuid;
|
||||
private final String userName;
|
||||
private final UserGroup userGroup;
|
||||
private final int team;
|
||||
private final boolean bedrock;
|
||||
private final Locale locale;
|
||||
|
||||
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean bedrock) {
|
||||
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean bedrock, Locale locale) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.userName = userName;
|
||||
this.userGroup = userGroup;
|
||||
this.team = team;
|
||||
this.bedrock = bedrock;
|
||||
this.locale = locale;
|
||||
|
||||
byUUID.put(uuid, this);
|
||||
byName.put(userName.toLowerCase(), this);
|
||||
@ -87,6 +95,10 @@ public class SteamwarUser {
|
||||
return bedrock;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static SteamwarUser get(String userName){
|
||||
Lixfel
hat
Das ist unnötig (Entweder in DB oder gibts gar keine Info) Das ist unnötig (Entweder in DB oder gibts gar keine Info)
YoyoNow
hat
s.o. s.o.
|
||||
SteamwarUser user = byName.get(userName.toLowerCase());
|
||||
if(user == null)
|
||||
Lixfel
hat
Bitte stattdessen ein != null return machen. Bitte stattdessen ein != null return machen.
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Das funktioniert so nicht. byLanguageTag oder so ähnlich.