forked from GeyserMC/Geyser
Introduce CommandSender.getLocale() (#1431)
* Introduce CommandSender.getLocale() This allows Geyser-specific commands (e.g. `/geyser help`) to be displayed in the (Java or Bedrock) player's default language, which stops those commands from simply being displayed in the default locale. * Tweak Javadoc * Set CommandManager's GeyserConnector to final * Clean up
This commit is contained in:
parent
9b46bf8bc9
commit
045c0e0637
37 changed files with 212 additions and 120 deletions
|
@ -25,17 +25,20 @@
|
||||||
|
|
||||||
package org.geysermc.platform.bungeecord.command;
|
package org.geysermc.platform.bungeecord.command;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import org.geysermc.connector.command.CommandSender;
|
import org.geysermc.connector.command.CommandSender;
|
||||||
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class BungeeCommandSender implements CommandSender {
|
public class BungeeCommandSender implements CommandSender {
|
||||||
|
|
||||||
private net.md_5.bungee.api.CommandSender handle;
|
private final net.md_5.bungee.api.CommandSender handle;
|
||||||
|
|
||||||
|
public BungeeCommandSender(net.md_5.bungee.api.CommandSender handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
// Ensure even Java players' languages are loaded
|
||||||
|
LanguageUtils.loadGeyserLocale(getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -51,4 +54,14 @@ public class BungeeCommandSender implements CommandSender {
|
||||||
public boolean isConsole() {
|
public boolean isConsole() {
|
||||||
return !(handle instanceof ProxiedPlayer);
|
return !(handle instanceof ProxiedPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLocale() {
|
||||||
|
if (handle instanceof ProxiedPlayer) {
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) handle;
|
||||||
|
String locale = player.getLocale().getLanguage() + "_" + player.getLocale().getCountry();
|
||||||
|
return LanguageUtils.formatLocale(locale);
|
||||||
|
}
|
||||||
|
return LanguageUtils.getDefaultLocale();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,10 @@ package org.geysermc.platform.bungeecord.command;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.GeyserCommand;
|
import org.geysermc.connector.command.GeyserCommand;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -41,7 +38,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
|
public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
public GeyserBungeeCommandExecutor(GeyserConnector connector) {
|
public GeyserBungeeCommandExecutor(GeyserConnector connector) {
|
||||||
super("geyser");
|
super("geyser");
|
||||||
|
@ -54,14 +51,10 @@ public class GeyserBungeeCommandExecutor extends Command implements TabExecutor
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (getCommand(args[0]) != null) {
|
if (getCommand(args[0]) != null) {
|
||||||
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
|
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
|
||||||
String message = "";
|
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
|
||||||
if (sender instanceof GeyserSession) {
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
|
||||||
message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", ((GeyserSession) sender).getClientData().getLanguageCode());
|
|
||||||
} else {
|
|
||||||
message = LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail");
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(TextComponent.fromLegacyText(ChatColor.RED + message));
|
commandSender.sendMessage(ChatColor.RED + message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getCommand(args[0]).execute(new BungeeCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
getCommand(args[0]).execute(new BungeeCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
import org.geysermc.platform.spigot.command.GeyserSpigotCommandExecutor;
|
import org.geysermc.platform.spigot.command.GeyserSpigotCommandExecutor;
|
||||||
import org.geysermc.platform.spigot.command.GeyserSpigotCommandManager;
|
import org.geysermc.platform.spigot.command.GeyserSpigotCommandManager;
|
||||||
|
import org.geysermc.platform.spigot.command.SpigotCommandSender;
|
||||||
import org.geysermc.platform.spigot.world.GeyserSpigotBlockPlaceListener;
|
import org.geysermc.platform.spigot.world.GeyserSpigotBlockPlaceListener;
|
||||||
import org.geysermc.platform.spigot.world.GeyserSpigotWorldManager;
|
import org.geysermc.platform.spigot.world.GeyserSpigotWorldManager;
|
||||||
|
|
||||||
|
@ -130,6 +131,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||||
geyserLogger.debug("Legacy version of Minecraft (1.15.2 or older) detected; not using 3D biomes.");
|
geyserLogger.debug("Legacy version of Minecraft (1.15.2 or older) detected; not using 3D biomes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set if we need to use a different method for getting a player's locale
|
||||||
|
SpigotCommandSender.setUseLegacyLocaleMethod(!isCompatible(Bukkit.getServer().getVersion(), "1.12.0"));
|
||||||
|
|
||||||
this.geyserWorldManager = new GeyserSpigotWorldManager(isLegacy, use3dBiomes, isViaVersion);
|
this.geyserWorldManager = new GeyserSpigotWorldManager(isLegacy, use3dBiomes, isViaVersion);
|
||||||
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(connector, isLegacy, isViaVersion);
|
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(connector, isLegacy, isViaVersion);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.GeyserCommand;
|
import org.geysermc.connector.command.GeyserCommand;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -42,21 +41,17 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class GeyserSpigotCommandExecutor implements TabExecutor {
|
public class GeyserSpigotCommandExecutor implements TabExecutor {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (getCommand(args[0]) != null) {
|
if (getCommand(args[0]) != null) {
|
||||||
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
|
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
|
||||||
String message = "";
|
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
|
||||||
if (sender instanceof GeyserSession) {
|
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());;
|
||||||
message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", ((GeyserSession) sender).getClientData().getLanguageCode());
|
|
||||||
} else {
|
|
||||||
message = LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail");
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.RED + message);
|
commandSender.sendMessage(ChatColor.RED + message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
getCommand(args[0]).execute(new SpigotCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
getCommand(args[0]).execute(new SpigotCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
|
|
|
@ -25,15 +25,33 @@
|
||||||
|
|
||||||
package org.geysermc.platform.spigot.command;
|
package org.geysermc.platform.spigot.command;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandSender;
|
import org.geysermc.connector.command.CommandSender;
|
||||||
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SpigotCommandSender implements CommandSender {
|
public class SpigotCommandSender implements CommandSender {
|
||||||
|
|
||||||
private org.bukkit.command.CommandSender handle;
|
/**
|
||||||
|
* Whether to use {@code Player.getLocale()} or {@code Player.spigot().getLocale()}, depending on version.
|
||||||
|
* 1.12 or greater should not use the legacy method.
|
||||||
|
*/
|
||||||
|
private static boolean USE_LEGACY_METHOD = false;
|
||||||
|
private static Method LOCALE_METHOD;
|
||||||
|
|
||||||
|
private final org.bukkit.command.CommandSender handle;
|
||||||
|
private final String locale;
|
||||||
|
|
||||||
|
public SpigotCommandSender(org.bukkit.command.CommandSender handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
this.locale = getSpigotLocale();
|
||||||
|
// Ensure even Java players' languages are loaded
|
||||||
|
LanguageUtils.loadGeyserLocale(locale);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -49,4 +67,49 @@ public class SpigotCommandSender implements CommandSender {
|
||||||
public boolean isConsole() {
|
public boolean isConsole() {
|
||||||
return handle instanceof ConsoleCommandSender;
|
return handle instanceof ConsoleCommandSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLocale() {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if we are on pre-1.12, and therefore {@code player.getLocale()} doesn't exist and we have to get
|
||||||
|
* {@code player.spigot().getLocale()}.
|
||||||
|
*
|
||||||
|
* @param useLegacyMethod if we are running pre-1.12 and therefore need to use reflection to get the player locale
|
||||||
|
*/
|
||||||
|
public static void setUseLegacyLocaleMethod(boolean useLegacyMethod) {
|
||||||
|
USE_LEGACY_METHOD = useLegacyMethod;
|
||||||
|
if (USE_LEGACY_METHOD) {
|
||||||
|
try {
|
||||||
|
//noinspection JavaReflectionMemberAccess - of course it doesn't exist; that's why we're doing it
|
||||||
|
LOCALE_METHOD = Player.Spigot.class.getMethod("getLocale");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
GeyserConnector.getInstance().getLogger().debug("Player.Spigot.getLocale() doesn't exist? Not a big deal but if you're seeing this please report it to the developers!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* So we only have to do nasty reflection stuff once per command
|
||||||
|
*
|
||||||
|
* @return the locale of the Spigot player
|
||||||
|
*/
|
||||||
|
private String getSpigotLocale() {
|
||||||
|
if (handle instanceof Player) {
|
||||||
|
Player player = (Player) handle;
|
||||||
|
if (USE_LEGACY_METHOD) {
|
||||||
|
try {
|
||||||
|
// sigh
|
||||||
|
// This was the only option on older Spigot instances and now it's gone
|
||||||
|
return (String) LOCALE_METHOD.invoke(player.spigot());
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return player.getLocale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return LanguageUtils.getDefaultLocale();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,11 @@ package org.geysermc.platform.velocity.command;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.Command;
|
import com.velocitypowered.api.command.Command;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
import net.kyori.text.TextComponent;
|
|
||||||
|
|
||||||
import org.geysermc.connector.common.ChatColor;
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.command.CommandSender;
|
||||||
import org.geysermc.connector.command.GeyserCommand;
|
import org.geysermc.connector.command.GeyserCommand;
|
||||||
|
import org.geysermc.connector.common.ChatColor;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -42,15 +39,15 @@ import java.util.Arrays;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class GeyserVelocityCommandExecutor implements Command {
|
public class GeyserVelocityCommandExecutor implements Command {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSource source, String[] args) {
|
public void execute(CommandSource source, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (getCommand(args[0]) != null) {
|
if (getCommand(args[0]) != null) {
|
||||||
if (!source.hasPermission(getCommand(args[0]).getPermission())) {
|
if (!source.hasPermission(getCommand(args[0]).getPermission())) {
|
||||||
// Not ideal to use log here but we dont get a session
|
CommandSender sender = new VelocityCommandSender(source);
|
||||||
source.sendMessage(TextComponent.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getCommand(args[0]).execute(new VelocityCommandSender(source), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
getCommand(args[0]).execute(new VelocityCommandSender(source), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
|
||||||
|
|
|
@ -28,17 +28,21 @@ package org.geysermc.platform.velocity.command;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
|
|
||||||
import org.geysermc.connector.command.CommandSender;
|
import org.geysermc.connector.command.CommandSender;
|
||||||
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class VelocityCommandSender implements CommandSender {
|
public class VelocityCommandSender implements CommandSender {
|
||||||
|
|
||||||
private CommandSource handle;
|
private final CommandSource handle;
|
||||||
|
|
||||||
|
public VelocityCommandSender(CommandSource handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
// Ensure even Java players' languages are loaded
|
||||||
|
LanguageUtils.loadGeyserLocale(getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -59,4 +63,13 @@ public class VelocityCommandSender implements CommandSender {
|
||||||
public boolean isConsole() {
|
public boolean isConsole() {
|
||||||
return handle instanceof ConsoleCommandSource;
|
return handle instanceof ConsoleCommandSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLocale() {
|
||||||
|
if (handle instanceof Player) {
|
||||||
|
Locale locale = ((Player) handle).getPlayerSettings().getLocale();
|
||||||
|
return LanguageUtils.formatLocale(locale.getLanguage() + "_" + locale.getCountry());
|
||||||
|
}
|
||||||
|
return LanguageUtils.getDefaultLocale();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ public class GeyserConnector {
|
||||||
// Make a copy to prevent ConcurrentModificationException
|
// Make a copy to prevent ConcurrentModificationException
|
||||||
final List<GeyserSession> tmpPlayers = new ArrayList<>(players);
|
final List<GeyserSession> tmpPlayers = new ArrayList<>(players);
|
||||||
for (GeyserSession playerSession : tmpPlayers) {
|
for (GeyserSession playerSession : tmpPlayers) {
|
||||||
playerSession.disconnect(LanguageUtils.getPlayerLocaleString("geyser.core.shutdown.kick.message", playerSession.getClientData().getLanguageCode()));
|
playerSession.disconnect(LanguageUtils.getPlayerLocaleString("geyser.core.shutdown.kick.message", playerSession.getLocale()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
|
CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
|
||||||
|
|
|
@ -40,19 +40,19 @@ public abstract class CommandManager {
|
||||||
@Getter
|
@Getter
|
||||||
private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>());
|
private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
public CommandManager(GeyserConnector connector) {
|
public CommandManager(GeyserConnector connector) {
|
||||||
this.connector = connector;
|
this.connector = connector;
|
||||||
|
|
||||||
registerCommand(new HelpCommand(connector, "help", LanguageUtils.getLocaleStringLog("geyser.commands.help.desc"), "geyser.command.help"));
|
registerCommand(new HelpCommand(connector, "help", "geyser.commands.help.desc", "geyser.command.help"));
|
||||||
registerCommand(new ListCommand(connector, "list", LanguageUtils.getLocaleStringLog("geyser.commands.list.desc"), "geyser.command.list"));
|
registerCommand(new ListCommand(connector, "list", "geyser.commands.list.desc", "geyser.command.list"));
|
||||||
registerCommand(new ReloadCommand(connector, "reload", LanguageUtils.getLocaleStringLog("geyser.commands.reload.desc"), "geyser.command.reload"));
|
registerCommand(new ReloadCommand(connector, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
|
||||||
registerCommand(new StopCommand(connector, "stop", LanguageUtils.getLocaleStringLog("geyser.commands.stop.desc"), "geyser.command.stop"));
|
registerCommand(new StopCommand(connector, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
|
||||||
registerCommand(new OffhandCommand(connector, "offhand", LanguageUtils.getLocaleStringLog("geyser.commands.offhand.desc"), "geyser.command.offhand"));
|
registerCommand(new OffhandCommand(connector, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
|
||||||
registerCommand(new DumpCommand(connector, "dump", LanguageUtils.getLocaleStringLog("geyser.commands.dump.desc"), "geyser.command.dump"));
|
registerCommand(new DumpCommand(connector, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
|
||||||
registerCommand(new VersionCommand(connector, "version", LanguageUtils.getLocaleStringLog("geyser.commands.version.desc"), "geyser.command.version"));
|
registerCommand(new VersionCommand(connector, "version", "geyser.commands.version.desc", "geyser.command.version"));
|
||||||
registerCommand(new StatisticsCommand(connector, "statistics", LanguageUtils.getLocaleStringLog("geyser.commands.statistics.desc"), "geyser.command.statistics"));
|
registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommand(GeyserCommand command) {
|
public void registerCommand(GeyserCommand command) {
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
|
|
||||||
package org.geysermc.connector.command;
|
package org.geysermc.connector.command;
|
||||||
|
|
||||||
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implemented on top of any class that can send a command.
|
||||||
|
* For example, it wraps around Spigot's CommandSender class.
|
||||||
|
*/
|
||||||
public interface CommandSender {
|
public interface CommandSender {
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
@ -37,5 +43,17 @@ public interface CommandSender {
|
||||||
|
|
||||||
void sendMessage(String message);
|
void sendMessage(String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the specified sender is from the console.
|
||||||
|
*/
|
||||||
boolean isConsole();
|
boolean isConsole();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale of the command sender. Defaults to the default locale at {@link LanguageUtils#getDefaultLocale()}.
|
||||||
|
*
|
||||||
|
* @return the locale of the command sender.
|
||||||
|
*/
|
||||||
|
default String getLocale() {
|
||||||
|
return LanguageUtils.getDefaultLocale();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import java.util.List;
|
||||||
public abstract class GeyserCommand {
|
public abstract class GeyserCommand {
|
||||||
|
|
||||||
protected final String name;
|
protected final String name;
|
||||||
|
/**
|
||||||
|
* The description of the command - will attempt to be translated.
|
||||||
|
*/
|
||||||
protected final String description;
|
protected final String description;
|
||||||
protected final String permission;
|
protected final String permission;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class DumpCommand extends GeyserCommand {
|
||||||
|
|
||||||
AsteriskSerializer.showSensitive = showSensitive;
|
AsteriskSerializer.showSensitive = showSensitive;
|
||||||
|
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.dump.collecting"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.dump.collecting", sender.getLocale()));
|
||||||
String dumpData = "";
|
String dumpData = "";
|
||||||
try {
|
try {
|
||||||
if (offlineDump) {
|
if (offlineDump) {
|
||||||
|
@ -82,7 +82,7 @@ public class DumpCommand extends GeyserCommand {
|
||||||
dumpData = MAPPER.writeValueAsString(new DumpInfo());
|
dumpData = MAPPER.writeValueAsString(new DumpInfo());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.dump.collect_error"));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.commands.dump.collect_error", sender.getLocale()));
|
||||||
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.collect_error_short"), e);
|
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.collect_error_short"), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -90,21 +90,21 @@ public class DumpCommand extends GeyserCommand {
|
||||||
String uploadedDumpUrl = "";
|
String uploadedDumpUrl = "";
|
||||||
|
|
||||||
if (offlineDump) {
|
if (offlineDump) {
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.dump.writing"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.dump.writing", sender.getLocale()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileOutputStream outputStream = new FileOutputStream(GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("dump.json").toFile());
|
FileOutputStream outputStream = new FileOutputStream(GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("dump.json").toFile());
|
||||||
outputStream.write(dumpData.getBytes());
|
outputStream.write(dumpData.getBytes());
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.dump.write_error"));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.commands.dump.write_error", sender.getLocale()));
|
||||||
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.write_error_short"), e);
|
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.write_error_short"), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadedDumpUrl = "dump.json";
|
uploadedDumpUrl = "dump.json";
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.dump.uploading"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.dump.uploading", sender.getLocale()));
|
||||||
|
|
||||||
String response;
|
String response;
|
||||||
JsonNode responseNode;
|
JsonNode responseNode;
|
||||||
|
@ -112,20 +112,20 @@ public class DumpCommand extends GeyserCommand {
|
||||||
response = WebUtils.post(DUMP_URL + "documents", dumpData);
|
response = WebUtils.post(DUMP_URL + "documents", dumpData);
|
||||||
responseNode = MAPPER.readTree(response);
|
responseNode = MAPPER.readTree(response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.dump.upload_error"));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.commands.dump.upload_error", sender.getLocale()));
|
||||||
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.upload_error_short"), e);
|
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.dump.upload_error_short"), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responseNode.has("key")) {
|
if (!responseNode.has("key")) {
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.dump.upload_error_short") + ": " + (responseNode.has("message") ? responseNode.get("message").asText() : response));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.commands.dump.upload_error_short", sender.getLocale()) + ": " + (responseNode.has("message") ? responseNode.get("message").asText() : response));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadedDumpUrl = DUMP_URL + responseNode.get("key").asText();
|
uploadedDumpUrl = DUMP_URL + responseNode.get("key").asText();
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.dump.message") + " " + ChatColor.DARK_AQUA + uploadedDumpUrl);
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.dump.message", sender.getLocale()) + " " + ChatColor.DARK_AQUA + uploadedDumpUrl);
|
||||||
if (!sender.isConsole()) {
|
if (!sender.isConsole()) {
|
||||||
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.commands.dump.created", sender.getName(), uploadedDumpUrl));
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.commands.dump.created", sender.getName(), uploadedDumpUrl));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,10 @@
|
||||||
|
|
||||||
package org.geysermc.connector.command.defaults;
|
package org.geysermc.connector.command.defaults;
|
||||||
|
|
||||||
import org.geysermc.connector.common.ChatColor;
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandSender;
|
import org.geysermc.connector.command.CommandSender;
|
||||||
import org.geysermc.connector.command.GeyserCommand;
|
import org.geysermc.connector.command.GeyserCommand;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.common.ChatColor;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.LanguageUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -52,17 +51,12 @@ public class HelpCommand extends GeyserCommand {
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
int page = 1;
|
int page = 1;
|
||||||
int maxPage = 1;
|
int maxPage = 1;
|
||||||
String header = "";
|
String header = LanguageUtils.getPlayerLocaleString("geyser.commands.help.header", sender.getLocale(), page, maxPage);
|
||||||
|
|
||||||
if (sender instanceof GeyserSession) {
|
|
||||||
header = LanguageUtils.getPlayerLocaleString("geyser.commands.help.header", ((GeyserSession) sender).getClientData().getLanguageCode(), page, maxPage);
|
|
||||||
} else {
|
|
||||||
header = LanguageUtils.getLocaleStringLog("geyser.commands.help.header", page, maxPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(header);
|
sender.sendMessage(header);
|
||||||
Map<String, GeyserCommand> cmds = connector.getCommandManager().getCommands();
|
Map<String, GeyserCommand> cmds = connector.getCommandManager().getCommands();
|
||||||
List<String> commands = connector.getCommandManager().getCommands().keySet().stream().sorted().collect(Collectors.toList());
|
List<String> commands = connector.getCommandManager().getCommands().keySet().stream().sorted().collect(Collectors.toList());
|
||||||
commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()));
|
commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " +
|
||||||
|
LanguageUtils.getPlayerLocaleString(cmds.get(cmd).getDescription(), sender.getLocale())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ListCommand extends GeyserCommand {
|
public class ListCommand extends GeyserCommand {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
public ListCommand(GeyserConnector connector, String name, String description, String permission) {
|
public ListCommand(GeyserConnector connector, String name, String description, String permission) {
|
||||||
super(name, description, permission);
|
super(name, description, permission);
|
||||||
|
@ -46,11 +46,9 @@ public class ListCommand extends GeyserCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
String message = "";
|
String message = "";
|
||||||
if (sender instanceof GeyserSession) {
|
message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(),
|
||||||
message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", ((GeyserSession) sender).getClientData().getLanguageCode(), connector.getPlayers().size(), connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
|
connector.getPlayers().size(),
|
||||||
} else {
|
connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
|
||||||
message = LanguageUtils.getLocaleStringLog("geyser.commands.list.message", connector.getPlayers().size(), connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
public class OffhandCommand extends GeyserCommand {
|
public class OffhandCommand extends GeyserCommand {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
|
||||||
public OffhandCommand(GeyserConnector connector, String name, String description, String permission) {
|
public OffhandCommand(GeyserConnector connector, String name, String description, String permission) {
|
||||||
super(name, description, permission);
|
super(name, description, permission);
|
||||||
|
@ -58,7 +58,7 @@ public class OffhandCommand extends GeyserCommand {
|
||||||
session.sendDownstreamPacket(releaseItemPacket);
|
session.sendDownstreamPacket(releaseItemPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Needed for Bukkit - sender is not an instance of GeyserSession
|
// Needed for Spigot - sender is not an instance of GeyserSession
|
||||||
for (GeyserSession session : connector.getPlayers()) {
|
for (GeyserSession session : connector.getPlayers()) {
|
||||||
if (sender.getName().equals(session.getPlayerEntity().getUsername())) {
|
if (sender.getName().equals(session.getPlayerEntity().getUsername())) {
|
||||||
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(0,0,0),
|
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(0,0,0),
|
||||||
|
|
|
@ -47,17 +47,12 @@ public class ReloadCommand extends GeyserCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = "";
|
String message = LanguageUtils.getPlayerLocaleString("geyser.commands.reload.message", sender.getLocale());
|
||||||
if (sender instanceof GeyserSession) {
|
|
||||||
message = LanguageUtils.getPlayerLocaleString("geyser.commands.reload.message", ((GeyserSession) sender).getClientData().getLanguageCode());
|
|
||||||
} else {
|
|
||||||
message = LanguageUtils.getLocaleStringLog("geyser.commands.reload.message");
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
|
|
||||||
for (GeyserSession session : connector.getPlayers()) {
|
for (GeyserSession session : connector.getPlayers()) {
|
||||||
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.commands.reload.kick", session.getClientData().getLanguageCode()));
|
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.commands.reload.kick", session.getLocale()));
|
||||||
}
|
}
|
||||||
connector.reload();
|
connector.reload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,12 @@ public class VersionCommand extends GeyserCommand {
|
||||||
bedrockVersions = BedrockProtocol.DEFAULT_BEDROCK_CODEC.getMinecraftVersion();
|
bedrockVersions = BedrockProtocol.DEFAULT_BEDROCK_CODEC.getMinecraftVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.version", GeyserConnector.NAME, GeyserConnector.VERSION, MinecraftConstants.GAME_VERSION, bedrockVersions));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.version", sender.getLocale(), GeyserConnector.NAME, GeyserConnector.VERSION, MinecraftConstants.GAME_VERSION, bedrockVersions));
|
||||||
|
|
||||||
// Disable update checking in dev mode
|
// Disable update checking in dev mode
|
||||||
//noinspection ConstantConditions - changes in production
|
//noinspection ConstantConditions - changes in production
|
||||||
if (!GeyserConnector.VERSION.equals("DEV")) {
|
if (!GeyserConnector.VERSION.equals("DEV")) {
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.checking"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.checking", sender.getLocale()));
|
||||||
try {
|
try {
|
||||||
Properties gitProp = new Properties();
|
Properties gitProp = new Properties();
|
||||||
gitProp.load(FileUtils.getResource("git.properties"));
|
gitProp.load(FileUtils.getResource("git.properties"));
|
||||||
|
@ -76,16 +76,16 @@ public class VersionCommand extends GeyserCommand {
|
||||||
int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim());
|
int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim());
|
||||||
int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number"));
|
int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number"));
|
||||||
if (latestBuildNum == buildNum) {
|
if (latestBuildNum == buildNum) {
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.no_updates"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.no_updates", sender.getLocale()));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.outdated", (latestBuildNum - buildNum), "http://ci.geysermc.org/"));
|
sender.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.commands.version.outdated", sender.getLocale(), (latestBuildNum - buildNum), "https://ci.geysermc.org/"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("buildNumber missing");
|
throw new AssertionError("buildNumber missing");
|
||||||
}
|
}
|
||||||
} catch (IOException | AssertionError | NumberFormatException e) {
|
} catch (IOException | AssertionError | NumberFormatException e) {
|
||||||
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed"), e);
|
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed"), e);
|
||||||
sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.version.failed"));
|
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.commands.version.failed", sender.getLocale()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ public class Entity {
|
||||||
Message message = (Message) entityMetadata.getValue();
|
Message message = (Message) entityMetadata.getValue();
|
||||||
if (message != null)
|
if (message != null)
|
||||||
// Always translate even if it's a TextMessage since there could be translatable parameters
|
// Always translate even if it's a TextMessage since there could be translatable parameters
|
||||||
metadata.put(EntityData.NAMETAG, MessageUtils.getTranslatedBedrockMessage(message, session.getClientData().getLanguageCode(), true));
|
metadata.put(EntityData.NAMETAG, MessageUtils.getTranslatedBedrockMessage(message, session.getLocale(), true));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // is custom name visible
|
case 3: // is custom name visible
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
|
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
|
||||||
LanguageUtils.loadGeyserLocale(session.getClientData().getLanguageCode());
|
LanguageUtils.loadGeyserLocale(session.getLocale());
|
||||||
|
|
||||||
if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) {
|
if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) {
|
||||||
// TODO it is safer to key authentication on something that won't change (UUID, not username)
|
// TODO it is safer to key authentication on something that won't change (UUID, not username)
|
||||||
|
@ -185,7 +185,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(MovePlayerPacket packet) {
|
public boolean handle(MovePlayerPacket packet) {
|
||||||
if (session.isLoggingIn()) {
|
if (session.isLoggingIn()) {
|
||||||
session.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.auth.login.wait", session.getClientData().getLanguageCode()));
|
session.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.auth.login.wait", session.getLocale()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return translateAndDefault(packet);
|
return translateAndDefault(packet);
|
||||||
|
|
|
@ -467,7 +467,7 @@ public class GeyserSession implements CommandSender {
|
||||||
// as it has to be extracted from a JAR
|
// as it has to be extracted from a JAR
|
||||||
if (locale.toLowerCase().equals("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) {
|
if (locale.toLowerCase().equals("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) {
|
||||||
// This should probably be left hardcoded as it will only show for en_us clients
|
// This should probably be left hardcoded as it will only show for en_us clients
|
||||||
sendMessage("Downloading your locale (en_us) this may take some time");
|
sendMessage("Loading your locale (en_us); if this isn't already downloaded, this may take some time");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download and load the language for the player
|
// Download and load the language for the player
|
||||||
|
@ -587,6 +587,11 @@ public class GeyserSession implements CommandSender {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLocale() {
|
||||||
|
return clientData.getLanguageCode();
|
||||||
|
}
|
||||||
|
|
||||||
public void sendForm(FormWindow window, int id) {
|
public void sendForm(FormWindow window, int id) {
|
||||||
windowCache.showWindow(window, id);
|
windowCache.showWindow(window, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class BossBar {
|
||||||
BossEventPacket bossEventPacket = new BossEventPacket();
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.CREATE);
|
bossEventPacket.setAction(BossEventPacket.Action.CREATE);
|
||||||
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getClientData().getLanguageCode()));
|
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getLocale()));
|
||||||
bossEventPacket.setHealthPercentage(health);
|
bossEventPacket.setHealthPercentage(health);
|
||||||
bossEventPacket.setColor(color); //ignored by client
|
bossEventPacket.setColor(color); //ignored by client
|
||||||
bossEventPacket.setOverlay(overlay);
|
bossEventPacket.setOverlay(overlay);
|
||||||
|
@ -72,7 +72,7 @@ public class BossBar {
|
||||||
BossEventPacket bossEventPacket = new BossEventPacket();
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.UPDATE_NAME);
|
bossEventPacket.setAction(BossEventPacket.Action.UPDATE_NAME);
|
||||||
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getClientData().getLanguageCode()));
|
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getLocale()));
|
||||||
|
|
||||||
session.sendUpstreamPacket(bossEventPacket);
|
session.sendUpstreamPacket(bossEventPacket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class EnchantmentInventoryTranslator extends BlockInventoryTranslator {
|
||||||
|
|
||||||
private String toRomanNumeral(GeyserSession session, int level) {
|
private String toRomanNumeral(GeyserSession session, int level) {
|
||||||
return LocaleUtils.getLocaleString("enchantment.level." + level,
|
return LocaleUtils.getLocaleString("enchantment.level." + level,
|
||||||
session.getClientData().getLanguageCode());
|
session.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,7 +261,7 @@ public class EnchantmentInventoryTranslator extends BlockInventoryTranslator {
|
||||||
|
|
||||||
public String toString(GeyserSession session) {
|
public String toString(GeyserSession session) {
|
||||||
return LocaleUtils.getLocaleString("enchantment.minecraft." + this.toString().toLowerCase(),
|
return LocaleUtils.getLocaleString("enchantment.minecraft." + this.toString().toLowerCase(),
|
||||||
session.getClientData().getLanguageCode());
|
session.getLocale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,7 +400,7 @@ public abstract class ItemTranslator {
|
||||||
// Check if its a message to translate
|
// Check if its a message to translate
|
||||||
if (MessageUtils.isMessage(name)) {
|
if (MessageUtils.isMessage(name)) {
|
||||||
// Get the translated name
|
// Get the translated name
|
||||||
name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getClientData().getLanguageCode());
|
name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getLocale());
|
||||||
|
|
||||||
// Add the new name tag
|
// Add the new name tag
|
||||||
display.put(new StringTag("Name", name));
|
display.put(new StringTag("Name", name));
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class JavaChatTranslator extends PacketTranslator<ServerChatPacket> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String locale = session.getClientData().getLanguageCode();
|
String locale = session.getLocale();
|
||||||
|
|
||||||
if (packet.getMessage() instanceof TranslationMessage) {
|
if (packet.getMessage() instanceof TranslationMessage) {
|
||||||
textPacket.setType(TextPacket.Type.TRANSLATION);
|
textPacket.setType(TextPacket.Type.TRANSLATION);
|
||||||
|
|
|
@ -36,6 +36,6 @@ public class JavaDisconnectPacket extends PacketTranslator<ServerDisconnectPacke
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerDisconnectPacket packet, GeyserSession session) {
|
public void translate(ServerDisconnectPacket packet, GeyserSession session) {
|
||||||
session.disconnect(MessageUtils.getTranslatedBedrockMessage(packet.getReason(), session.getClientData().getLanguageCode(), true));
|
session.disconnect(MessageUtils.getTranslatedBedrockMessage(packet.getReason(), session.getLocale(), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
||||||
session.setRenderDistance(packet.getViewDistance());
|
session.setRenderDistance(packet.getViewDistance());
|
||||||
|
|
||||||
// We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
|
// We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
|
||||||
String locale = session.getClientData().getLanguageCode();
|
String locale = session.getLocale();
|
||||||
List<SkinPart> skinParts = Arrays.asList(SkinPart.values());
|
List<SkinPart> skinParts = Arrays.asList(SkinPart.values());
|
||||||
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, HandPreference.RIGHT_HAND);
|
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, HandPreference.RIGHT_HAND);
|
||||||
session.sendDownstreamPacket(clientSettingsPacket);
|
session.sendDownstreamPacket(clientSettingsPacket);
|
||||||
|
|
|
@ -37,6 +37,6 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator<LoginDisconn
|
||||||
@Override
|
@Override
|
||||||
public void translate(LoginDisconnectPacket packet, GeyserSession session) {
|
public void translate(LoginDisconnectPacket packet, GeyserSession session) {
|
||||||
// The client doesn't manually get disconnected so we have to do it ourselves
|
// The client doesn't manually get disconnected so we have to do it ourselves
|
||||||
session.disconnect(MessageUtils.getTranslatedBedrockMessage(packet.getReason(), session.getClientData().getLanguageCode()));
|
session.disconnect(MessageUtils.getTranslatedBedrockMessage(packet.getReason(), session.getLocale()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class JavaTitleTranslator extends PacketTranslator<ServerTitlePacket> {
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerTitlePacket packet, GeyserSession session) {
|
public void translate(ServerTitlePacket packet, GeyserSession session) {
|
||||||
SetTitlePacket titlePacket = new SetTitlePacket();
|
SetTitlePacket titlePacket = new SetTitlePacket();
|
||||||
String locale = session.getClientData().getLanguageCode();
|
String locale = session.getLocale();
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case TITLE:
|
case TITLE:
|
||||||
|
|
|
@ -62,8 +62,8 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
.setNameTagVisibility(packet.getNameTagVisibility())
|
.setNameTagVisibility(packet.getNameTagVisibility())
|
||||||
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getLocale()))
|
||||||
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()));
|
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getLocale()));
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
if (team == null) {
|
if (team == null) {
|
||||||
|
@ -77,8 +77,8 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
.setNameTagVisibility(packet.getNameTagVisibility())
|
.setNameTagVisibility(packet.getNameTagVisibility())
|
||||||
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getLocale()))
|
||||||
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()))
|
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getLocale()))
|
||||||
.setUpdateType(UpdateType.UPDATE);
|
.setUpdateType(UpdateType.UPDATE);
|
||||||
break;
|
break;
|
||||||
case ADD_PLAYER:
|
case ADD_PLAYER:
|
||||||
|
|
|
@ -58,9 +58,9 @@ public class JavaOpenWindowTranslator extends PacketTranslator<ServerOpenWindowP
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(packet.getName()),
|
String name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(packet.getName()),
|
||||||
session.getClientData().getLanguageCode());
|
session.getLocale());
|
||||||
|
|
||||||
name = LocaleUtils.getLocaleString(name, session.getClientData().getLanguageCode());
|
name = LocaleUtils.getLocaleString(name, session.getLocale());
|
||||||
|
|
||||||
Inventory newInventory = new Inventory(name, packet.getWindowId(), packet.getType(), newTranslator.size + 36);
|
Inventory newInventory = new Inventory(name, packet.getWindowId(), packet.getType(), newTranslator.size + 36);
|
||||||
session.getInventoryCache().cacheInventory(newInventory);
|
session.getInventoryCache().cacheInventory(newInventory);
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
||||||
case INVALID_BED:
|
case INVALID_BED:
|
||||||
// Not sent as a proper message? Odd.
|
// Not sent as a proper message? Odd.
|
||||||
session.sendMessage(LocaleUtils.getLocaleString("block.minecraft.spawn.not_valid",
|
session.sendMessage(LocaleUtils.getLocaleString("block.minecraft.spawn.not_valid",
|
||||||
session.getClientData().getLanguageCode()));
|
session.getLocale()));
|
||||||
break;
|
break;
|
||||||
case ARROW_HIT_PLAYER:
|
case ARROW_HIT_PLAYER:
|
||||||
PlaySoundPacket arrowSoundPacket = new PlaySoundPacket();
|
PlaySoundPacket arrowSoundPacket = new PlaySoundPacket();
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
|
||||||
textPacket.setMessage("record.nowPlaying");
|
textPacket.setMessage("record.nowPlaying");
|
||||||
List<String> params = new ArrayList<>();
|
List<String> params = new ArrayList<>();
|
||||||
String recordString = "%item." + soundEvent.name().toLowerCase(Locale.ROOT) + ".desc";
|
String recordString = "%item." + soundEvent.name().toLowerCase(Locale.ROOT) + ".desc";
|
||||||
params.add(LocaleUtils.getLocaleString(recordString, session.getClientData().getLanguageCode()));
|
params.add(LocaleUtils.getLocaleString(recordString, session.getLocale()));
|
||||||
textPacket.setParameters(params);
|
textPacket.setParameters(params);
|
||||||
session.sendUpstreamPacket(textPacket);
|
session.sendUpstreamPacket(textPacket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ public class LanguageUtils {
|
||||||
*/
|
*/
|
||||||
public static void loadGeyserLocale(String locale) {
|
public static void loadGeyserLocale(String locale) {
|
||||||
locale = formatLocale(locale);
|
locale = formatLocale(locale);
|
||||||
|
// Don't load the locale if it's already loaded.
|
||||||
|
if (LOCALE_MAPPINGS.containsKey(locale)) return;
|
||||||
|
|
||||||
InputStream localeStream = GeyserConnector.class.getClassLoader().getResourceAsStream("languages/texts/" + locale + ".properties");
|
InputStream localeStream = GeyserConnector.class.getClassLoader().getResourceAsStream("languages/texts/" + locale + ".properties");
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ public class LanguageUtils {
|
||||||
* @param locale The locale to format
|
* @param locale The locale to format
|
||||||
* @return The formatted locale
|
* @return The formatted locale
|
||||||
*/
|
*/
|
||||||
private static String formatLocale(String locale) {
|
public static String formatLocale(String locale) {
|
||||||
try {
|
try {
|
||||||
String[] parts = locale.toLowerCase().split("_");
|
String[] parts = locale.toLowerCase().split("_");
|
||||||
return parts[0] + "_" + parts[1].toUpperCase();
|
return parts[0] + "_" + parts[1].toUpperCase();
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.geysermc.connector.GeyserConnector;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class LoginEncryptionUtils {
|
||||||
private static int AUTH_DETAILS_FORM_ID = 1337;
|
private static int AUTH_DETAILS_FORM_ID = 1337;
|
||||||
|
|
||||||
public static void showLoginWindow(GeyserSession session) {
|
public static void showLoginWindow(GeyserSession session) {
|
||||||
String userLanguage = session.getClientData().getLanguageCode();
|
String userLanguage = session.getLocale();
|
||||||
SimpleFormWindow window = new SimpleFormWindow(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.title", userLanguage), LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.desc", userLanguage));
|
SimpleFormWindow window = new SimpleFormWindow(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.title", userLanguage), LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.desc", userLanguage));
|
||||||
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.btn_login", userLanguage)));
|
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.btn_login", userLanguage)));
|
||||||
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.btn_disconnect", userLanguage)));
|
window.getButtons().add(new FormButton(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.notice.btn_disconnect", userLanguage)));
|
||||||
|
@ -169,7 +169,7 @@ public class LoginEncryptionUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showLoginDetailsWindow(GeyserSession session) {
|
public static void showLoginDetailsWindow(GeyserSession session) {
|
||||||
String userLanguage = session.getClientData().getLanguageCode();
|
String userLanguage = session.getLocale();
|
||||||
CustomFormWindow window = new CustomFormBuilder(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.title", userLanguage))
|
CustomFormWindow window = new CustomFormBuilder(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.title", userLanguage))
|
||||||
.addComponent(new LabelComponent(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.desc", userLanguage)))
|
.addComponent(new LabelComponent(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.desc", userLanguage)))
|
||||||
.addComponent(new InputComponent(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.email", userLanguage), "account@geysermc.org", ""))
|
.addComponent(new InputComponent(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.details.email", userLanguage), "account@geysermc.org", ""))
|
||||||
|
@ -210,7 +210,7 @@ public class LoginEncryptionUtils {
|
||||||
if (response.getClickedButtonId() == 0) {
|
if (response.getClickedButtonId() == 0) {
|
||||||
showLoginDetailsWindow(session);
|
showLoginDetailsWindow(session);
|
||||||
} else if(response.getClickedButtonId() == 1) {
|
} else if(response.getClickedButtonId() == 1) {
|
||||||
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getClientData().getLanguageCode()));
|
session.disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showLoginWindow(session);
|
showLoginWindow(session);
|
||||||
|
|
|
@ -485,7 +485,7 @@ public class MessageUtils {
|
||||||
*/
|
*/
|
||||||
public static boolean isTooLong(String message, GeyserSession session) {
|
public static boolean isTooLong(String message, GeyserSession session) {
|
||||||
if (message.length() > 256) {
|
if (message.length() > 256) {
|
||||||
session.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.chat.too_long", session.getClientData().getLanguageCode(), message.length()));
|
session.sendMessage(LanguageUtils.getPlayerLocaleString("geyser.chat.too_long", session.getLocale(), message.length()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class SettingsUtils {
|
||||||
*/
|
*/
|
||||||
public static void buildForm(GeyserSession session) {
|
public static void buildForm(GeyserSession session) {
|
||||||
// Cache the language for cleaner access
|
// Cache the language for cleaner access
|
||||||
String language = session.getClientData().getLanguageCode();
|
String language = session.getLocale();
|
||||||
|
|
||||||
CustomFormBuilder builder = new CustomFormBuilder(LanguageUtils.getPlayerLocaleString("geyser.settings.title.main", language));
|
CustomFormBuilder builder = new CustomFormBuilder(LanguageUtils.getPlayerLocaleString("geyser.settings.title.main", language));
|
||||||
builder.setIcon(new FormImage(FormImage.FormImageType.PATH, "textures/ui/settings_glyph_color_2x.png"));
|
builder.setIcon(new FormImage(FormImage.FormImageType.PATH, "textures/ui/settings_glyph_color_2x.png"));
|
||||||
|
|
Loading…
Reference in a new issue