Implemented the unregister command

This commit is contained in:
Tim Visée 2015-11-01 18:30:29 +01:00
parent 2d935d5fef
commit e4d46ae9b9
2 changed files with 113 additions and 0 deletions

View File

@ -138,6 +138,21 @@ public class CommandManager {
registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false)); registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false)); registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the unregister command
CommandDescription unregisterCommand = new CommandDescription(
new UnregisterCommand(),
new ArrayList<String>() {{
add("unregister");
add("unreg");
add("delete");
add("del");
}},
"Unregister a player",
"Unregister the specified player.",
authMeCommand);
unregisterCommand.setCommandPermissions("authme.admin.unregister", CommandPermissions.DefaultPermission.OP_ONLY);
unregisterCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
// Register the changepassword command // Register the changepassword command
CommandDescription changePasswordCommand = new CommandDescription( CommandDescription changePasswordCommand = new CommandDescription(
new RegisterCommand(), new RegisterCommand(),

View File

@ -0,0 +1,98 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
public class UnregisterCommand 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 name
String playerName = commandArguments.get(0);
String playerNameLowerCase = playerName.toLowerCase();
// Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, "user_unknown");
return true;
}
// Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) {
m.send(sender, "error");
return true;
}
// Unregister the player
@SuppressWarnings("deprecation")
Player target = Bukkit.getPlayer(playerNameLowerCase);
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
if (target != null) {
if (target.isOnline()) {
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
Location spawn = plugin.getSpawnLocation(target);
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
target.teleport(tpEvent.getTo());
}
}
LimboCache.getInstance().addLimboPlayer(target);
int delay = Settings.getRegistrationTimeout * 20;
int interval = Settings.getWarnMessageInterval;
BukkitScheduler scheduler = sender.getServer().getScheduler();
if (delay != 0) {
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
}
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
if (Settings.applyBlindEffect)
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
target.setWalkSpeed(0.0f);
target.setFlySpeed(0.0f);
}
m.send(target, "unregistered");
}
}
// Show a status message
m.send(sender, "unregistered");
ConsoleLogger.info(playerName + " unregistered");
return true;
}
}