diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 0040b677..70b147d4 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -236,7 +236,20 @@ public class CommandManager { "Get the IP address of the specified online player.", authMeCommand); getIpCommand.setCommandPermissions("authme.admin.getip", CommandPermissions.DefaultPermission.OP_ONLY); - getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", false)); + getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true)); + + // Register the forcelogin command + CommandDescription forceLoginCommand = new CommandDescription( + new ForceLoginCommand(), + new ArrayList() {{ + add("forcelogin"); + add("login"); + }}, + "Force login player", + "Force the specified player to login.", + authMeCommand); + forceLoginCommand.setCommandPermissions("authme.admin.forcelogin", CommandPermissions.DefaultPermission.OP_ONLY); + forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true)); // Register the spawn command CommandDescription spawnCommand = new CommandDescription( diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java new file mode 100644 index 00000000..e4f285be --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java @@ -0,0 +1,51 @@ +package fr.xephi.authme.command.executable.authme; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ForceLoginCommand extends ExecutableCommand { + + /** + * Execute the command. + * + * @param sender The command sender. + * @param commandReference The command reference. + * @param commandArguments The command arguments. + * + * @return True if the command was executed successfully, false otherwise. + */ + @Override + public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + // AuthMe plugin instance + final AuthMe plugin = AuthMe.getInstance(); + + // Get the player query + String playerName = sender.getName(); + if(commandArguments.getCount() >= 1) + playerName = commandArguments.get(0); + + // Command logic + try { + @SuppressWarnings("deprecation") + Player player = Bukkit.getPlayer(playerName); + if (player == null || !player.isOnline()) { + sender.sendMessage("Player needs to be online!"); + return true; + } + if (!plugin.authmePermissible(player, "authme.canbeforced")) { + sender.sendMessage("You cannot force login for the player " + playerName + "!"); + return true; + } + plugin.management.performLogin(player, "dontneed", true); + sender.sendMessage("Force Login for " + playerName + " performed!"); + } catch (Exception e) { + sender.sendMessage("An error occurred while trying to get that player!"); + } + + return true; + } +}