Update /mcpurge command to use Bukkit CommandAPI. Addresses #628

This commit is contained in:
GJ 2013-02-05 12:50:09 -05:00
parent 2d9dc92f83
commit ab92aa3ffa
5 changed files with 30 additions and 19 deletions

View File

@ -19,6 +19,8 @@ import com.gmail.nossr50.commands.player.McmmoCommand;
import com.gmail.nossr50.commands.player.McrankCommand;
import com.gmail.nossr50.commands.player.McstatsCommand;
import com.gmail.nossr50.commands.player.MctopCommand;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.commands.McpurgeCommand;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
@ -252,4 +254,13 @@ public final class CommandRegistrationHelper {
command.setUsage(LocaleLoader.getString("Commands.Usage.2", "mctop", "[" + LocaleLoader.getString("Commands.Usage.Skill") + "]", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"));
command.setExecutor(new MctopCommand());
}
public static void registerMcpurgeCommand() {
PluginCommand command = mcMMO.p.getCommand("mcpurge");
command.setDescription(LocaleLoader.getString("Commands.Description.mcpurge", Config.getInstance().getOldUsersCutoff()));
command.setPermission("mcmmo.commands.mcpurge");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcpurge"));
command.setExecutor(new McpurgeCommand());
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.locale.LocaleLoader;
@ -12,22 +11,24 @@ import com.gmail.nossr50.locale.LocaleLoader;
public class McpurgeCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcpurge")) {
return true;
}
switch (args.length) {
case 0:
if (Config.getInstance().getUseMySQL()) {
Database.purgePowerlessSQL();
if (Config.getInstance().getUseMySQL()) {
Database.purgePowerlessSQL();
if (Config.getInstance().getOldUsersCutoff() != -1) {
Database.purgeOldSQL();
if (Config.getInstance().getOldUsersCutoff() != -1) {
Database.purgeOldSQL();
}
}
else {
//TODO: Make this work for Flatfile data.
}
}
else {
//TODO: Make this work for Flatfile data.
}
sender.sendMessage(LocaleLoader.getString("Commands.mcpurge.Success"));
return true;
sender.sendMessage(LocaleLoader.getString("Commands.mcpurge.Success"));
return true;
default:
return false;
}
}
}

View File

@ -30,7 +30,6 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.commands.McpurgeCommand;
import com.gmail.nossr50.database.commands.McremoveCommand;
import com.gmail.nossr50.database.commands.MmoupdateCommand;
import com.gmail.nossr50.database.runnables.UserPurgeTask;
@ -277,7 +276,7 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerSkillCommands();
// mc* commands
getCommand("mcpurge").setExecutor(new McpurgeCommand());
CommandRegistrationHelper.registerMcpurgeCommand();
getCommand("mcremove").setExecutor(new McremoveCommand());
CommandRegistrationHelper.registerMcabilityCommand();
getCommand("mcc").setExecutor(new MccCommand());

View File

@ -695,6 +695,7 @@ Commands.Description.inspect=View detailed mcMMO info on another player
Commands.Description.mcability=Toggle mcMMO abilities being readied on right-click on/off
Commands.Description.mcgod=Toggle mcMMO god-mode on/off
Commands.Description.mcmmo=Show a brief description of mcMMO
Commands.Description.mcpurge=Purge users with no mcMMO levels and/or who haven't connected in over {0} months from the server DB.
Commands.Description.mcrank=Show mcMMO ranking for a player
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mcstats=Show your mcMMO levels and XP

View File

@ -100,8 +100,7 @@ commands:
aliases: []
description: Toggle Admin chat or send admin chat messages
mcpurge:
aliases: []
description: Purge users with 0 powerlevel and/or who haven't connected in over 30 days from the server DB.
description: Purge users with 0 powerlevel and/or who haven't connected in several months from the server DB.
permissions:
mcmmo.*:
default: false