WorldGuard

WorldGuard

8M Downloads

When non-player entities create new nether portals, an error occurs

bergerkiller opened this issue ยท 11 comments

commented

WorldEdit Version

7.2.15-SNAPSHOT

WorldGuard Version

7.1.0-SNAPSHOT

Platform Version

git-Paper-478 (MC: 1.19.4)

Confirmations

  • I am using the most recent Minecraft release.
  • I am using a version of WorldEdit compatible with my Minecraft version.
  • I am using a version of WorldGuard compatible with my Minecraft version.
  • I am using the latest or recommended version of my platform software.
  • I am NOT using a hybrid server, e.g. a server that combines Bukkit and Forge. Examples include Arclight, Mohist, and Cardboard.
  • I am NOT using a fork of WorldEdit, such as FastAsyncWorldEdit (FAWE) or AsyncWorldEdit (AWE)

Bug Description

When a non-player entity, like a Pig, initiates nether portal creation WorldGuard has an internal error:

[18:13:31 ERROR]: Could not pass event PortalCreateEvent to WorldGuard v7.1.0-SNAPSHOT+2232-b67fd01
java.lang.NullPointerException: The build flag is handled in a special fashion and requires a non-null subject parameter
        at com.sk89q.worldguard.protection.FlagValueCalculator.queryAllValues(FlagValueCalculator.java:392) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.sk89q.worldguard.protection.FlagValueCalculator.queryValue(FlagValueCalculator.java:227) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.sk89q.worldguard.protection.FlagValueCalculator.queryState(FlagValueCalculator.java:174) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.sk89q.worldguard.protection.RegionResultSet.queryState(RegionResultSet.java:103) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.sk89q.worldguard.protection.AbstractRegionSet.testState(AbstractRegionSet.java:34) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.sk89q.worldguard.bukkit.listener.WorldGuardEntityListener.onCreatePortal(WorldGuardEntityListener.java:679) ~[worldguard-bukkit-7.1.0-SNAPSHOT-dist.jar:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor137.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[purpur-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:77) ~[purpur-api-1.19.4-R0.1-SNAPSHOT.jar:git-Purpur-1952]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[purpur-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:126) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:617) ~[purpur-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at net.minecraft.world.level.portal.PortalForcer.createPortal(PortalForcer.java:224) ~[?:?]
        at com.bergerkiller.mountiplex.reflection.util.fast.GeneratedCodeInvoker$mpldefgen377ba225.createNetherPortal(Unknown Source) ~[?:?]
        at com.bergerkiller.mountiplex.reflection.util.fast.GeneratedCodeInvoker$mpldefgen377ba225.invoke(Unknown Source) ~[?:?]
        at com.bergerkiller.bukkit.common.internal.logic.PortalHandler_1_14_1$PortalTravelAgentHandle$impl.createNetherPortal(Unknown Source) ~[?:?]
        at com.bergerkiller.bukkit.common.internal.logic.PortalHandler_1_14_1.createNetherPortal(PortalHandler_1_14_1.java:87) ~[BKCommonLib-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at com.bergerkiller.bukkit.common.utils.WorldUtil.createNetherPortal(WorldUtil.java:559) ~[BKCommonLib-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at com.bergerkiller.bukkit.mw.portal.NetherPortalSearcher$SearchResult.whenLoaded(NetherPortalSearcher.java:311) ~[MyWorlds-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at com.bergerkiller.bukkit.mw.portal.NetherPortalSearcher$SearchResult.lambda$verify$2(NetherPortalSearcher.java:289) ~[MyWorlds-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[?:?]
        at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[?:?]
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[?:?]
        at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147) ~[?:?]
        at com.bergerkiller.bukkit.common.internal.CommonForcedChunkManager$Entry.lambda$accept$0(CommonForcedChunkManager.java:365) ~[BKCommonLib-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at com.bergerkiller.bukkit.common.internal.CommonNextTickExecutor$ExecutorTask.run(CommonNextTickExecutor.java:161) ~[BKCommonLib-1.19.4-v1-SNAPSHOT-NO-CI.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1510) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:487) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1424) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1195) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:325) ~[purpur-1.19.4.jar:git-Purpur-1952]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

This is because the Entity initiating it isnt a player, so the associable here is null:
https://github.com/EngineHub/WorldGuard/blob/master/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java#L679

The methods claim they support a nullable associable, but I guess its querying a flag that requires one. It probably need a null check at that location. Besides printing that error, there appears to not be any other problem.

Expected Behavior

No error

Reproduction Steps

  1. Install worldedit and worldguard
  2. Add MyWorlds and BKCommonLib (unsure if this is critical, but its myworlds thats firing a portal create event through NMS code with the pig or other non-player entity as initiator)
  3. Create a new nether portal on one world
  4. Spawn a pig and make it enter it, so it creates a fresh portal on the other end

Optional WorldGuard-Report

No response

Anything Else?

No response

commented

Add MyWorlds and BKCommonLib (unsure if this is critical, but its myworlds thats firing a portal create event through NMS code with the pig or other non-player entity as initiator)

smh my head. this is indeed a critical step as vanilla code doesn't fire nether pairing like this. we can technically work around this i guess though, associables can be nonplayers we just didn't bother in that particular method because vanilla doesn't allow for it, but ig the bukkit api does (even though manually constructed events aren't meant to be api).

commented

that's possible. i only looked at vanilla code when i wrote this [edit: i.e. the original code, not this comment], not mojira :^)

commented

because vanilla doesn't allow for it

That was my first thought too after looking at the event. However, a quick search on google showed that this is apparently a bug. Also according to the comments this isn't the case in newer versions anymore, I'll test this. Edit: Actually, according to the mojira comments, entities still can't travel through non-linked portals, but due to another issue.

commented

Add MyWorlds and BKCommonLib (unsure if this is critical, but its myworlds thats firing a portal create event through NMS code with the pig or other non-player entity as initiator)

smh my head. this is indeed a critical step as vanilla code doesn't fire nether pairing like this. we can technically work around this i guess though, associables can be nonplayers we just didn't bother in that particular method because vanilla doesn't allow for it, but ig the bukkit api does (even though manually constructed events aren't meant to be api).

That explains that, then, yeah. Mojangs own code supports non-player entities doing this all the way. I wasnt aware that bukkit disallowed nonplayers from doing so. I still view this as a bug as seemingly other parts of the code do check for a null associable, so apparently this should just work.

I can obviously just exempt nonplayers from creating portals, but it feels silly when both bukkit api and mojangs own portal creation code don't have any such restrictions

commented

it's not a null associable, the entity passed to the portalcreateevent would be responsible. that part of the code (build flag) very specifically (if you read the error message) requires a non-null associable.
so it's not about supporting null associables, it's about using the method to convert the root entity into an associable rather than assuming it must be a player (an assumption which is/was sound in vanilla code).

commented

it's not a null associable, the entity passed to the portalcreateevent would be responsible. that part of the code (build flag) very specifically (if you read the error message) requires a non-null associable. so it's not about supporting null associables, it's about using the method to convert the root entity into an associable rather than assuming it must be a player (an assumption which is/was sound in vanilla code).

I was talking about the if (associable != null) { part of worldguards code. This is dead code by your logic and the if should just be omitted, and it should be allowed to fail right away

commented

no that part was fine (it will be changed to checking if the associable is a player instead) as we don't care to send deny-messages to pigs. it's the player check 15 lines up that needs to change.

commented

no that part was fine (it will be changed to checking if the associable is a player instead) as we don't care to send deny-messages to pigs. it's the player check 15 lines up that needs to change.

yeah I can agree with that

commented

Kind of ironic that I made all of this work never realizing Mojang botched it so non-player entities cant create nether portals. Im confused thats not possible because Ive seen item dropper obsidian farms being made by people.

I swear Ive seen people use items as I was asked about it on my discord way back. Maybe it only worked in like, 1.12 or 1.8 or something.

commented

Just to clarify, current Vanilla and Paper behavior is that non-players can't trigger portal generation.

commented

If the decision is to not fix this (and effectively mandate that the portal create event initiator argument shouldve just been a Player), let me know. I guess I can hack in something so it doesnt fire that event at all for non-player entities with a little bit of effort.