Class CanPlayerSleepEvent


public class CanPlayerSleepEvent extends PlayerEvent
Called from ServerPlayer.startSleepInBed(BlockPos) when a player attempts to sleep.

This event receives the result of vanilla checking if the sleep attempt is valid, and permits overriding it.

This event is only fired on the logical server.

  • Field Details

    • pos

      private final net.minecraft.core.BlockPos pos
    • state

      private final net.minecraft.world.level.block.state.BlockState state
    • vanillaProblem

      @Nullable private final @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem vanillaProblem
    • problem

      @Nullable private @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem problem
  • Constructor Details

    • CanPlayerSleepEvent

      public CanPlayerSleepEvent(net.minecraft.server.level.ServerPlayer player, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem problem)
  • Method Details

    • getEntity

      public net.minecraft.server.level.ServerPlayer getEntity()
      Overrides:
      getEntity in class PlayerEvent
    • getLevel

      public net.minecraft.world.level.Level getLevel()
    • getPos

      public net.minecraft.core.BlockPos getPos()
    • getState

      public net.minecraft.world.level.block.state.BlockState getState()
    • getProblem

      @Nullable public @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem getProblem()
      Returns the current sleeping problem.
      Returns:
      the current sleeping problem
    • setProblem

      public void setProblem(@Nullable @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem problem)
      Sets a new sleeping problem. If the new problem is null, the player is allowed to sleep here.
    • getVanillaProblem

      @Nullable public @Nullable net.minecraft.world.entity.player.Player.BedSleepingProblem getVanillaProblem()
      Returns the default sleeping problem based on the vanilla checks.
      See Also:
      • to identify the cause of a problem.