OnPlayerSleepEvent

A new update is now available, introducing seasons and more!
Latest hotfix: 0.8.0.1 (2024-12-20)
  • Sure, that could be added with the upcoming hotfix :) However, we have been thinking about adding a more generic event like PlayerChangeStateEvent instead - it would be called every time the player changes his state, e.g. sitting on a chair, lying in a bed, playing a piano etc. So this old code:

    Java
    @EventMethod
    public void onPlayerSleep(PlayerSleepEvent evt){
    Player player = evt.getPlayer();
    //Player is sleeping
    if(evt.isSleeping()) System.out.println("Player " + player.getName() + " is now sleeping");
    //Player is no longer sleeping
    else System.out.println("Player " + player.getName() + " is no longer sleeping...");
    }


    Would look like this in the new API:

    Java
    @EventMethod
    public void onPlayerChangeState(PlayerChangeStateEvent evt){
    Player player = evt.getPlayer();
    //If new state is "sleeping", player went to bed
    if(evt.getNewState() == Player.State.Sleeping) System.out.println("Player " + player.getName() + " is now sleeping");
    //If old state was sleeping, player is now definitely no longer sleeping
    //(otherwise there wouldn't have been a state change)
    else if(evt.getOldState() == Player.State.Sleeping) System.out.println("Player " + player.getName() + " is no longer sleeping...");
    }


    The new event requires a bit more code, but in return, it provides access to other state changes as well (e.g. sitting on a chair, swimming, climbing ladders etc). Do you think that would work in your case?

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!