PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.7k stars 2.27k forks source link

I can't cancel the creation of the end portal #5547

Open Splitrox opened 3 years ago

Splitrox commented 3 years ago

Expected behavior

When canceling the PortalCreateEvent or EntityPortalCreateEvent he should block the portal from being created After canceling the spawn of a dragon from CreatureSpawnEvent, a bossbar should not appear since the dragon's spawn is canceled Note: Nether portal is cancelled, only the end portal is not.

Observed/Actual behavior

When canceling PortalCreateEvent or EntityPortalCreateEvent he is allowing the creation of portals but I believe the problem here is that the event is not being called so it is not canceled ... After canceling the spawn of the CreatureSpawnEvent dragon, a boss bar appears, and the event is canceled (the dragon is not born but regardless a boss bar appears)

http://prntscr.com/121u9mc http://prntscr.com/121uaap

Steps/models to reproduce

@EventHandler // Not running
protected void onEntityCreatePortal(PortalCreateEvent event) {
    if (event.getWorld().getEnvironment() == Environment.THE_END)
        event.setCancelled(true);
}

@EventHandler // Not running
protected void onDragonEggSpawn(DragonEggFormEvent event) {
    event.setCancelled(true);
}

    @EventHandler // Running but with bugs
protected void onDragonSpawn(CreatureSpawnEvent event) {
    if (event.getEntityType() == EntityType.ENDER_DRAGON && 
            event.getLocation().getWorld().getEnvironment() == Environment.THE_END) {
        EnderDragon dragon = ((EnderDragon) event.getEntity());

        dragon.getBossBar().removeAll();
        dragon.getDragonBattle().generateEndPortal(false);

        event.setCancelled(true);
    }
}

Plugin list

FastAsyncWorldEdit-Bukkit-1.16-655 HolographicDisplays Multiverse-Core-4.2.2 ProtocolLib

Paper version

This server is running Paper version git-Paper-629 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT) You are running the latest version Previous version: git-Paper-a98d389d1 (MC: 1.16.5)

Agreements

embeddedt commented 3 years ago

For the second part of your issue: as far as I know, in 1.9+, the presence of the boss bar is controlled by the world's fight manager, not the dragon entity itself. Have a look at [DragonBattle.getBossBar](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/boss/DragonBattle.html#getBossBar()).

You should be able to get a reference to the battle with world.getEnderDragonBattle() (going from memory so the name might be slightly different) and turn off the boss bar's visibility there.

Machine-Maker commented 3 years ago

The PortalCreateEvent doesn't seem to fire for the creation of the end portal. Unless you are talking about the generation of the obsidian platform when a players travels to the end dimension. You can see the list of reasons its fired in the PortalCreateEvent$CreateReason enum.

The point of ^ being that it's not expected behavior right now, for the event to be called. Doesn't mean it shouldn't be called.

Splitrox commented 3 years ago

@embeddedt I already tried to disable the boss bar in the CreatureSpawnEvent from the dragon(EnderDragon#getDragonBattle) and from the dragon world(World#getEnderDragonBattle), even with some delay (1-5 ticks after) and I still can't do it. @Machine-Maker I am not expecting to be able to cancel it from an event, but if there is a portal creation event, it may be possible to cancel it from that event, or not, what matters is that there is a way to cancel the creation and I am not seeing it be possible at the moment.

Machine-Maker commented 3 years ago

@Splitrox You need to say what specifically you are trying to cancel with PortalCreateEvent, there are only 3 reasons that event is fired (found here). Which of of those 3 things are you trying to cancel specifically? And if it is none of those, then specifically state what you are requesting a feature of.

Splitrox commented 3 years ago

@Machine-Maker I didn't literally say the reason but by the code you can understand that it is THE_END, but here the problem is that the only portal that is not to be canceled is the THE_END Just updated with that information

Splitrox commented 3 years ago

You actually have two portals that are created, the one in the middle that is opened when the dragon is killed and the one that allows you to take it to the place where you can get the elytra (it is a smaller one that has a purple light)

electronicboy commented 3 years ago

Cancelling portals in the end does not mean that you might catch ALL of the portal creations, judging from this, the event just quite simply isn't even handled for the end of a dragon battle

Phoenix616 commented 3 years ago

The places where such an event would need to be added is either EnderDragonBatle#generateExitPortal or WorldGenEndTrophy#generate. Of course this would need the whole block capture stuff and a new create reason as well as forwarding of the entity (the dragon I guess?).

Also a thing to note: The portal would be created without portal blocks first (on world generation or when a legacy dragon is found which wasn't slain and no portal in teh world), then "lit" when the dragon dies so the event would be called with two different "states" which, besides from the block list, can't be differentiated.

Machine-Maker commented 3 years ago

@Splitrox What do you mean by DragonEggFormEvent is "Not running"? The event does not fire when the ender dragon is killed and an egg is generated?

Splitrox commented 3 years ago

@Machine-Maker " The event does not fire when the ender dragon is killed and an egg is generated?" yes maybe I should have divided each problem into different issues but as it was all about the end I decided to put it all together

Machine-Maker commented 3 years ago

I can't replicate the part about the event not firing when the dragon is killed, it always seems to fire for me. It is fired in the cancelled state however, if the dragon has already been killed (unless paper is configured to always drop the dragon egg)

Splitrox commented 3 years ago

@Machine-Maker "unless paper is configured to always drop the dragon egg" oh alright, i can disable that so its not a problem But this is a problem: "After canceling the spawn of the CreatureSpawnEvent dragon, a boss bar appears, and the event is canceled (the dragon is not spawn but regardless a boss bar appears)"

Machine-Maker commented 3 years ago

Yeah, #5717 has a fix for that, and the other linked pr has more portal creation reasons

This issue is kinda two issues wrapped into one, perhaps you should open a second issue and split it up? Usually we like to keep one problem per issue, and these aren't really related

Splitrox commented 3 years ago

@Machine-Maker oh i didnt saw the message, yeah, i just opened an issue about it