Add config option to use player teleports for move events.

Additionally removed code duplication in Vehicle listener.
This commit is contained in:
wizjany 2013-06-08 12:04:58 -04:00
parent 4718c5dab0
commit 736eecc13b
3 changed files with 10 additions and 86 deletions

View File

@ -99,6 +99,7 @@ public class ConfigurationManager {
public boolean activityHaltToggle = false; public boolean activityHaltToggle = false;
public boolean autoGodMode; public boolean autoGodMode;
public boolean usePlayerMove; public boolean usePlayerMove;
public boolean usePlayerTeleports;
public boolean deopOnJoin; public boolean deopOnJoin;
public boolean blockInGameOp; public boolean blockInGameOp;
public Map<String, String> hostKeys = new HashMap<String, String>(); public Map<String, String> hostKeys = new HashMap<String, String>();
@ -144,6 +145,7 @@ public void load() {
autoGodMode = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false)); autoGodMode = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
config.removeProperty("auto-invincible-permission"); config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean("use-player-move-event", true); usePlayerMove = config.getBoolean("use-player-move-event", true);
usePlayerTeleports = config.getBoolean("use-player-teleports", true);
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false); deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false); blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);

View File

@ -1376,11 +1376,13 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
ApplicableRegionSet setFrom = mgr.getApplicableRegions(ptFrom); ApplicableRegionSet setFrom = mgr.getApplicableRegions(ptFrom);
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer()); LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
if (cfg.usePlayerTeleports) {
boolean result = checkMove(plugin, event.getPlayer(), event.getPlayer().getWorld(), event.getFrom(), event.getTo()); boolean result = checkMove(plugin, event.getPlayer(), event.getPlayer().getWorld(), event.getFrom(), event.getTo());
if (result) { if (result) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
if (event.getCause() == TeleportCause.ENDER_PEARL) { if (event.getCause() == TeleportCause.ENDER_PEARL) {
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world) if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)

View File

@ -82,96 +82,16 @@ public void onVehicleMove(VehicleMoveEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager(); ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world); WorldConfiguration wcfg = cfg.get(world);
// unfortunate code duplication
if (wcfg.useRegions) { if (wcfg.useRegions) {
// Did we move a block? // Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX() if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
PlayerFlagState state = plugin.getFlagStateManager().getState(player); boolean result = WorldGuardPlayerListener.checkMove(plugin, player, world, event.getFrom(), event.getTo());
LocalPlayer localPlayer = plugin.wrapPlayer(player); if (result) {
boolean hasBypass = plugin.getGlobalRegionManager().hasBypass(player, world);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) {
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0)); vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
vehicle.teleport(event.getFrom()); vehicle.teleport(event.getFrom());
return; }
}
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = mgr.getApplicableRegions(toVector(event.getFrom()))
.allows(DefaultFlag.EXIT, localPlayer);
}
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.");
vehicle.setVelocity(new org.bukkit.util.Vector(0,0,0));
vehicle.teleport(event.getFrom());
return;
}
String greeting = set.getFlag(DefaultFlag.GREET_MESSAGE, localPlayer);
String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE, localPlayer);
Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER, localPlayer);
Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE, localPlayer);
if (state.lastFarewell != null && (farewell == null
|| !state.lastFarewell.equals(farewell))) {
String replacedFarewell = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(state.lastFarewell));
player.sendMessage(ChatColor.AQUA + " ** " + replacedFarewell);
}
if (greeting != null && (state.lastGreeting == null
|| !state.lastGreeting.equals(greeting))) {
String replacedGreeting = plugin.replaceMacros(
player, BukkitUtil.replaceColorMacros(greeting));
player.sendMessage(ChatColor.AQUA + " ** " + replacedGreeting);
}
if ((notifyLeave == null || !notifyLeave)
&& state.notifiedForLeave != null && state.notifiedForLeave) {
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " left NOTIFY region");
}
if (notifyEnter != null && notifyEnter && (state.notifiedForEnter == null
|| !state.notifiedForEnter)) {
StringBuilder regionList = new StringBuilder();
for (ProtectedRegion region : set) {
if (regionList.length() != 0) {
regionList.append(", ");
}
regionList.append(region.getId());
}
plugin.broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + player.getName()
+ ChatColor.GOLD + " entered NOTIFY region: "
+ ChatColor.WHITE
+ regionList);
}
state.lastGreeting = greeting;
state.lastFarewell = farewell;
state.notifiedForEnter = notifyEnter;
state.notifiedForLeave = notifyLeave;
state.lastExitAllowed = exitAllowed;
state.lastWorld = event.getTo().getWorld();
state.lastBlockX = event.getTo().getBlockX();
state.lastBlockY = event.getTo().getBlockY();
state.lastBlockZ = event.getTo().getBlockZ();
} }
} }
} }