diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 690329ed4..e6f0042bd 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -159,41 +159,46 @@ public class EventListen implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChunkUnload(final ChunkUnloadEvent event) { - ChunkCoord coord = new ChunkCoord(event.getChunk()); - boolean loadChunk = false; - for (Entity entity : event.getChunk().getEntities()) { - NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity); - if (npc == null || !npc.isSpawned()) - continue; - if (!npc.despawn(DespawnReason.CHUNK_UNLOAD)) { - if (!(event instanceof Cancellable)) { - loadChunk = true; + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { + @Override + public void run() { + ChunkCoord coord = new ChunkCoord(event.getChunk()); + boolean loadChunk = false; + for (Entity entity : event.getChunk().getEntities()) { + NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity); + if (npc == null || !npc.isSpawned()) + continue; + if (!npc.despawn(DespawnReason.CHUNK_UNLOAD)) { + if (!(event instanceof Cancellable)) { + loadChunk = true; + toRespawn.put(coord, npc); + continue; + } + ((Cancellable) event).setCancelled(true); + if (Messaging.isDebugging()) { + Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]"); + } + respawnAllFromCoord(coord); + return; + } toRespawn.put(coord, npc); - continue; - } - ((Cancellable) event).setCancelled(true); - if (Messaging.isDebugging()) { - Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]"); - } - respawnAllFromCoord(coord); - return; - } - toRespawn.put(coord, npc); - if (Messaging.isDebugging()) { - Messaging.debug("Despawned id", npc.getId(), - "due to chunk unload at [" + coord.x + "," + coord.z + "]"); - } - } - if (loadChunk) { - Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { - @Override - public void run() { - if (!event.getChunk().isLoaded()) { - event.getChunk().load(); + if (Messaging.isDebugging()) { + Messaging.debug("Despawned id", npc.getId(), + "due to chunk unload at [" + coord.x + "," + coord.z + "]"); } } - }, 10); - } + if (loadChunk) { + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { + @Override + public void run() { + if (!event.getChunk().isLoaded()) { + event.getChunk().load(); + } + } + }, 10); + } + } + }); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index 83ef41cf0..76a11372a 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -228,7 +228,8 @@ public class CommandTrait extends Trait { } long currentTimeSec = System.currentTimeMillis() / 1000; if (lastUsed.containsKey(command.command)) { - if (currentTimeSec < ((Number) (lastUsed.get(command.command) + command.cooldown)).longValue()) { + if (currentTimeSec < ((Number) (lastUsed.get(command.command) + + ((Number) command.cooldown).longValue())).longValue()) { return false; } lastUsed.remove(command.command); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/CitizensBlockBreaker.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/CitizensBlockBreaker.java index 633cf6203..45e54815c 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/CitizensBlockBreaker.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/CitizensBlockBreaker.java @@ -30,6 +30,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -69,6 +70,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -92,6 +100,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerControllerLook.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerControllerLook.java index 29249c734..954ce9b16 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerControllerLook.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerControllerLook.java @@ -42,6 +42,7 @@ public class PlayerControllerLook { this.a.aQ += 360F; } } else { + this.a.yaw = this.a.aQ + 40; // this.a.aQ = a(this.a.aQ, this.a.aO, 10.0F); } float f3 = MathHelper.g(this.a.aQ - this.a.aO); @@ -56,6 +57,10 @@ public class PlayerControllerLook { } public void a(double d0, double d1, double d2, float f, float f1) { + double d = Math.pow(this.e - d0, 2) + Math.pow(this.f - d1, 2) + Math.pow(this.g - d2, 2); + if (d < 0.01) { + return; + } this.e = d0; this.f = d1; this.g = d2; diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/CitizensBlockBreaker.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/CitizensBlockBreaker.java index 732ddabe1..a433c220b 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/CitizensBlockBreaker.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/CitizensBlockBreaker.java @@ -30,6 +30,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -69,6 +70,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -92,6 +100,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerControllerLook.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerControllerLook.java index c3d4aa86d..856ec258c 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerControllerLook.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerControllerLook.java @@ -42,6 +42,7 @@ public class PlayerControllerLook { this.a.aP += 360F; } } else { + this.a.yaw = this.a.aP + 40; // this.a.aP = a(this.a.aP, this.a.aN, 10.0F); } float f3 = MathHelper.g(this.a.aP - this.a.aN); @@ -56,6 +57,10 @@ public class PlayerControllerLook { } public void a(double d0, double d1, double d2, float f, float f1) { + double d = Math.pow(this.e - d0, 2) + Math.pow(this.f - d1, 2) + Math.pow(this.g - d2, 2); + if (d < 0.01) { + return; + } this.e = d0; this.f = d1; this.g = d2; diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/CitizensBlockBreaker.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/CitizensBlockBreaker.java index 4f3d41a0d..91ca551f1 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/CitizensBlockBreaker.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/CitizensBlockBreaker.java @@ -30,6 +30,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -69,6 +70,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -92,6 +100,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerControllerLook.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerControllerLook.java index 85c962c25..8dd0ea7eb 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerControllerLook.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerControllerLook.java @@ -42,6 +42,7 @@ public class PlayerControllerLook { this.a.aP += 360F; } } else { + this.a.yaw = this.a.aP + 40; // this.a.aP = a(this.a.aP, this.a.aN, 10.0F); } float f3 = MathHelper.g(this.a.aP - this.a.aN); @@ -56,6 +57,10 @@ public class PlayerControllerLook { } public void a(double d0, double d1, double d2, float f, float f1) { + double d = Math.pow(this.e - d0, 2) + Math.pow(this.f - d1, 2) + Math.pow(this.g - d2, 2); + if (d < 0.01) { + return; + } this.e = d0; this.f = d1; this.g = d2; diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/CitizensBlockBreaker.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/CitizensBlockBreaker.java index c0d604d0b..bcf052dae 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/CitizensBlockBreaker.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/CitizensBlockBreaker.java @@ -30,6 +30,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -69,6 +70,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -92,6 +100,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerControllerLook.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerControllerLook.java index a2aeff98a..c5cbf6a83 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerControllerLook.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerControllerLook.java @@ -43,6 +43,7 @@ public class PlayerControllerLook { this.a.aS += 360F; } } else { + this.a.yaw = this.a.aS + 40; // this.a.aP = a(this.a.aS, this.a.aQ, 10.0F); } float f3 = MathHelper.g(this.a.aS - this.a.aQ); @@ -57,6 +58,10 @@ public class PlayerControllerLook { } public void a(double d0, double d1, double d2, float f, float f1) { + double d = Math.pow(this.e - d0, 2) + Math.pow(this.f - d1, 2) + Math.pow(this.g - d2, 2); + if (d < 0.01) { + return; + } this.e = d0; this.f = d1; this.g = d2; diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/CitizensBlockBreaker.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/CitizensBlockBreaker.java index 47c76cbf7..f8abb5962 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/CitizensBlockBreaker.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/CitizensBlockBreaker.java @@ -31,6 +31,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -70,6 +71,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -93,6 +101,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerControllerLook.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerControllerLook.java index ad1b753f8..61035fae0 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerControllerLook.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerControllerLook.java @@ -31,6 +31,7 @@ public class PlayerControllerLook { this.a.yaw = this.a.aM; this.a.pitch = this.a(this.a.pitch, this.g(), this.c); } else { + this.a.yaw = this.a.aM + 40; // this.a.aM = this.a(this.a.aM, this.a.aK, 10.0F); } @@ -44,6 +45,10 @@ public class PlayerControllerLook { } public void a(double var0, double var2, double var4, float var6, float var7) { + double d = Math.pow(this.e - var0, 2) + Math.pow(this.f - var2, 2) + Math.pow(this.g - var4, 2); + if (d < 0.01) { + return; + } this.e = var0; this.f = var2; this.g = var4; diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/CitizensBlockBreaker.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/CitizensBlockBreaker.java index 3008810cf..d631f9603 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/CitizensBlockBreaker.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/CitizensBlockBreaker.java @@ -31,6 +31,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -70,6 +71,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -93,6 +101,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerControllerLook.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerControllerLook.java index 42bce49d2..a72b94c49 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerControllerLook.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerControllerLook.java @@ -31,6 +31,7 @@ public class PlayerControllerLook { this.a.yaw = this.a.aK; this.a.pitch = this.a(this.a.pitch, this.g(), this.c); } else { + this.a.yaw = this.a.aK + 40; // this.a.aK = this.a(this.a.aK, this.a.aI, 10.0F); } @@ -44,6 +45,10 @@ public class PlayerControllerLook { } public void a(double var0, double var2, double var4, float var6, float var7) { + double d = Math.pow(this.e - var0, 2) + Math.pow(this.f - var2, 2) + Math.pow(this.g - var4, 2); + if (d < 0.01) { + return; + } this.e = var0; this.f = var2; this.g = var4; diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java index 8023db8f3..2afeb66c6 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java @@ -30,6 +30,7 @@ public class CitizensBlockBreaker extends BlockBreaker { private final Entity entity; private boolean isDigging = true; private final Location location; + private boolean setTarget; private int startDigTick; private final int x, y, z; @@ -69,6 +70,13 @@ public class CitizensBlockBreaker extends BlockBreaker { @Override public void reset() { + if (setTarget && entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } + } + setTarget = false; if (configuration.callback() != null) { configuration.callback().run(); } @@ -92,6 +100,7 @@ public class CitizensBlockBreaker extends BlockBreaker { if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + setTarget = true; } } return BehaviorStatus.RUNNING; diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java index c5a6cfbc3..22c5c7252 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java @@ -43,6 +43,7 @@ public class PlayerControllerLook { this.a.aK += 360F; } } else { + this.a.yaw = this.a.aK + 40; // this.a.aK = a(this.a.aK, this.a.aI, 10.0F); } float f3 = MathHelper.g(this.a.aK - this.a.aI); @@ -57,6 +58,10 @@ public class PlayerControllerLook { } public void a(double d0, double d1, double d2, float f, float f1) { + double d = Math.pow(this.e - d0, 2) + Math.pow(this.f - d1, 2) + Math.pow(this.g - d2, 2); + if (d < 0.01) { + return; + } this.e = d0; this.f = d1; this.g = d2;