1
0
mirror of https://e.coding.net/circlecloud/Residence.git synced 2025-11-24 21:46:16 +00:00

convert command to subclass...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-09-23 20:56:52 +08:00
parent 371be069c6
commit 6b0f5ac789
9 changed files with 475 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
package com.bekvon.bukkit.residence.commandmain;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.commandsub.CommandConfirm;
import com.bekvon.bukkit.residence.commandsub.CommandRemove;
import com.bekvon.bukkit.residence.commandsub.CommandSetOwner;
import com.bekvon.bukkit.residence.commandsub.CommandVersion;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
public class CommandRes extends BaseCommand {
Residence plugin;
HandlerSubCommand hdsubcmd;
public CommandRes(Residence plugin) {
super("res", "residence", "resadmin");
this.plugin = plugin;
hdsubcmd = new HandlerSubCommand(plugin);
hdsubcmd.registerCommand(new CommandConfirm(plugin));
hdsubcmd.registerCommand(new CommandRemove(plugin));
hdsubcmd.registerCommand(new CommandVersion(plugin));
hdsubcmd.registerCommand(new CommandSetOwner(plugin));
// Player player = null;
// boolean resadmin = (command != null);
// ResidenceManager rmanager = Residence.getResidenceManager();
// Map<String, String> deleteConfirm = plugin.deleteConfirm;
// Language language = Residence.getLanguage();
plugin.getCommand("residence").setTabCompleter(hdsubcmd);
}
@Override
public void execute(CommandSender sender, Command command, String label, String[] args) throws CommandException {
boolean resadmin = false;
if (sender instanceof Player) {
if (label.equalsIgnoreCase("resadmin"))
if (Residence.getPermissionManager().isResidenceAdmin((Player) sender))
resadmin = true;
else
sender.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NonAdmin"));
} else
resadmin = true;
if (args.length > 0 && args[args.length - 1].equalsIgnoreCase("?") || args.length > 1 && args[args.length - 2].equals("?")) {
commandHelp(args, resadmin, sender);
return;
}
if (Residence.getConfigManager().allowAdminsOnly())
if (!resadmin) {
sender.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AdminOnly"));
return;
}
if (args.length == 0)
return;
hdsubcmd.onCommand(sender, resadmin ? command : null, label, args);
}
private boolean commandHelp(String[] args, boolean resadmin, CommandSender sender) {
if (Residence.helppages != null) {
String helppath = "res";
for (String arg : args) {
if (arg.equalsIgnoreCase("?"))
break;
helppath = helppath + "." + arg;
}
int page = 1;
if (!args[args.length - 1].equalsIgnoreCase("?"))
try {
page = Integer.parseInt(args[args.length - 1]);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidHelp"));
}
if (Residence.helppages.containesEntry(helppath)) {
Residence.helppages.printHelp(sender, page, helppath);
return true;
}
}
return false;
}
}