aromaa / WorldGuardExtraFlags

Extension for the WorldGuard plugin.
https://www.spigotmc.org/resources/worldguard-extra-flags.4823
MIT License
90 stars 71 forks source link

Multiverse-Inventories incorrectly saving effects given by give-effects flag #103

Closed Nevrai closed 4 years ago

Nevrai commented 4 years ago

When a regular player goes through a portal and teleports to another world from the hub, they don’t lose the status effect given by the give-effects flag. Instead, it counts down from 15 seconds.

However, when I, an OP and player with all permissions, go through a portal from the hub, I do lose the effect. I want players to lose the effect when going through the portal in the hub.

After some testing, I found that this is caused by the plugin Multiverse-Inventories. I have its bypass permission, whilst regular players don’t. When a regular player goes through the portal to a different world, they have a different inventory, health, XP, gamemode, and more; everything is separate. Status effects are also separate, so if the player has a status effect and go through a portal, they no longer have it, but if they travel back to the world they were in, they have it again. However, for some reason, they still have status effects given by WGEF’s give-effects flag, which doesn’t make much sense. If they get the permission to bypass Multiverse-Inventories so that everything is shared between worlds, they then lose the status effect given by give-effects when switching worlds. It seems a bit backwards to me.

Versions

aromaa commented 4 years ago

When testing this happens when you enter to region with give-effects flag from another world.

What actually happens is that WorldGuard listens on event (PlayerTeleportEvent) that is fired before the one Multiverse-Inventories is listening to (PlayerChangedWorldEvent). Which means that WorldGuard gives my plugin indication that the player has moved to new region and updates their potion effects.

Because Multiverse-Inventories is listening on PlayerChangedWorldEvent it thinks the just added potion effect was from the previous world and saves it to previous world and removes it from the players current effects. WGEF automatically gives you new potion effect every second so you don't notice this.

So now that the potion is saved incorrectly to the previous world it means that when you go back to there you have the 15s potion effect because you entered to a region which had the flag, not because you left area which had it!

I don't think I'm gonna do anything about this on my side. People has always requested for me to make the timer infinite instead of 15s but the main reason I have kept it like that is because these issues exists and for having the potion effect for 15s is not as damaging as having never ending effects.

aromaa commented 4 years ago

To add, this isn't simple case to fix. Flipping the order of which the events happen is obviously not a fix. The issue just flips around, instead of saving the effects of region you are entering to the previous world you are saving the effects of the one you are exiting.

To have this properly fixed Multiverse-Inventories would need to know which potion effect it should ignore. How could this be achieved? Dunno? Theres no simple solution when you need to work with the mess that the Bukkit API is.

Nevrai commented 4 years ago

Perhaps you could add a flag that clears all the status effects of a player once they leave the region? E.g., clear-effects-on-leave? It wouldn’t be a solution, but it would be a workaround that’d work in most situations.

aromaa commented 4 years ago

Did you read what I wrote?

Nevrai commented 4 years ago

I did.

Nevrai commented 4 years ago

To be frank, I don’t quite understand it.

So, WGEF gives Player the status effect “Effect.” If Player leaves the region, Effect disappears immediately. If they instead are in the region while teleporting out of it such as by going through a portal, WGEF is supposed to still remove the effect, but if Multiverse-Inventories is installed and Player does not have bypass permissions, Multiverse-Inventories changes the inventory, status effects, etc., of the player on world change.

However, from here, I don’t follow. You’re saying that the status effect is saved to the previous world and that the player regains that effect when returning to the world, but what does that have to do with the effect from the previous world not being cleared when moving to the new world?

My apologies for my confusion, but I just don’t really understand.

aromaa commented 4 years ago

As I explained, the problem is when you enter to a region. You understood the problem was when you leave a region.

You can easily reproduce this by first creating a region on overworld with give-effects flag. Then make a nether portal inside that region. Now enter to the nether and make sure you do not have any effects on you. Enter the portal again, which should send you inside a region that has the give-effects flag. Go outside the region and make sure you have no effects. Teleport to nether without entering the previous region. Now you should notice you have the 15s effect.

Nevrai commented 4 years ago

Oh, I see. I understand it now—at least I think I do.

Is there a way around this? Perhaps I could find a way to clear the effects of the player after teleporting through a portal?

aromaa commented 4 years ago

Like I mentioned, there is no easy way to get around this. I can't inform Multiverse-Inventories that those effects are "fake". Even that is not enough as my plugin holds storage for the effects that it removed in order to restore them after leaving a region.

It would require to have direct access to the underlying storage I'm holding in order to not preserve those "fake" effects and restore the potion effects correctly.

aromaa commented 4 years ago

I could hack around Multiverse-Inventories to make it aware of my plugins internal state but thats just unnecessary complexity for my plugin and there are a ton of other similar plugins which would have exactly the same issue. Its not worth the mess.