[Unimplemented, Partially Resolved] Player Crouch Event

Hi, I love sponge but could not find an event for when a player crouches in the java-docs or on google.

Does anyone know how I would run code when someone crouches?

I believe that you should be able to listen to the player move event and check if the player is sneaking or not using the IS_SNEAKING key.

Okay, thank you for the quick reply and help. I will try reading the event data on player move.

Is the player move event DisplaceEntityEvent.Move.TargetPlayer?

Yes, I linked it in my previous post.

Ah, sorry, i skimmed through your post too quick. Thanks.

1 Like

Hmm, DisplaceEntityEvent gets DisplaceEntityEvent cannot be resolved to a type in eclipse. I can try importing it manually.

Edit 1: I can’t seem to find that code in the version of Sponge i am using.

If you are using Sponge API 5, the event got renamed to MoveEntityEvent.

Okay, thanks, I’ll try to get this working. The only thing I am unsure of is how i can see if the player was crouching on the last move event so i know that they just started crouching.

There is the ChangeDataHolderEvent (It fires when data changes, so you could listen to it to find out if the sneaking data changed), but I am unsure if that is implemented or not.

Hmm, okay, thanks.

Do you know how I would see what keys are down on the player, etc… The only thing i found was ply.getKeys();

Edit: I realized that I think it won’t detect the crouch unless they move while crouched regardless, so IDK what i can do.

Moving the cursor calls the event, so I would assume crouching would. Test if it will with some debug messages.

I made it send the player a message when the event is run and it does not run on crouch.

Ah, that’s a shame. Have you tested if the ChangeDataHolderEvent fires?

It doesn’t seem to, I tried this with both events and it only called at all with the first one it seems.

Edit 1: And it did not run on crouch for either of them.

In that case, it appears that you will have to wait for the event to be implemented.

Okay, thanks for the help.