|
25 | 25 | import com.sk89q.worldguard.WorldGuard; |
26 | 26 | import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration; |
27 | 27 | import com.sk89q.worldguard.bukkit.WorldGuardPlugin; |
| 28 | +import com.sk89q.worldguard.bukkit.cause.Cause; |
28 | 29 | import com.sk89q.worldguard.bukkit.util.Entities; |
| 30 | +import com.sk89q.worldguard.bukkit.util.InteropUtils; |
29 | 31 | import com.sk89q.worldguard.config.ConfigurationManager; |
30 | 32 | import com.sk89q.worldguard.config.WorldConfiguration; |
31 | 33 | import com.sk89q.worldguard.protection.ApplicableRegionSet; |
| 34 | +import com.sk89q.worldguard.protection.FailedLoadRegionSet; |
32 | 35 | import com.sk89q.worldguard.protection.association.RegionAssociable; |
33 | 36 | import com.sk89q.worldguard.protection.flags.Flags; |
34 | 37 | import com.sk89q.worldguard.protection.flags.StateFlag; |
| 38 | +import com.sk89q.worldguard.protection.flags.StateFlag.State; |
35 | 39 | import com.sk89q.worldguard.protection.managers.RegionManager; |
36 | 40 | import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; |
37 | 41 | import com.sk89q.worldguard.protection.regions.RegionQuery; |
@@ -653,35 +657,46 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { |
653 | 657 | public void onCreatePortal(PortalCreateEvent event) { |
654 | 658 | WorldConfiguration wcfg = getWorldConfig(event.getWorld()); |
655 | 659 |
|
656 | | - if (wcfg.regionNetherPortalProtection |
| 660 | + if (wcfg.useRegions && wcfg.regionNetherPortalProtection |
657 | 661 | && event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR |
658 | 662 | && !event.getBlocks().isEmpty()) { |
659 | 663 | final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld()); |
660 | | - final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer() |
661 | | - .get(world); |
662 | | - if (regionManager == null) return; |
663 | | - LocalPlayer associable = null; |
664 | | - if (event.getEntity() instanceof Player player) { |
665 | | - associable = getPlugin().wrapPlayer(player); |
666 | | - if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) { |
| 664 | + final Cause cause = Cause.create(event.getEntity()); |
| 665 | + LocalPlayer localPlayer = null; |
| 666 | + if (cause.getRootCause() instanceof Player player) { |
| 667 | + if (wcfg.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) { |
| 668 | + return; |
| 669 | + } |
| 670 | + localPlayer = getPlugin().wrapPlayer(player); |
| 671 | + if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) { |
667 | 672 | return; |
668 | 673 | } |
669 | 674 | } |
670 | | - BlockVector3 min = null; |
671 | | - BlockVector3 max = null; |
672 | | - for (BlockState block : event.getBlocks()) { |
673 | | - BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ()); |
674 | | - min = min == null ? loc : loc.getMinimum(min); |
675 | | - max = max == null ? loc : loc.getMaximum(max); |
676 | | - } |
677 | | - ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max); |
678 | | - final ApplicableRegionSet regions = regionManager.getApplicableRegions(target); |
679 | | - if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) { |
680 | | - if (associable != null) { |
| 675 | + final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer() |
| 676 | + .get(world); |
| 677 | + ApplicableRegionSet regions; |
| 678 | + if (regionManager == null) { |
| 679 | + regions = FailedLoadRegionSet.getInstance(); |
| 680 | + } else { |
| 681 | + BlockVector3 min = null; |
| 682 | + BlockVector3 max = null; |
| 683 | + for (BlockState block : event.getBlocks()) { |
| 684 | + BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ()); |
| 685 | + min = min == null ? loc : loc.getMinimum(min); |
| 686 | + max = max == null ? loc : loc.getMaximum(max); |
| 687 | + } |
| 688 | + ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max); |
| 689 | + regions = regionManager.getApplicableRegions(target); |
| 690 | + } |
| 691 | + final RegionAssociable associable = createRegionAssociable(cause); |
| 692 | + final State buildState = StateFlag.denyToNone(regions.queryState(associable, Flags.BUILD)); |
| 693 | + if (!StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_BREAK)) |
| 694 | + || !StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_PLACE))) { |
| 695 | + if (localPlayer != null && !cause.isIndirect()) { |
681 | 696 | // NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info) |
682 | 697 | // removing PTA was a mistake |
683 | | - String message = regions.queryValue(associable, Flags.DENY_MESSAGE); |
684 | | - RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message); |
| 698 | + String message = regions.queryValue(localPlayer, Flags.DENY_MESSAGE); |
| 699 | + RegionProtectionListener.formatAndSendDenyMessage("create portals", localPlayer, message); |
685 | 700 | } |
686 | 701 | event.setCancelled(true); |
687 | 702 | } |
|
0 commit comments