added aliases /rd, /rc, /rf, /ri, /rl, /rp for region commands

This commit is contained in:
Redecouverte 2011-02-26 12:24:49 +01:00
parent a258400443
commit 0669bab563
4 changed files with 59 additions and 18 deletions

View File

@ -24,7 +24,7 @@ commands:
region: region:
description: Adjust protected regions description: Adjust protected regions
usage: /<command> <define|claim|setparent|flag|delete|info|addowner|removeowner|addmember|removemember|list|save|load|priority> ... usage: /<command> <define|claim|setparent|flag|delete|info|addowner|removeowner|addmember|removemember|list|save|load|priority> ...
aliases: rg, regions aliases: rg, regions, rd, rc, rsp, rf, rdel, ri, rao, rro, rl, rp
locate: locate:
description: Set your compass towards a person description: Set your compass towards a person
usage: /<command> <target> usage: /<command> <target>

View File

@ -255,13 +255,12 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
player.getWorld().getName()).getApplicableRegions( player.getWorld().getName()).getApplicableRegions(
BukkitUtil.toVector(location)); BukkitUtil.toVector(location));
BukkitPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
String spawnconfig = regions.getAreaFlag("spawn", "settings", true, null);
Location spawn = regions.getLocationAreaFlag("spawn", player.getServer(), true, null); Location spawn = regions.getLocationAreaFlag("spawn", player.getServer(), true, null);
if (spawn != null) { if (spawn != null) {
String spawnconfig = regions.getAreaFlag("spawn", "settings", true, null);
if (spawnconfig != null) { if (spawnconfig != null) {
BukkitPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
if (spawnconfig.equals("owner")) { if (spawnconfig.equals("owner")) {
if (regions.isOwner(localPlayer)) { if (regions.isOwner(localPlayer)) {
player.teleportTo(spawn); player.teleportTo(spawn);

View File

@ -44,11 +44,19 @@ public CommandHandler(WorldGuardPlugin wg)
this.wg = wg; this.wg = wg;
this.commandMap = new HashMap<String, WgCommand>(); this.commandMap = new HashMap<String, WgCommand>();
WgCommand regionHandler = new RegionCommandHandler();
// commands that DO support console as sender // commands that DO support console as sender
this.commandMap.put("allowfire", new CommandAllowFire()); this.commandMap.put("allowfire", new CommandAllowFire());
this.commandMap.put("god", new CommandGod()); this.commandMap.put("god", new CommandGod());
this.commandMap.put("heal", new CommandHeal()); this.commandMap.put("heal", new CommandHeal());
this.commandMap.put("region", new RegionCommandHandler()); this.commandMap.put("region", regionHandler);
this.commandMap.put("rd", regionHandler);
this.commandMap.put("rc", regionHandler);
this.commandMap.put("rf", regionHandler);
this.commandMap.put("ri", regionHandler);
this.commandMap.put("rl", regionHandler);
this.commandMap.put("rp", regionHandler);
this.commandMap.put("reloadwg", new CommandReloadWG()); this.commandMap.put("reloadwg", new CommandReloadWG());
this.commandMap.put("slay", new CommandSlay()); this.commandMap.put("slay", new CommandSlay());
this.commandMap.put("stopfire", new CommandStopFire()); this.commandMap.put("stopfire", new CommandStopFire());

View File

@ -35,9 +35,11 @@
public class RegionCommandHandler extends WgCommand { public class RegionCommandHandler extends WgCommand {
private Map<String, WgRegionCommand> commandMap; private Map<String, WgRegionCommand> commandMap;
private Map<String, String> aliasMap;
public RegionCommandHandler() { public RegionCommandHandler() {
this.commandMap = new HashMap<String, WgRegionCommand>(); this.commandMap = new HashMap<String, WgRegionCommand>();
this.aliasMap = new HashMap<String, String>();
WgRegionCommand addmember = new CommandRegionAddMember(); WgRegionCommand addmember = new CommandRegionAddMember();
WgRegionCommand removemember = new CommandRegionRemoveMember(); WgRegionCommand removemember = new CommandRegionRemoveMember();
@ -60,21 +62,46 @@ public RegionCommandHandler() {
this.commandMap.put("define", new CommandRegionDefine()); this.commandMap.put("define", new CommandRegionDefine());
this.commandMap.put("claim", new CommandRegionClaim()); this.commandMap.put("claim", new CommandRegionClaim());
this.aliasMap.put("rd", "define");
this.aliasMap.put("rc", "claim");
this.aliasMap.put("rf", "flag");
this.aliasMap.put("ri", "info");
this.aliasMap.put("rl", "list");
this.aliasMap.put("rp", "priority");
} }
public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg) throws CommandHandlingException { public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg) throws CommandHandlingException {
String worldName; String worldName;
String subCommand; String subCommand;
int argsStartAt;
if (!command.equals("region")) {
subCommand = this.aliasMap.get(command);
if (subCommand == null) {
return false;
}
if (sender instanceof Player) {
worldName = ((Player) sender).getWorld().getName();
argsStartAt = 0;
} else {
CommandHandler.checkArgs(args, 1, -1);
worldName = args[0];
argsStartAt = 1;
}
} else {
if (sender instanceof Player) { if (sender instanceof Player) {
CommandHandler.checkArgs(args, 1, -1); CommandHandler.checkArgs(args, 1, -1);
worldName = ((Player) sender).getWorld().getName(); worldName = ((Player) sender).getWorld().getName();
subCommand = args[0].toLowerCase(); subCommand = args[0].toLowerCase();
argsStartAt = 1;
} else { } else {
CommandHandler.checkArgs(args, 2, -1); CommandHandler.checkArgs(args, 2, -1);
worldName = args[0]; worldName = args[0];
subCommand = args[1].toLowerCase(); subCommand = args[1].toLowerCase();
argsStartAt = 2;
}
} }
Server server = cfg.getWorldGuardPlugin().getServer(); Server server = cfg.getWorldGuardPlugin().getServer();
@ -96,16 +123,23 @@ public boolean handle(CommandSender sender, String senderName, String command, S
} }
String[] subArgs; String[] subArgs;
if (sender instanceof Player) { if (argsStartAt > 0) {
subArgs = new String[args.length - 1]; subArgs = new String[args.length - argsStartAt];
System.arraycopy(args, 1, subArgs, 0, args.length - 1); System.arraycopy(args, argsStartAt, subArgs, 0, args.length - argsStartAt);
} else { } else {
subArgs = new String[args.length - 2]; subArgs = args;
System.arraycopy(args, 2, subArgs, 0, args.length - 2);
} }
wgcmd.handle(sender, senderName, subCommand, subArgs, cfg, wcfg); wgcmd.handle(sender, senderName, subCommand, subArgs, cfg, wcfg);
return true; return true;
} }
private String getCommandFromAlias(String alias) {
if (alias.equals("rf")) {
return "flag";
}
return "";
}
} }