added /region priority command, fixed loading region parent loading

This commit is contained in:
Redecouverte 2011-02-25 22:37:56 +01:00
parent 55210caceb
commit 97b09aab34
7 changed files with 96 additions and 5 deletions

View File

@ -70,6 +70,8 @@ player-damage:
regions:
enable: on
claim-only-inside-existing-regions: off
max-region-count-per-player: 7
wand: 287
default:
build: on

View File

@ -38,6 +38,9 @@ worldguard.region.save
worldguard.region.setparent.own
worldguard.region.setparent.all
worldguard.region.priority
worldguard.reloadwg
worldguard.region.delete.own
@ -51,3 +54,5 @@ worldguard.tpregion
worldguard.tpregion.spawn
worldguard.buyregion
worldedit.region.nolimit

View File

@ -23,7 +23,7 @@ commands:
aliases: ;
region:
description: Adjust protected regions
usage: /<command> <define|claim|setparent|flag|delete|info|addowner|removeowner|addmember|removemember|list|save|load> ...
usage: /<command> <define|claim|setparent|flag|delete|info|addowner|removeowner|addmember|removemember|list|save|load|priority> ...
aliases: rg, regions
locate:
description: Set your compass towards a person

View File

@ -0,0 +1,74 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardWorldConfiguration;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/**
*
* @author Michael
*/
public class CommandRegionPriority extends WgRegionCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg, WorldGuardWorldConfiguration wcfg) throws CommandHandlingException {
CommandHandler.checkArgs(args, 1, 2, "/region priority <id> (<value>)");
cfg.checkRegionPermission(sender, "region.priority");
try {
String id = args[0].toLowerCase();
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(wcfg.getWorldName());
if (!mgr.hasRegion(id)) {
sender.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = mgr.getRegion(id);
if (args.length > 1) {
try {
Integer prio = Integer.valueOf(args[1]);
existing.setPriority(prio);
mgr.save();
sender.sendMessage(ChatColor.YELLOW + "Priority of region " + existing.getId() + " set to " + prio.toString());
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Not a valid number: " + args[1]);
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Priority of region " + existing.getId() + " is " + existing.getPriority());
}
} catch (IOException e) {
sender.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -54,6 +54,7 @@ public RegionCommandHandler() {
this.commandMap.put("delete", new CommandRegionDelete());
this.commandMap.put("addmember", addmember);
this.commandMap.put("addowner", addmember);
this.commandMap.put("priority", new CommandRegionPriority());
// commands that DO NOT support console as sender
this.commandMap.put("define", new CommandRegionDefine());

View File

@ -76,10 +76,10 @@ public Map<String, ProtectedRegion> getRegions() {
String id = entry.getKey();
ProtectedRegion region = entry.getValue();
ProtectedRegion parent = region.getParent();
if (parent != null) {
String parentId = region.getParentId();
if (parentId != null) {
try {
region.setParent(ret.get(parent.getId()));
region.setParent(ret.get(parentId));
} catch (CircularInheritanceException ex) {
}
} else {

View File

@ -78,6 +78,15 @@ public String getId() {
}
public String getParentId() {
if (this.parent != null) {
this.parentId = parent.getId();
}
return this.parentId;
}
/**
* @setFlag the parentId. Used for serialization, don't touch it.
*/