From 8ead129423add129a39aac5fabc37aadb3655475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 18:23:03 +0100 Subject: [PATCH] Implemented the firstspawn command --- .../xephi/authme/command/CommandManager.java | 12 ++++++ .../executable/authme/FirstSpawnCommand.java | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 5d48133d..02e77267 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -219,6 +219,18 @@ public class CommandManager { authMeCommand); setSpawnCommand.setCommandPermissions("authme.admin.setspawn", CommandPermissions.DefaultPermission.OP_ONLY); + // Register the firstspawn command + CommandDescription firstSpawnCommand = new CommandDescription( + new FirstSpawnCommand(), + new ArrayList() {{ + add("firstspawn"); + add("firsthome"); + }}, + "Teleport to first spawn", + "Teleport to the first spawn.", + authMeCommand); + firstSpawnCommand.setCommandPermissions("authme.admin.firstspawn", CommandPermissions.DefaultPermission.OP_ONLY); + // Register the setfirstspawn command CommandDescription setFirstSpawnCommand = new CommandDescription( new SetFirstSpawnCommand(), diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java new file mode 100644 index 00000000..4cf5789d --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java @@ -0,0 +1,37 @@ +package fr.xephi.authme.command.executable.authme; + +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.Spawn; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class FirstSpawnCommand 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) { + // Make sure the command executor is a player + try { + if (sender instanceof Player) { + if (Spawn.getInstance().getFirstSpawn() != null) + ((Player) sender).teleport(Spawn.getInstance().getFirstSpawn()); + else sender.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn"); + } else { + sender.sendMessage("[AuthMe] Please use that command in game"); + } + } catch (NullPointerException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + return true; + } +}