diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index d08fe26b2..bf1d10b6a 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -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() {{ + 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(), diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java new file mode 100644 index 000000000..32c2937c7 --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java @@ -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 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; + } +}