From e9430596234612642bd49123a51afc3b25d34817 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 2 Jan 2019 14:37:43 +1100 Subject: [PATCH] SPIGOT-4560: Add HumanEntity.sleep and related APIs By: md_5 --- .../java/org/bukkit/entity/HumanEntity.java | 55 +++++++++++++++++++ .../main/java/org/bukkit/entity/Player.java | 24 -------- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/entity/HumanEntity.java b/paper-api/src/main/java/org/bukkit/entity/HumanEntity.java index 71e52b486d..8fc5c83cf3 100644 --- a/paper-api/src/main/java/org/bukkit/entity/HumanEntity.java +++ b/paper-api/src/main/java/org/bukkit/entity/HumanEntity.java @@ -221,6 +221,61 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder */ public int getSleepTicks(); + /** + * Gets the Location where the player will spawn at their bed, null if + * they have not slept in one or their current bed spawn is invalid. + * + * @return Bed Spawn Location if bed exists, otherwise null. + */ + public Location getBedSpawnLocation(); + + /** + * Sets the Location where the player will spawn at their bed. + * + * @param location where to set the respawn location + */ + public void setBedSpawnLocation(Location location); + + /** + * Sets the Location where the player will spawn at their bed. + * + * @param location where to set the respawn location + * @param force whether to forcefully set the respawn location even if a + * valid bed is not present + */ + public void setBedSpawnLocation(Location location, boolean force); + + /** + * Attempts to make the entity sleep at the given location. + *
+ * The location must be in the current world and have a bed placed at the + * location. The game may also enforce other requirements such as proximity + * to bed, monsters, and dimension type if force is not set. + * + * @param location the location of the bed + * @param force whether to try and sleep at the location even if not + * normally possible + * @return whether the sleep was successful + */ + public boolean sleep(Location location, boolean force); + + /** + * Causes the player to wakeup if they are currently sleeping. + * + * @param setSpawnLocation whether to set their spawn location to the bed + * they are currently sleeping in + * @throws IllegalStateException if not sleeping + */ + public void wakeup(boolean setSpawnLocation); + + /** + * Gets the location of the bed the player is currently sleeping in + * + * @return location + * @throws IllegalStateException if not sleeping + */ + public Location getBedLocation(); + /** * Gets this human's current {@link GameMode} * diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index 9399a420c1..b7aff5cb4b 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -887,30 +887,6 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM */ public void setFoodLevel(int value); - /** - * Gets the Location where the player will spawn at their bed, null if - * they have not slept in one or their current bed spawn is invalid. - * - * @return Bed Spawn Location if bed exists, otherwise null. - */ - public Location getBedSpawnLocation(); - - /** - * Sets the Location where the player will spawn at their bed. - * - * @param location where to set the respawn location - */ - public void setBedSpawnLocation(Location location); - - /** - * Sets the Location where the player will spawn at their bed. - * - * @param location where to set the respawn location - * @param force whether to forcefully set the respawn location even if a - * valid bed is not present - */ - public void setBedSpawnLocation(Location location, boolean force); - /** * Determines if the Player is allowed to fly via jump key double-tap like * in creative mode.