From 284565598edd803fb81ccb81fb02db18ab55399e Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 27 Dec 2020 20:54:21 +0800 Subject: [PATCH] Trial a new method for fixing spawn body yaw, fix /npc rename not applying hologram name immediately --- .../java/net/citizensnpcs/npc/CitizensNPC.java | 17 +++++++++++++++++ .../trait/waypoint/WanderWaypointProvider.java | 2 +- .../java/net/citizensnpcs/util/Messages.java | 1 + main/src/main/resources/messages_en.properties | 1 + .../nms/v1_16_R3/util/PlayerControllerLook.java | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 34550745b..29bd3b75e 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -48,6 +48,7 @@ import net.citizensnpcs.trait.ScoreboardTrait; import net.citizensnpcs.util.ChunkCoord; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.PlayerAnimation; import net.citizensnpcs.util.PlayerUpdateTask; import net.citizensnpcs.util.Util; @@ -221,6 +222,15 @@ public class CitizensNPC extends AbstractNPC { updateFlyableState(); } + @Override + public void setName(String name) { + super.setName(name); + + if (requiresNameHologram() && !hasTrait(HologramTrait.class)) { + addTrait(HologramTrait.class); + } + } + @Override public boolean spawn(Location at) { return spawn(at, SpawnReason.PLUGIN); @@ -261,6 +271,7 @@ public class CitizensNPC extends AbstractNPC { Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at)); return false; } + // send skin packets, if applicable, before other NMS packets are sent SkinnableEntity skinnable = getEntity() instanceof SkinnableEntity ? ((SkinnableEntity) getEntity()) : null; if (skinnable != null) { @@ -309,6 +320,12 @@ public class CitizensNPC extends AbstractNPC { if (getEntity() instanceof Player) { NMS.replaceTrackerEntry((Player) getEntity()); PlayerUpdateTask.registerPlayer(getEntity()); + Bukkit.getScheduler().runTaskLater(CitizensAPI.getPlugin(), new Runnable() { + @Override + public void run() { + PlayerAnimation.ARM_SWING.play((Player) getEntity()); + } + }, Setting.TABLIST_REMOVE_PACKET_DELAY.asLong()); } } 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 a496bd3b1..95d907143 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -176,6 +176,7 @@ public class WanderWaypointProvider Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_REGION_EDITING_START); } else { markers.destroyMarkers(); + Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_REGION_EDITING_STOP); } } }); @@ -187,7 +188,6 @@ public class WanderWaypointProvider currentGoal.setDelay(delay); } Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { - @Override public void run() { Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_DELAY_SET, delay); diff --git a/main/src/main/java/net/citizensnpcs/util/Messages.java b/main/src/main/java/net/citizensnpcs/util/Messages.java index e8854cc2d..f1c282299 100644 --- a/main/src/main/java/net/citizensnpcs/util/Messages.java +++ b/main/src/main/java/net/citizensnpcs/util/Messages.java @@ -383,6 +383,7 @@ public class Messages { public static final String WANDER_WAYPOINTS_INVALID_DELAY = "citizens.editors.waypoints.wander.invalid-delay"; public static final String WANDER_WAYPOINTS_RANGE_SET = "citizens.editors.waypoints.wander.range-set"; public static final String WANDER_WAYPOINTS_REGION_EDITING_START = "citizens.editors.waypoints.wander.editing-regions"; + public static final String WANDER_WAYPOINTS_REGION_EDITING_STOP = "citizens.editors.waypoints.wander.editing-regions-stop"; public static final String WANDER_WAYPOINTS_REMOVED_REGION = "citizens.editors.waypoints.wander.removed-region"; public static final String WANDER_WAYPOINTS_WORLDGUARD_REGION_NOT_FOUND = "citizens.editors.waypoints.wander.worldguard-region-not-found"; public static final String WANDER_WAYPOINTS_WORLDGUARD_REGION_SET = "citizens.editors.waypoints.wander.worldguard-region-set"; diff --git a/main/src/main/resources/messages_en.properties b/main/src/main/resources/messages_en.properties index 7df71f75b..405f21c1b 100644 --- a/main/src/main/resources/messages_en.properties +++ b/main/src/main/resources/messages_en.properties @@ -320,6 +320,7 @@ citizens.editors.text.remove-prompt=Enter the index of the entry you wish to rem citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]]. citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC to send messages when players get close, [[item]] to set the talk item in hand pattern (set to [[default]] to clear), [[range]] to set the talking range, [[delay]] to set the talking delay in seconds and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again. citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]]. +citizens.editors.waypoints.wander.editing-regions-stop=Exited the region editor. citizens.editors.waypoints.wander.worldguard-region-not-found=WorldGuard region not found. citizens.editors.waypoints.wander.worldguard-region-set=WorldGuard region set to [[{0}]]. citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]]. diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java index c852e9c43..203033f95 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerControllerLook.java @@ -29,7 +29,7 @@ public class PlayerControllerLook { this.d = false; this.a.pitch = this.a(this.a.pitch, this.g(), this.c); this.a.aC = this.a(this.a.aC, this.h(), this.b); - this.a.yaw = this.a.aC; + this.a.yaw = this.a(this.a.aC, this.h(), this.b); while (this.a.aC >= 180F) { this.a.aC -= 360F; }