How to register and listen for Key change events?

Now that the new ChangeDataHolderEvent et al. is implemented, how do we use it? I couldn’t find any examples or preexisting plugins.

For example, I want to stop players’ food level from changing. Here is a code example:

@Listener
public void onPostInit(GamePostInitializationEvent event)
{
    Keys.FOOD_LEVEL.registerEvent(Player.class, e -> System.out.println("a"));
    //just printing a line for testing purposes
}

However, it doesn’t seem to actually work. Do I need a listener somewhere?

ChangeDataHolderEvent is only partially implemented right now. It doesn’t yet work for Keys.FOOD_LEVEL. The keys that it works for currently are:

  • Keys.REMAINING_AIR
  • Keys.DISPLAY_NAME
  • Keys.CUSTOM_NAME_VISIBLE
  • Keys.IS_SNEAKING
  • Keys.IS_SPRINTING
  • Keys.INVISIBLE
  • Keys.GLOWING
  • Keys.HAS_GRAVITY
  • Keys.IS_SILENT