From 102630a5e0eeed8ceb762255610321a916254e81 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 12 Nov 2022 12:51:40 +0800 Subject: [PATCH] Pass wander pause through to wander goal, fix SleepTrait --- .../net/citizensnpcs/trait/SleepTrait.java | 18 +++++++++++------- .../trait/waypoint/WanderWaypointProvider.java | 7 +++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java b/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java index 43b0f9200..a0ecf3525 100644 --- a/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java @@ -25,12 +25,16 @@ public class SleepTrait extends Trait { public void run() { if (!npc.isSpawned()) return; - if (sleeping && at != null) { - return; - } else if (sleeping && at == null) { - stopSleeping(); + if (sleeping) { + if (at == null) { + wakeup(); + } return; } + if (at == null) + return; + + npc.teleport(at, TeleportCause.PLUGIN); if (npc.getEntity() instanceof Player) { Player player = (Player) npc.getEntity(); if (at.getBlock().getBlockData() instanceof Bed || at.getBlock().getState() instanceof Bed) { @@ -46,15 +50,15 @@ public class SleepTrait extends Trait { public void setSleeping(Location at) { this.at = at != null ? at.clone() : null; - stopSleeping(); - npc.teleport(at, TeleportCause.PLUGIN); + wakeup(); } - private void stopSleeping() { + private void wakeup() { if (npc.getEntity() instanceof Player) { NMS.sleep((Player) npc.getEntity(), false); } else if (npc.getEntity() instanceof Villager) { ((Villager) npc.getEntity()).wakeup(); } + sleeping = false; } } diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index e4ba2e073..214c0f36c 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -345,6 +345,13 @@ public class WanderWaypointProvider @Override public void setPaused(boolean paused) { this.paused = paused; + if (currentGoal != null) { + if (paused) { + currentGoal.pause(); + } else { + currentGoal.unpause(); + } + } } public void setXYRange(int xrange, int yrange) {