SteamWar/SpigotCore
Archiviert
13
0

Add LocaleInvalidationHandler
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-05-21 13:21:20 +02:00
Ursprung 55fb0b8f47
Commit 22e691dcb8
7 geänderte Dateien mit 68 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,7 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import de.steamwar.comms.handlers.BungeeHandler; import de.steamwar.comms.handlers.BungeeHandler;
import de.steamwar.comms.handlers.InventoryHandler; import de.steamwar.comms.handlers.InventoryHandler;
import de.steamwar.comms.handlers.LocaleInvalidationHandler;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.BountifulWrapper;
import de.steamwar.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
@ -57,6 +58,7 @@ public class BungeeReceiver implements PluginMessageListener {
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
player.closeInventory(); player.closeInventory();
}); });
registerHandler(PacketIdManager.LOCALE_INVALIDATION, new LocaleInvalidationHandler());
} }
@Override @Override

Datei anzeigen

@ -28,6 +28,8 @@ public class PacketIdManager {
public static final byte PREPARE_SCHEM = 0x03; public static final byte PREPARE_SCHEM = 0x03;
public static final byte BAUMEMBER_UPDATE = 0x04; public static final byte BAUMEMBER_UPDATE = 0x04;
public static final byte EXECUTE_COMMAND = 0x05; public static final byte EXECUTE_COMMAND = 0x05;
public static final byte LOCALE_INVALIDATION = 0x06;
//0x1(X) Bungee Inventory //0x1(X) Bungee Inventory
public static final byte INVENTORY_PACKET = 0x10; public static final byte INVENTORY_PACKET = 0x10;
public static final byte INVENTORY_CALLBACK_PACKET = 0x11; 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,7 +21,7 @@ package de.steamwar.message;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.WorldOfColorWrapper; 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.ChatMessageType;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
@ -75,11 +75,12 @@ public class Message {
} }
private Locale getLocale(Player player){ private Locale getLocale(Player player){
String dbLocale = UserConfig.getConfig(player.getUniqueId(), "language"); Locale locale = SteamwarUser.get(player).getLocale();
if (dbLocale != null) { if (locale == null)
return new Locale(dbLocale); locale = WorldOfColorWrapper.impl.getLocale(player);
} if (locale == null)
return WorldOfColorWrapper.impl.getLocale(player); locale = Locale.getDefault();
return locale;
} }
/* Send a message to one player */ /* Send a message to one player */

Datei anzeigen

@ -331,7 +331,12 @@ public class SQLProvider implements Provider {
} }
private SteamwarUser newSteamwarUser(ResultSet rs) throws SQLException { 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 (?, ?, ?)"); private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.sql; package de.steamwar.sql;
import de.steamwar.core.WorldEditWrapper; import de.steamwar.core.WorldEditWrapper;
import de.steamwar.core.WorldOfColorWrapper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -168,12 +169,12 @@ public class StandaloneProvider implements Provider {
Player player = Bukkit.getPlayer(userName); Player player = Bukkit.getPlayer(userName);
if(player == null) if(player == null)
return 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)));
} }
@Override @Override
public SteamwarUser getUserByUUID(UUID uuid) { 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 @Override

Datei anzeigen

@ -23,10 +23,7 @@ import de.steamwar.core.Core;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class SteamwarUser { public class SteamwarUser {
@ -43,20 +40,31 @@ public class SteamwarUser {
}, 72000, 72000); }, 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());
byUUID.remove(user.getUUID());
}
private final int id; private final int id;
private final UUID uuid; private final UUID uuid;
private final String userName; private final String userName;
private final UserGroup userGroup; private final UserGroup userGroup;
private final int team; private final int team;
private final boolean bedrock; 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.id = id;
this.uuid = uuid; this.uuid = uuid;
this.userName = userName; this.userName = userName;
this.userGroup = userGroup; this.userGroup = userGroup;
this.team = team; this.team = team;
this.bedrock = bedrock; this.bedrock = bedrock;
this.locale = locale;
byUUID.put(uuid, this); byUUID.put(uuid, this);
byName.put(userName.toLowerCase(), this); byName.put(userName.toLowerCase(), this);
@ -87,6 +95,10 @@ public class SteamwarUser {
return bedrock; return bedrock;
} }
public Locale getLocale() {
return locale;
}
public static SteamwarUser get(String userName){ public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase()); SteamwarUser user = byName.get(userName.toLowerCase());
if(user == null) if(user == null)