Fix NPE when non-player entities create new nether portals (#1995)
* Fix NPE when non-player entities create new nether portals * Fix flag checking for portal create event * Use failed load region set * Clean up
This commit is contained in:
parent
bddfbdd353
commit
ca636d20af
|
@ -25,13 +25,17 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
|
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.bukkit.cause.Cause;
|
||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
|
import com.sk89q.worldguard.bukkit.util.InteropUtils;
|
||||||
import com.sk89q.worldguard.config.ConfigurationManager;
|
import com.sk89q.worldguard.config.ConfigurationManager;
|
||||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.FailedLoadRegionSet;
|
||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
|
@ -653,35 +657,46 @@ public class WorldGuardEntityListener extends AbstractListener {
|
||||||
public void onCreatePortal(PortalCreateEvent event) {
|
public void onCreatePortal(PortalCreateEvent event) {
|
||||||
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
|
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
|
||||||
|
|
||||||
if (wcfg.regionNetherPortalProtection
|
if (wcfg.useRegions && wcfg.regionNetherPortalProtection
|
||||||
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
|
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
|
||||||
&& !event.getBlocks().isEmpty()) {
|
&& !event.getBlocks().isEmpty()) {
|
||||||
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
|
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
|
||||||
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
final Cause cause = Cause.create(event.getEntity());
|
||||||
.get(world);
|
LocalPlayer localPlayer = null;
|
||||||
if (regionManager == null) return;
|
if (cause.getRootCause() instanceof Player player) {
|
||||||
LocalPlayer associable = null;
|
if (wcfg.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
|
||||||
if (event.getEntity() instanceof Player player) {
|
return;
|
||||||
associable = getPlugin().wrapPlayer(player);
|
}
|
||||||
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
|
localPlayer = getPlugin().wrapPlayer(player);
|
||||||
|
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BlockVector3 min = null;
|
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
||||||
BlockVector3 max = null;
|
.get(world);
|
||||||
for (BlockState block : event.getBlocks()) {
|
ApplicableRegionSet regions;
|
||||||
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
if (regionManager == null) {
|
||||||
min = min == null ? loc : loc.getMinimum(min);
|
regions = FailedLoadRegionSet.getInstance();
|
||||||
max = max == null ? loc : loc.getMaximum(max);
|
} else {
|
||||||
|
BlockVector3 min = null;
|
||||||
|
BlockVector3 max = null;
|
||||||
|
for (BlockState block : event.getBlocks()) {
|
||||||
|
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||||
|
min = min == null ? loc : loc.getMinimum(min);
|
||||||
|
max = max == null ? loc : loc.getMaximum(max);
|
||||||
|
}
|
||||||
|
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
|
||||||
|
regions = regionManager.getApplicableRegions(target);
|
||||||
}
|
}
|
||||||
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
|
final RegionAssociable associable = createRegionAssociable(cause);
|
||||||
final ApplicableRegionSet regions = regionManager.getApplicableRegions(target);
|
final State buildState = StateFlag.denyToNone(regions.queryState(associable, Flags.BUILD));
|
||||||
if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) {
|
if (!StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_BREAK))
|
||||||
if (associable != null) {
|
|| !StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_PLACE))) {
|
||||||
|
if (localPlayer != null && !cause.isIndirect()) {
|
||||||
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
|
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
|
||||||
// removing PTA was a mistake
|
// removing PTA was a mistake
|
||||||
String message = regions.queryValue(associable, Flags.DENY_MESSAGE);
|
String message = regions.queryValue(localPlayer, Flags.DENY_MESSAGE);
|
||||||
RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message);
|
RegionProtectionListener.formatAndSendDenyMessage("create portals", localPlayer, message);
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue