SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Add language via db' (#194) from LanguageConfig into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #194
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-05-24 09:20:37 +02:00
Commit 5289907eb4
7 geänderte Dateien mit 64 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -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

Datei anzeigen

@ -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;

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -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 */

Datei anzeigen

@ -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 (?, ?, ?)");

Datei anzeigen

@ -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));
}
@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

Datei anzeigen

@ -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());
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)
return locale;
return Locale.getDefault();
}
public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase());
if(user == null)