DragonTravel icon indicating copy to clipboard operation
DragonTravel copied to clipboard

Fix: Player got falling damage when dismount

Open mhtvsSFrpHdE opened this issue 5 years ago • 6 comments

close #53

This time I use async method to do this:
first I set player invulnerable to true, this can avoid damage for the player.
then use async method to set invulnerable to false after 3 second,
this should enough for him to fall.

A event listener solution certainly better than "invulnerable hack",
but that have too much job to do.

For me, I feel not good when your magic without comment everywhere.
The thing is, when you try to do same things but use method different than "Bukkit new developer tutorial & guide", as your personal style...
or even just use some API, I, or the after contributors, are not here to DECOMPILE your code.

If now I want to implement the "on demand event listen" solution instead of "invulnerable hack",
I need to know where to put my "traveling player array".
So I start read code from main method and one line after another,
to figure out where are you placing similar things.
In this process, I don't want to care about how exactly the code to implement human design.
Just like any "HelloWorld" program that doesn't need to care about how the graphic card and HDMI protocol or anything else to work.
So I need the "green things"(comment) says "Oh here I do some stuff because I want to...", "The process to dismount player: one two three four five", "I put these variable here because..."
By read the green things I can fast a lot to know if a new things join in, where to put it,
or if I want to edit something, where to find.

OK yet, I know how bad is "tell the open source author you should do things like this". Just my two cents about somebody is can't even understand what happened in "onLoad" method.
Sometimes, for better OTHER human readable, I even NOT to simplify

if (player.isInvulnerable() == false)

to

if (!player.isInvulnerable())

mhtvsSFrpHdE avatar Oct 03 '19 12:10 mhtvsSFrpHdE

The close #53 is masked because now it is not a universal way.
I need to copy & paste it to every code section that dismount player.

To make it callable, like "safeDismount(Player player)" or something
I still need a deep understand about how this project is designed.

mhtvsSFrpHdE avatar Oct 03 '19 12:10 mhtvsSFrpHdE

Some other bug that:
A player may be able to use this patch to get permanent invulnerable status.

It's very rare to happen this but sometimes the async cancel method may not trigger.

  • Server crashed.
  • Server stopped.
  • Server restarted.

mhtvsSFrpHdE avatar Oct 03 '19 13:10 mhtvsSFrpHdE

The code is simple to follow

Totollie avatar Oct 03 '19 18:10 Totollie

  • If you search for stuff dealing with dismounts, take a look at the parts of the code dealing with mounts/dismounts wich clearly is for

    • mounts: https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/DragonManager.java#L91
    • dismounts:
      • general dismount (only called when properly dismounting): https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/DragonManager.java#L45
      • removing riders and dragons (called from method dismount and from other methods, e.g. when player is kicked): https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/DragonManager.java#L195
        • In case of PlayerKick/PlayerQuit/... https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/listeners/PlayerListener.java#L46 https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/listeners/PlayerListener.java#L63
  • Players already are invulnerable while travelling to avoid damage when passing through blocks (e.g. in case the dragon's route is through a high mountain). We would just need to extend this for the few seconds after the dismount. There already is a list of riders (and their dragons) as one of the very central parts of the plugin (DragonManager.ridersDragons). https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/DragonManager.java#L35 To achieve this invulnerability, we have an event listener for the EntityDamageEvent and if the entity is a player and this player is a rider, we cancel the event: https://github.com/Phiwa/DragonTravel/blob/958264782a41880453e2be887919cfa2d57c7a15/src/main/java/eu/phiwa/dragontravel/core/listeners/EntityListener.java#L43

  • I just tried to adjust the existing code to solve our problem, but the problem is that we cannot move the code which removes the player from the hashmap until after the dismount (in an async delayed task) since this blocks the removal of the dragon entity and therefore corrupts the dismount process.

To be honest, I do not like to create another list with players because this increases the risk of "forgetting" something when mounting/dismounting/..., but if it is implemented in the right place, it could be done and I'd be okay with it. You just need to make sure that it does not lead to problems. Adding the player to the list should be done in the mount method and the removing in the async task scheduled in removeRiderAndDragon, I guess. You could pobably use the existing EntityDamageEvent listener.

Phiwa avatar Oct 03 '19 19:10 Phiwa

So we now don't use setInvulnerable instead, we use event cancel to avoid permanent invulnerable.
This is really simple I just need to add a background task at the remove player from list method,
let him be removed later for few seconds instead of immediately.

I later do the coding.

mhtvsSFrpHdE avatar Oct 09 '19 13:10 mhtvsSFrpHdE

But as I said, this won't work out that easily...

  • You cannot simply use the existing list
  • Creating another list doesn't seem like a nice option either

Phiwa avatar Oct 10 '19 17:10 Phiwa