mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 03:25:24 +01:00
updated FlagInfo, don't check for commands directly in CommandRegionFlag, use FlagInfo
This commit is contained in:
parent
1d5c28f37f
commit
05239bccb0
@ -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();
|
||||
|
||||
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 ){
|
||||
|
||||
String spawnconfig = regions.getAreaFlag("spawn", "settings", true, null);
|
||||
Location spawn = regions.getLocationAreaFlag("spawn", player.getServer(), true, null);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,4 +135,4 @@ public GlobalRegionManager getGlobalRegionManager() {
|
||||
public WorldGuardConfiguration getWgConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,33 +89,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
boolean validValue = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
validValue = true;
|
||||
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;
|
||||
|
@ -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) {
|
||||
|
@ -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().
|
||||
*
|
||||
|
@ -93,11 +93,10 @@ public void run() {
|
||||
|
||||
|
||||
//check greeting/farewell flag
|
||||
ProtectedRegion newRegion = regions.getAffectedRegion();
|
||||
String newRegionName = null;
|
||||
String newRegionName = regions.getAffectedRegionId();
|
||||
|
||||
if (newRegion != null) {
|
||||
newRegionName = newRegion.getId();
|
||||
if (newRegionName != null) {
|
||||
|
||||
|
||||
if (nfo.lastRegion == null || !newRegionName.equals(nfo.lastRegion)) {
|
||||
String newGreetMsg = regions.getAreaFlag("msg", "g", null, true, null);
|
||||
|
Loading…
Reference in New Issue
Block a user