mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-30 07:37:31 +02:00
Overprotective nether portal protection.
Blocks any portal travel that might lead to portal creation in a protected area. Fixes WORLDGUARD-3479.
This commit is contained in:
parent
21d13cc72c
commit
463a356020
@ -29,6 +29,7 @@
|
||||
import com.sk89q.worldguard.bukkit.util.Events;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
@ -368,6 +369,33 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
// hackily estimate the area that could be effected by this event, since the server refuses to tell us
|
||||
int radius;
|
||||
if (event.getPortalTravelAgent() != null) {
|
||||
radius = event.getPortalTravelAgent().getCreationRadius();
|
||||
} else {
|
||||
radius = 16; // from CraftTravelAgent
|
||||
}
|
||||
Location min = event.getTo().clone().subtract(radius, radius, radius);
|
||||
Location max = event.getTo().clone().add(radius, radius, radius);
|
||||
World world = event.getTo().getWorld();
|
||||
|
||||
ProtectedRegion check = new ProtectedCuboidRegion("__portalcheck__", BukkitUtil.toVector(min.getBlock()), BukkitUtil.toVector(max.getBlock()));
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(event.getPlayer(), world)) {
|
||||
ApplicableRegionSet set = plugin.getRegionContainer().get(event.getTo().getWorld()).getApplicableRegions(check);
|
||||
if (!set.testState(plugin.wrapPlayer(event.getPlayer()), DefaultFlag.BUILD)) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Destination is in a protected area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
Loading…
Reference in New Issue
Block a user