mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 17:47:38 +01:00
Implemented the purge command
This commit is contained in:
parent
085f19355d
commit
1a62cecd58
@ -123,6 +123,19 @@ public class CommandManager {
|
||||
dungeonMazeCommand);
|
||||
listWorldCommand.setCommandPermissions("dungeonmaze.command.listworlds", CommandPermissions.DefaultPermission.OP_ONLY);*/
|
||||
|
||||
// Register the purge command
|
||||
CommandDescription purgeCommand = new CommandDescription(
|
||||
new ReloadCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("purge");
|
||||
add("delete");
|
||||
}},
|
||||
"Purge AuthMeReloaded data",
|
||||
"Purge old AuthMeReloaded data longer than the specified amount of days ago.",
|
||||
authMeCommand);
|
||||
purgeCommand.setCommandPermissions("authme.admin.purge", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
||||
|
||||
// Register the reload command
|
||||
CommandDescription reloadCommand = new CommandDescription(
|
||||
new ReloadCommand(),
|
||||
|
@ -0,0 +1,72 @@
|
||||
package fr.xephi.authme.command.executable;
|
||||
|
||||
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.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class PurgeCommand 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
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the days parameter
|
||||
String daysStr = commandArguments.get(0);
|
||||
|
||||
// Convert the days string to an integer value, and make sure it's valid
|
||||
int days;
|
||||
try {
|
||||
days = Integer.valueOf(daysStr);
|
||||
} catch(Exception ex) {
|
||||
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Validate the value
|
||||
if(days < 30) {
|
||||
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a calender instance to determine the date
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -days);
|
||||
long until = calendar.getTimeInMillis();
|
||||
|
||||
// Purge the data, get the purged values
|
||||
List<String> purged = plugin.database.autoPurgeDatabase(until);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
|
||||
// Purge other data
|
||||
if(Settings.purgeEssentialsFile && plugin.ess != null)
|
||||
plugin.dataManager.purgeEssentials(purged);
|
||||
if(Settings.purgePlayerDat)
|
||||
plugin.dataManager.purgeDat(purged);
|
||||
if(Settings.purgeLimitedCreative)
|
||||
plugin.dataManager.purgeLimitedCreative(purged);
|
||||
if(Settings.purgeAntiXray)
|
||||
plugin.dataManager.purgeAntiXray(purged);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GREEN + "[AuthMe] Database has been purged correctly");
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user