Implemented the purgebannedplayers command

This commit is contained in:
Tim Visée 2015-11-01 18:17:13 +01:00
parent 17c103a7b2
commit 4ff8cb8c59
2 changed files with 64 additions and 0 deletions

View File

@ -232,6 +232,20 @@ public class CommandManager {
purgeCommand.setCommandPermissions("authme.admin.purge", CommandPermissions.DefaultPermission.OP_ONLY);
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
// Register the purgebannedplayers command
CommandDescription purgeBannedPlayersCommand = new CommandDescription(
new PurgeBannedPlayersCommand(),
new ArrayList<String>() {{
add("purgebannedplayers");
add("purgebannedplayer");
add("deletebannedplayers");
add("deletebannedplayer");
}},
"Purge banned palyers data",
"Purge all AuthMeReloaded data for banned players.",
authMeCommand);
purgeBannedPlayersCommand.setCommandPermissions("authme.admin.purgebannedplayers", CommandPermissions.DefaultPermission.OP_ONLY);
// Register the reload command
CommandDescription reloadCommand = new CommandDescription(
new ReloadCommand(),

View File

@ -0,0 +1,50 @@
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 fr.xephi.authme.settings.Settings;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
public class PurgeBannedPlayersCommand 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 list of banned players
List<String> bannedPlayers = new ArrayList<>();
for (OfflinePlayer offlinePlayer : plugin.getServer().getBannedPlayers()) {
bannedPlayers.add(offlinePlayer.getName().toLowerCase());
}
// Purge the banned players
plugin.database.purgeBanned(bannedPlayers);
if (Settings.purgeEssentialsFile && plugin.ess != null)
plugin.dataManager.purgeEssentials(bannedPlayers);
if (Settings.purgePlayerDat)
plugin.dataManager.purgeDat(bannedPlayers);
if (Settings.purgeLimitedCreative)
plugin.dataManager.purgeLimitedCreative(bannedPlayers);
if (Settings.purgeAntiXray)
plugin.dataManager.purgeAntiXray(bannedPlayers);
// Show a status message
sender.sendMessage("[AuthMe] Database has been purged correctly");
return true;
}
}