From 559072b3c642f4b60c6ca48a87a948d9a2d0ce23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 18:35:40 +0100 Subject: [PATCH] Implemented the purgelastposition command --- .../xephi/authme/command/CommandManager.java | 17 +++++ .../authme/PurgeLastPositionCommand.java | 64 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index b03e9e5f..0b600944 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -286,6 +286,23 @@ public class CommandManager { purgeCommand.setCommandPermissions("authme.admin.purge", CommandPermissions.DefaultPermission.OP_ONLY); purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false)); + // Register the purgelastposition command + CommandDescription purgeLastPositionCommand = new CommandDescription( + new PurgeLastPositionCommand(), + new ArrayList() {{ + add("purgelastposition"); + add("purgelastpos"); + add("resetposition"); + add("resetpos"); + add("resetlastposition"); + add("resetlastpos"); + }}, + "Purge player's last position", + "Purge the last know position of the specified player.", + authMeCommand); + purgeLastPositionCommand.setCommandPermissions("authme.admin.purgelastpos", CommandPermissions.DefaultPermission.OP_ONLY); + purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true)); + // Register the purgebannedplayers command CommandDescription purgeBannedPlayersCommand = new CommandDescription( new PurgeBannedPlayersCommand(), diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java new file mode 100644 index 00000000..e74e6651 --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java @@ -0,0 +1,64 @@ +package fr.xephi.authme.command.executable.authme; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.Messages; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class PurgeLastPositionCommand 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(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + // AuthMe plugin instance + final AuthMe plugin = AuthMe.getInstance(); + + // Messages instance + final Messages m = Messages.getInstance(); + + // Get the player + String playerName = sender.getName(); + if(commandArguments.getCount() >= 1) + playerName = commandArguments.get(0); + String playerNameLowerCase = playerName.toLowerCase(); + + // Purge the last position of the player + try { + // Get the user auth and make sure the user exists + PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase); + if (auth == null) { + m.send(sender, "unknown_user"); + return true; + } + + // Set the last position + auth.setQuitLocX(0D); + auth.setQuitLocY(0D); + auth.setQuitLocZ(0D); + auth.setWorld("world"); + plugin.database.updateQuitLoc(auth); + + // Show a status message + sender.sendMessage(playerNameLowerCase + "'s last position location is now reset"); + + } catch (Exception e) { + ConsoleLogger.showError("An error occurred while trying to reset location or player do not exist, please see below: "); + ConsoleLogger.showError(e.getMessage()); + if (sender instanceof Player) + sender.sendMessage("An error occurred while trying to reset location or player do not exist, please see logs"); + } + return true; + } +}