diff --git a/src/main/java/me/lorenzo0111/multilang/commands/AdminLangCommand.java b/src/main/java/me/lorenzo0111/multilang/commands/AdminLangCommand.java index b827369..e3c2469 100644 --- a/src/main/java/me/lorenzo0111/multilang/commands/AdminLangCommand.java +++ b/src/main/java/me/lorenzo0111/multilang/commands/AdminLangCommand.java @@ -28,6 +28,7 @@ import me.lorenzo0111.multilang.commands.executor.SubcommandExecutor; import me.lorenzo0111.multilang.commands.subcommands.admin.AdminHelpCommand; import me.lorenzo0111.multilang.commands.subcommands.admin.DebugCommand; +import me.lorenzo0111.multilang.commands.subcommands.admin.DetectCommand; import me.lorenzo0111.multilang.commands.subcommands.admin.ReloadCommand; import me.lorenzo0111.pluginslib.command.Customization; import me.lorenzo0111.pluginslib.command.ICommand; @@ -51,6 +52,7 @@ public AdminLangCommand(MultiLangPlugin plugin, String command, @Nullable Custom super(plugin, command, customization); this.addSubcommand(new ReloadCommand(this)); + this.addSubcommand(new DetectCommand(this)); this.addSubcommand(new DebugCommand(this)); try { Field subcommands = this.getClass().getSuperclass().getDeclaredField("subcommands"); diff --git a/src/main/java/me/lorenzo0111/multilang/commands/subcommands/EditCommand.java b/src/main/java/me/lorenzo0111/multilang/commands/subcommands/EditCommand.java index 96812b5..cbb25af 100644 --- a/src/main/java/me/lorenzo0111/multilang/commands/subcommands/EditCommand.java +++ b/src/main/java/me/lorenzo0111/multilang/commands/subcommands/EditCommand.java @@ -37,6 +37,7 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class EditCommand extends SubCommand { @@ -82,7 +83,7 @@ public void handleSubcommand(CommandSender commandSender, String[] args) { setLang(player,lang,this); } - public static void setLang(LocalizedPlayer player, String localeName, SubCommand subcommand) { + public static void setLang(@NotNull LocalizedPlayer player, String localeName, SubCommand subcommand) { if (player.getLocale().getName().equalsIgnoreCase(localeName)) { player.getPlayer().sendMessage(subcommand.format(MessagesManager.get("already"))); return; diff --git a/src/main/java/me/lorenzo0111/multilang/commands/subcommands/admin/DetectCommand.java b/src/main/java/me/lorenzo0111/multilang/commands/subcommands/admin/DetectCommand.java new file mode 100644 index 0000000..3cd8ad7 --- /dev/null +++ b/src/main/java/me/lorenzo0111/multilang/commands/subcommands/admin/DetectCommand.java @@ -0,0 +1,47 @@ +package me.lorenzo0111.multilang.commands.subcommands.admin; + +import me.lorenzo0111.multilang.MultiLangPlugin; +import me.lorenzo0111.multilang.api.objects.LocalizedPlayer; +import me.lorenzo0111.multilang.commands.SubCommand; +import me.lorenzo0111.multilang.commands.subcommands.EditCommand; +import me.lorenzo0111.multilang.utils.Reflection; +import me.lorenzo0111.pluginslib.command.ICommand; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class DetectCommand extends SubCommand { + + public DetectCommand(ICommand command) { + super(command); + } + + @Override + public String getName() { + return "detect"; + } + + @Override + public String getDescription() { + return "Force language auto-detection for a user"; + } + + @Override + public void handleSubcommand(CommandSender sender, String[] args) { + if (args.length != 2) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getPlugin().getConfig("prefix") + "&cTry using /alang detect (Player)")); + return; + } + + Player target = Bukkit.getPlayer(args[1]); + if (target == null || !target.isOnline()) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getPlugin().getConfig("prefix") + "&cThis user is not online")); + return; + } + + LocalizedPlayer player = LocalizedPlayer.from(target); + EditCommand.setLang(player, Reflection.getLocale(target), this); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getPlugin().getConfig("prefix") + "&7Locale autodetected to &9" + player.getLocale().getName())); + } +}