diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index fa9cedd6e2..28ebb73a9b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -173,7 +173,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { @Override public boolean sleep(Location location, boolean force) { - Preconditions.checkArgument(location != null, "Location == null"); + Preconditions.checkArgument(location != null, "Location cannot be null"); + Preconditions.checkArgument(location.getWorld() != null, "Location needs to be in a world"); Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds"); BlockPosition blockposition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index ba769f985e..f291a8d754 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -5,7 +5,11 @@ import java.util.Locale; import net.minecraft.server.EntityVillager; import net.minecraft.server.IRegistry; import net.minecraft.server.VillagerProfession; +import net.minecraft.server.IBlockData; +import net.minecraft.server.BlockPosition; +import net.minecraft.server.BlockBed; import org.apache.commons.lang.Validate; +import org.bukkit.Location; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; @@ -78,6 +82,29 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { getHandle().setExperience(experience); } + @Override + public boolean sleep(Location location) { + Preconditions.checkArgument(location != null, "Location cannot be null"); + Preconditions.checkArgument(location.getWorld() != null, "Location needs to be in a world"); + Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds"); + + BlockPosition position = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + IBlockData iblockdata = getHandle().world.getType(position); + if (!(iblockdata.getBlock() instanceof BlockBed)) { + return false; + } + + getHandle().e(position); // PAIL rename sleep + return true; + } + + @Override + public void wakeup() { + Preconditions.checkState(isSleeping(), "Cannot wakeup if not sleeping"); + + getHandle().dy(); // PAIL rename wakeup + } + public static Profession nmsToBukkitProfession(VillagerProfession nms) { return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getKey().toUpperCase(Locale.ROOT)); }