@@ -47,6 +47,8 @@ public abstract class NPC {
4747 protected double x ;
4848 protected double y ;
4949 protected double z ;
50+ protected float yaw ;
51+ protected float pitch ;
5052 protected BukkitTask updateSeeingTask ;
5153 protected Consumer <Player > onClickAction ;
5254 protected final NPCHandler npcHandler ;
@@ -61,6 +63,8 @@ public NPC(String name, String worldName, double x, double y, double z, EntityTy
6163 this .x = x ;
6264 this .y = y ;
6365 this .z = z ;
66+ this .yaw = 0 ;
67+ this .pitch = 0 ;
6468 this .equipments = new ArrayList <>();
6569 this .entityType = entityType ;
6670
@@ -73,7 +77,6 @@ public NPC(String name, String worldName, double x, double y, double z, EntityTy
7377 oldVersion = versionHandler .isServerOlderThan (Version .v1_17 );
7478
7579 npcHandler .getNpcs ().add (this );
76-
7780 startSeeingTask ();
7881 }
7982
@@ -108,9 +111,7 @@ public void run() {
108111
109112 Location playerLocation = player .getLocation ();
110113 if (playerLocation .getWorld () != world ) despawn (player , false );
111- else if (playerLocation .distance (location ) > 32 ) {
112- despawn (player , false );
113- }
114+ else if (playerLocation .distance (location ) > 32 ) despawn (player , false );
114115 });
115116
116117 List <UUID > newSeeingList = new ArrayList <>();
@@ -146,7 +147,8 @@ public void spawn(Player player) {
146147 );
147148
148149 queuePacket (spawnPacket , player );
149- update ();
150+
151+ Bukkit .getScheduler ().scheduleSyncDelayedTask (LitLibsPlugin .getInstance (), this ::update , 10 );
150152 }
151153
152154 public void update () {
@@ -167,10 +169,6 @@ public void updateEquipment(List<Equipment> equipments) {
167169 }
168170
169171 public void updateRotation () {
170- Location location = getLocation ();
171- float yaw = location .getYaw ();
172- float pitch = location .getPitch ();
173-
174172 WrapperPlayServerEntityRotation packet = new WrapperPlayServerEntityRotation (
175173 entityId ,
176174 yaw ,
@@ -261,4 +259,11 @@ public Location getLocation() {
261259 return new Location (Bukkit .getWorld (worldName ), x , y , z );
262260 }
263261
262+ public void setLocation (Location location ) {
263+ this .x = location .getX ();
264+ this .y = location .getY ();
265+ this .z = location .getZ ();
266+ this .worldName = location .getWorld ().getName ();
267+ }
268+
264269}
0 commit comments