Added exit flag to deny exiting a region.

This commit is contained in:
sk89q 2011-06-26 14:11:11 -07:00
parent 13840cf61b
commit 7fce4bf53e
3 changed files with 20 additions and 12 deletions

View File

@ -152,6 +152,7 @@ public static class PlayerFlagState {
public long lastHeal;
public String lastGreeting;
public String lastFarewell;
public boolean lastExitAllowed = true;
public Boolean notifiedForEnter = false;
public Boolean notifiedForLeave = false;
}

View File

@ -239,25 +239,28 @@ public void onPlayerMove(PlayerMoveEvent event) {
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
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)) {
if (!hasBypass && !entryAllowed) {
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;
}
boolean exitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
if (!hasBypass && exitAllowed && !state.lastExitAllowed) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to leave this area.");
Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5);
newLoc.setY(newLoc.getBlockY());
@ -310,6 +313,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
}
}
}

View File

@ -49,6 +49,8 @@ public final class DefaultFlag {
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 StateFlag EXIT = new StateFlag("exit", true);
public static final RegionGroupFlag EXIT_PERM = new RegionGroupFlag("exit-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");
@ -71,11 +73,12 @@ 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, ENTRY, ENTRY_PERM
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS, ENTRY, ENTRY_PERM, EXIT, EXIT_PERM
};
static {
ENTRY.setGroupFlag(ENTRY_PERM);
EXIT.setGroupFlag(EXIT_PERM);
}
private DefaultFlag() {