Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4666

Force sleep not working during daytime

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • CraftBukkit version git-Spigot-3cb9dcb-8b1588e
    • Yes

      I just come to find out that the force player to sleep method does not seem to be doing its job.
      https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/HumanEntity.html#sleep-org.bukkit.Location-boolean-

      According to the docs, it should be able to force the player to sleep if conditions are not met.
      " The game may also enforce other requirements such as proximity to bed, monsters, and dimension type if force is not set. " and "force - whether to try and sleep at the location even if not normally possible"

      Here is the code I tested

      @EventHandler
      public void enterBedTest(PlayerInteractEvent e) {
      	if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
      
      		e.setCancelled(true);
      		Bukkit.broadcastMessage("Clicked block: " + e.getClickedBlock().getType() + " Player: " + e.getPlayer().getName());
      
      		if (e.getPlayer().sleep(e.getClickedBlock().getLocation(), true))
      			e.getPlayer().sendMessage("SLEEPY TIME");
      		else
      			e.getPlayer().sendMessage("NO SLEEPY TIME");
      	}
      }
      

      This code was just used for testing. I added the cancel to prevent the "You can only sleep at night message" If I remove the event cancel, I get the same outcome.

      If it is night time, the player will sleep and get the message "SLEEPY TIME"
      When it is daytime, the player is not forced to sleep and they get the message "NO SLEEPY TIME"

      I included a short little video so you can see this in action (this video is taking forever to publish)
      https://youtu.be/sIQyC_jv-U8

            Unassigned Unassigned
            ShaneBee Shane Bee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: