mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-28 05:25:20 +01:00
Added 'entry' flag to deny entry.
This commit is contained in:
parent
767c49f9fa
commit
e26f6b5e8d
@ -23,6 +23,8 @@
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -236,10 +238,34 @@ public void onPlayerMove(PlayerMoveEvent event) {
|
||||
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
||||
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
|
||||
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Vector pt = toVector(event.getTo());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
|
||||
if (!entryAllowed && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area.");
|
||||
|
||||
// Make sure that we don't get the player stuck
|
||||
/*if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
||||
&& event.getFrom().getBlockY() > event.getTo().getBlockY()
|
||||
&& BlockType.canPassThrough(event.getFrom().getBlock().getRelative(0, -1, 0).getTypeId())) {
|
||||
event.setTo(world.getSpawnLocation());
|
||||
player.sendMessage(ChatColor.GRAY + "Because you fell vertically into a forbidden area, you have been sent to spawn so as to not get stuck.");
|
||||
return;
|
||||
}*/
|
||||
|
||||
Location newLoc = event.getFrom();
|
||||
newLoc.setX(newLoc.getBlockX() + 0.5);
|
||||
newLoc.setY(newLoc.getBlockY());
|
||||
newLoc.setZ(newLoc.getBlockZ() + 0.5);
|
||||
event.setTo(newLoc);
|
||||
return;
|
||||
}
|
||||
|
||||
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE);
|
||||
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);
|
||||
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);
|
||||
@ -822,15 +848,9 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if (group != null) {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (group == RegionGroup.OWNERS) {
|
||||
if (set.isOwnerOfAll(localPlayer)) {
|
||||
if (RegionGroupFlag.isMember(set, group, localPlayer)) {
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
} else if (group == RegionGroup.MEMBERS) {
|
||||
if (set.isMemberOfAll(localPlayer)) {
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
|
@ -60,17 +60,17 @@ public ApplicableRegionSet(Collection<ProtectedRegion> applicable,
|
||||
* @return
|
||||
*/
|
||||
public boolean canBuild(LocalPlayer player) {
|
||||
return internalGetState(DefaultFlag.BUILD, player);
|
||||
return internalGetState(DefaultFlag.BUILD, player, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player can build in an area.
|
||||
* Checks if a player can use items in an area.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean canUse(LocalPlayer player) {
|
||||
return internalGetState(DefaultFlag.USE, player);
|
||||
return internalGetState(DefaultFlag.USE, player, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +80,17 @@ public boolean canUse(LocalPlayer player) {
|
||||
* @return
|
||||
*/
|
||||
public boolean allows(StateFlag flag) {
|
||||
return internalGetState(flag, null);
|
||||
return internalGetState(flag, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
public boolean allows(StateFlag flag, LocalPlayer player) {
|
||||
return internalGetState(flag, null, flag.getGroupFlag(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,13 +129,15 @@ public boolean isMemberOfAll(LocalPlayer player) {
|
||||
/**
|
||||
* Checks to see if a flag is permitted.
|
||||
*
|
||||
* @param def
|
||||
* default state if there are no regions defined
|
||||
* @param player
|
||||
* null to not check owners and members
|
||||
* @param flag flag to check
|
||||
* @param player null to not check owners and members
|
||||
* @param groupFlag group flag to check
|
||||
* @param groupPlayer player to use for the group flag check
|
||||
* @return
|
||||
*/
|
||||
private boolean internalGetState(StateFlag flag, LocalPlayer player) {
|
||||
private boolean internalGetState(StateFlag flag, LocalPlayer player,
|
||||
RegionGroupFlag groupFlag,
|
||||
LocalPlayer groupPlayer) {
|
||||
boolean found = false;
|
||||
boolean allowed = false; // Used for ALLOW override
|
||||
boolean def = flag.getDefault();
|
||||
@ -187,6 +199,17 @@ private boolean internalGetState(StateFlag flag, LocalPlayer player) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check group permissions
|
||||
if (groupPlayer != null && groupFlag != null) {
|
||||
RegionGroupFlag.RegionGroup group = region.getFlag(groupFlag);
|
||||
if (group == null) {
|
||||
group = groupFlag.getDefault();
|
||||
}
|
||||
if (!RegionGroupFlag.isMember(region, group, groupPlayer)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
State v = region.getFlag(flag);
|
||||
|
||||
// Allow DENY to override everything
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
import org.bukkit.entity.CreatureType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
@ -49,6 +47,8 @@ public final class DefaultFlag {
|
||||
public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false);
|
||||
public static final StateFlag SNOW_FALL = new StateFlag("snow-fall", true);
|
||||
public static final StateFlag LEAF_DECAY = new StateFlag("leaf-decay", true);
|
||||
public static final StateFlag ENTRY = new StateFlag("entry", true);
|
||||
public static final RegionGroupFlag ENTRY_PERM = new RegionGroupFlag("entry-group", RegionGroupFlag.RegionGroup.NON_MEMBERS);
|
||||
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting");
|
||||
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell");
|
||||
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter");
|
||||
@ -57,9 +57,9 @@ public final class DefaultFlag {
|
||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
|
||||
public static final VectorFlag TELE_LOC = new VectorFlag("teleport");
|
||||
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group");
|
||||
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group", RegionGroupFlag.RegionGroup.MEMBERS);
|
||||
public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn");
|
||||
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group");
|
||||
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group", RegionGroupFlag.RegionGroup.MEMBERS);
|
||||
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
|
||||
public static final DoubleFlag PRICE = new DoubleFlag("price");
|
||||
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", new CommandStringFlag(null));
|
||||
@ -71,9 +71,13 @@ public final class DefaultFlag {
|
||||
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER,
|
||||
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
|
||||
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY,
|
||||
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS
|
||||
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS, ENTRY, ENTRY_PERM
|
||||
};
|
||||
|
||||
static {
|
||||
ENTRY.setGroupFlag(ENTRY_PERM);
|
||||
}
|
||||
|
||||
private DefaultFlag() {
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
@ -29,15 +32,25 @@ public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
|
||||
|
||||
public static enum RegionGroup {
|
||||
MEMBERS,
|
||||
OWNERS
|
||||
OWNERS,
|
||||
NON_MEMBERS,
|
||||
NON_OWNERS
|
||||
}
|
||||
|
||||
public RegionGroupFlag(String name, char legacyCode) {
|
||||
private RegionGroup def;
|
||||
|
||||
public RegionGroupFlag(String name, char legacyCode, RegionGroup def) {
|
||||
super(name, legacyCode);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public RegionGroupFlag(String name) {
|
||||
public RegionGroupFlag(String name, RegionGroup def) {
|
||||
super(name);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public RegionGroup getDefault() {
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,6 +62,10 @@ public RegionGroup parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
return RegionGroup.MEMBERS;
|
||||
} else if (input.equalsIgnoreCase("owners") || input.equalsIgnoreCase("owner")) {
|
||||
return RegionGroup.OWNERS;
|
||||
} else if (input.equalsIgnoreCase("nonowners") || input.equalsIgnoreCase("nonowner")) {
|
||||
return RegionGroup.NON_OWNERS;
|
||||
} else if (input.equalsIgnoreCase("nonmembers") || input.equalsIgnoreCase("nonmember")) {
|
||||
return RegionGroup.NON_MEMBERS;
|
||||
} else if (input.equalsIgnoreCase("everyone") || input.equalsIgnoreCase("anyone")) {
|
||||
return null;
|
||||
} else {
|
||||
@ -63,6 +80,10 @@ public RegionGroup unmarshal(Object o) {
|
||||
return RegionGroup.MEMBERS;
|
||||
} else if (str.equalsIgnoreCase("owners")) {
|
||||
return RegionGroup.OWNERS;
|
||||
} else if (str.equalsIgnoreCase("nonmembers")) {
|
||||
return RegionGroup.NON_MEMBERS;
|
||||
} else if (str.equalsIgnoreCase("nonowners")) {
|
||||
return RegionGroup.NON_OWNERS;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -74,9 +95,58 @@ public Object marshal(RegionGroup o) {
|
||||
return "members";
|
||||
} else if (o == RegionGroup.OWNERS) {
|
||||
return "owners";
|
||||
} else if (o == RegionGroup.NON_MEMBERS) {
|
||||
return "nonmembers";
|
||||
} else if (o == RegionGroup.NON_OWNERS) {
|
||||
return "nonowners";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMember(ProtectedRegion region, RegionGroup group, LocalPlayer player) {
|
||||
if (group == RegionGroupFlag.RegionGroup.OWNERS) {
|
||||
if (region.isOwner(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.MEMBERS) {
|
||||
if (region.isMember(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.NON_OWNERS) {
|
||||
if (!region.isOwner(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.NON_MEMBERS) {
|
||||
if (!region.isMember(player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isMember(ApplicableRegionSet set,
|
||||
RegionGroup group, LocalPlayer player) {
|
||||
if (group == RegionGroupFlag.RegionGroup.OWNERS) {
|
||||
if (set.isOwnerOfAll(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.MEMBERS) {
|
||||
if (set.isMemberOfAll(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.NON_OWNERS) {
|
||||
if (!set.isOwnerOfAll(player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (group == RegionGroupFlag.RegionGroup.NON_MEMBERS) {
|
||||
if (!set.isMemberOfAll(player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public enum State {
|
||||
}
|
||||
|
||||
private boolean def;
|
||||
private RegionGroupFlag groupFlag;
|
||||
|
||||
public StateFlag(String name, char legacyCode, boolean def) {
|
||||
super(name, legacyCode);
|
||||
@ -48,6 +49,14 @@ public boolean getDefault() {
|
||||
return def;
|
||||
}
|
||||
|
||||
public RegionGroupFlag getGroupFlag() {
|
||||
return groupFlag;
|
||||
}
|
||||
|
||||
public void setGroupFlag(RegionGroupFlag groupFlag) {
|
||||
this.groupFlag = groupFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
|
Loading…
Reference in New Issue
Block a user