updated FlagInfo, don't check for commands directly in CommandRegionFlag, use FlagInfo

This commit is contained in:
Redecouverte 2011-02-26 00:51:35 +01:00
parent 1d5c28f37f
commit 05239bccb0
6 changed files with 58 additions and 74 deletions

View File

@ -251,6 +251,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
}
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
Location location = player.getLocation();
@ -262,21 +263,15 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
BukkitUtil.toVector(location));
BukkitPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
ProtectedRegion childRegion = regions.getChildRegion();
AreaFlags flags = childRegion.getFlags();
String spawnconfig = regions.getAreaFlag("spawn", "settings", true, null);
Location spawn = regions.getLocationAreaFlag("spawn", player.getServer(), true, null);
Boolean owner = flags.getBooleanFlag("spawn", "settings.owner", true);
Boolean member = flags.getBooleanFlag("spawn", "settings.owner", true);
Boolean all = flags.getBooleanFlag("spawn", "settings.owner", false);
Location spawn = flags.getLocationFlag(player.getServer(), "spawn");
if(childRegion.isOwner(localPlayer) && owner ){
if(spawnconfig.equals("owner") && regions.isOwner(localPlayer)){
player.teleportTo(spawn);
} else if (childRegion.isMember(localPlayer) && member) {
} else if (spawnconfig.equals("member") && regions.isMember(localPlayer)) {
player.teleportTo(spawn);
} else if (all){
} else {
player.teleportTo(spawn);
}

View File

@ -92,9 +92,9 @@ private void registerEvents() {
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.REDSTONE_CHANGE, blockListener, Priority.High, this);
// pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High, this);
// pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.High, this);
// pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.High, this);
@ -107,7 +107,7 @@ private void registerEvents() {
pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this);
// 25 equals about 1s real time
// this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
}
/**

View File

@ -90,32 +90,6 @@ public boolean handle(CommandSender sender, String senderName, String command, S
switch (nfo.type) {
case STRING: {
validValue = true;
if(nfo.name.equals("teleport") || nfo.name.equals("spawn")){
if (valueStr.equals("all")) {
if(nfo.subName.equals("allow")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, true);
}else if(nfo.subName.equals("deny")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, false);
}
} else if (valueStr.equals("owner")){
if(nfo.subName.equals("allow")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, true);
}else if(nfo.subName.equals("deny")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, false);
}
} else if (valueStr.equals("member")){
if(nfo.subName.equals("allow")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, true);
}else if(nfo.subName.equals("deny")){
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName+"."+valueStr, false);
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: /region flag "+id+" "+nfo.name+" "+nfo.subName+" (all|owner|member)");
validValue=false;
}
}
break;
}
case INT: {
@ -135,14 +109,6 @@ public boolean handle(CommandSender sender, String senderName, String command, S
valueStr = "true";
} else if (valueStr.equals("1")) {
valueStr = "true";
} else if (valueStr.equals("off")){
valueStr="false";
} else if (valueStr.equals("deny")){
valueStr="false";
}else if(valueStr.equals("0")){
valueStr="false";
} else{
validValue = false;
}
validValue = true;
break;

View File

@ -60,12 +60,12 @@ public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE, L
flagList.add(new FlagInfo("iconomy", "price", FlagValueType.INT, "iconomy", "price"));
flagList.add(new FlagInfo("spawn", "set", FlagValueType.LOCATION, "spawn", ""));
flagList.add(new FlagInfo("spawn", "delete", FlagValueType.LOCATION, "spawn", ""));
flagList.add(new FlagInfo("spawn", "allow", FlagValueType.STRING, "spawn", "settings"));
flagList.add(new FlagInfo("spawn", "deny", FlagValueType.STRING, "spawn", "settings"));
flagList.add(new FlagInfo("spawn", "allow", FlagValueType.STRING, "spawn", "allow"));
flagList.add(new FlagInfo("spawn", "deny", FlagValueType.STRING, "spawn", "deny"));
flagList.add(new FlagInfo("teleport", "set", FlagValueType.LOCATION, "teleport", ""));
flagList.add(new FlagInfo("teleport", "delete", FlagValueType.LOCATION, "teleport", ""));
flagList.add(new FlagInfo("teleport", "allow", FlagValueType.STRING, "teleport", "settings"));
flagList.add(new FlagInfo("teleport", "deny", FlagValueType.STRING, "teleport", "settings"));
flagList.add(new FlagInfo("teleport", "allow", FlagValueType.STRING, "teleport", "allow"));
flagList.add(new FlagInfo("teleport", "deny", FlagValueType.STRING, "teleport", "deny"));
}
public static FlagInfo getFlagInfo(String name, String subName) {

View File

@ -19,17 +19,12 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Server;
@ -43,6 +38,7 @@ public class ApplicableRegionSet {
private GlobalFlags global;
private Vector pt;
private List<ProtectedRegion> applicable;
private ProtectedRegion affectedRegion;
/**
* Construct the object.
@ -56,6 +52,8 @@ public ApplicableRegionSet(Vector pt, List<ProtectedRegion> applicable,
this.pt = pt;
this.applicable = applicable;
this.global = global;
determineAffectedRegion();
}
/**
@ -70,13 +68,10 @@ public boolean canBuild(LocalPlayer player) {
return global.canBuild;
}
ProtectedRegion affectedRegion = getAffectedRegion();
if (affectedRegion == null) {
return global.canBuild;
}
String data = getAreaFlag("states", AreaFlags.FLAG_BUILD, true, null, affectedRegion);
State state;
@ -252,12 +247,22 @@ private String getAreaFlag(String name, String subname, Boolean inherit, LocalPl
}
/**
* Gets the region with the hightest priority that is not a parent.
* Gets the region with the hightest priority.
*
*/
public ProtectedRegion getAffectedRegion() {
private ProtectedRegion getAffectedRegion() {
ProtectedRegion affectedRegion = null;
return affectedRegion;
}
/**
* Determines the region with the hightest priority that is not a parent.
*
*/
private void determineAffectedRegion() {
affectedRegion = null;
Iterator<ProtectedRegion> iter = applicable.iterator();
while (iter.hasNext()) {
@ -267,10 +272,9 @@ public ProtectedRegion getAffectedRegion() {
affectedRegion = region;
}
}
return affectedRegion;
}
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player) {
String data = getAreaFlag(name, subname, inherit, player);
return data != null ? data : defaultValue;
@ -385,6 +389,26 @@ public Location getLocationAreaFlag(String name, Server server, Boolean inherit,
}
}
public boolean isOwner(LocalPlayer player) {
return affectedRegion != null ? affectedRegion.isOwner(player) : false;
}
/**
* Checks whether a player is a member of the region or any of its parents.
*
* @param player
* @return
*/
public boolean isMember(LocalPlayer player) {
return affectedRegion != null ? affectedRegion.isMember(player) : false;
}
public String getAffectedRegionId() {
return affectedRegion != null ? affectedRegion.getId() : "";
}
/**
* Clear a region's parents for isFlagAllowed().
*

View File

@ -93,11 +93,10 @@ public void run() {
//check greeting/farewell flag
ProtectedRegion newRegion = regions.getAffectedRegion();
String newRegionName = null;
String newRegionName = regions.getAffectedRegionId();
if (newRegionName != null) {
if (newRegion != null) {
newRegionName = newRegion.getId();
if (nfo.lastRegion == null || !newRegionName.equals(nfo.lastRegion)) {
String newGreetMsg = regions.getAreaFlag("msg", "g", null, true, null);