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,6 +21,7 @@ package de.steamwar.message;
|
||||
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.WorldOfColorWrapper;
|
||||
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;
|
||||
@ -74,7 +75,7 @@ public class Message {
|
||||
}
|
||||
|
||||
private Locale getLocale(Player player){
|
||||
return WorldOfColorWrapper.impl.getLocale(player);
|
||||
return SteamwarUser.get(player).getLocale();
|
||||
}
|
||||
|
||||
/* Send a message to one player */
|
||||
|
@ -331,7 +331,8 @@ 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");
|
||||
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"), dbLocale != null ? Locale.forLanguageTag(dbLocale) : null);
|
||||
}
|
||||
|
||||
|
||||
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, null));
|
||||
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, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,13 +20,11 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldOfColorWrapper;
|
||||
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 +41,30 @@ public class SteamwarUser {
|
||||
}, 72000, 72000);
|
||||
}
|
||||
|
||||
public static void invalidate(int userId) {
|
||||
SteamwarUser user = byId.remove(userId);
|
||||
if (user == null)
|
||||
return;
|
||||
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 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,15 @@ public class SteamwarUser {
|
||||
return bedrock;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
if(locale != null)
|
||||
return locale;
|
||||
locale = WorldOfColorWrapper.impl.getLocale(Bukkit.getPlayer(uuid));
|
||||
if (locale != null)
|
||||
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.
|
||||
return locale;
|
||||
return Locale.getDefault();
|
||||
Lixfel
hat
Bitte stattdessen ein != null return machen. Bitte stattdessen ein != null return machen.
|
||||
}
|
||||
|
||||
public static SteamwarUser get(String userName){
|
||||
SteamwarUser user = byName.get(userName.toLowerCase());
|
||||
if(user == null)
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Das funktioniert so nicht. byLanguageTag oder so ähnlich.