77import com .github .retrooper .packetevents .wrapper .play .server .WrapperPlayServerPlayerInfo ;
88import com .github .retrooper .packetevents .wrapper .play .server .WrapperPlayServerPlayerInfoRemove ;
99import me .tofaa .entitylib .wrapper .WrapperEntity ;
10+ import me .tofaa .entitylib .wrapper .WrapperPlayer ;
1011import org .bukkit .World ;
1112import org .bukkit .entity .Player ;
1213import org .bukkit .event .EventHandler ;
@@ -36,15 +37,22 @@ public void onPlayerJoin(PlayerJoinEvent event) {
3637 Location npcLoc = npc .getPosition ();
3738 if (viewDistance > 0 && !isPlayerInRange (playerLoc , npcLoc , viewDistance )) continue ;
3839
39- npc .getEntity ().get (). addViewer ( playerId );
40+ boolean isSitting = npc .getSittingEntity ().isPresent ( );
4041
41- npc .getSittingEntity ().ifPresent (sitting -> sitting .addViewer (playerId ));
42+ if (isSitting ) {
43+ npc .getSittingEntity ().ifPresent (sitting -> sitting .addViewer (playerId ));
44+ }
45+
46+ npc .getEntity ().ifPresent (entity -> {
47+ entity .addViewer (playerId );
48+ if (entity instanceof me .tofaa .entitylib .wrapper .WrapperPlayer ) {
49+ npc .doStupidDogshitForOldClients (player );
50+ }
51+ });
4252
4353 if (npc .getHologram ().isPresent ()) {
4454 npc .getHologram ().get ().addViewer (playerId );
4555 }
46-
47- npc .doStupidDogshitForOldClients (player );
4856 }
4957 }
5058
@@ -56,10 +64,10 @@ public void onPlayerQuit(PlayerQuitEvent event) {
5664 for (NPC npc : NPCRegistry .getAll ()) {
5765 if (!npc .isSpawned () || !npc .getEntity ().isPresent ()) continue ;
5866
59- npc .getEntity ().get ().removeViewer (playerId );
60-
6167 npc .getSittingEntity ().ifPresent (sitting -> sitting .removeViewer (playerId ));
6268
69+ npc .getEntity ().ifPresent (entity -> entity .removeViewer (playerId ));
70+
6371 if (npc .getHologram ().isPresent ()) {
6472 npc .getHologram ().get ().removeViewer (playerId );
6573 }
@@ -85,29 +93,49 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
8593 Location npcLoc = npc .getPosition ();
8694 boolean inRange = viewDistance <= 0 || isPlayerInRange (playerLoc , npcLoc , viewDistance );
8795
88- npc .getEntity ().ifPresent (entity -> {
89- if (inRange ) {
90- if (!entity .getViewers ().contains (playerId )) {
91- entity .addViewer (playerId );
96+ boolean isSitting = npc .getSittingEntity ().isPresent ();
97+
98+ if (isSitting ) {
99+ npc .getSittingEntity ().ifPresent (sitting -> {
100+ if (inRange ) {
101+ if (!sitting .getViewers ().contains (playerId )) {
102+ sitting .addViewer (playerId );
103+ }
104+ npc .getEntity ().ifPresent (entity -> {
105+ if (!entity .getViewers ().contains (playerId )) {
106+ entity .addViewer (playerId );
107+ }
108+ if (entity instanceof me .tofaa .entitylib .wrapper .WrapperPlayer ) {
109+ npc .doStupidDogshitForOldClients (player );
110+ }
111+ });
112+ } else {
113+ if (sitting .getViewers ().contains (playerId )) {
114+ sitting .removeViewer (playerId );
115+ }
116+ npc .getEntity ().ifPresent (entity -> {
117+ if (entity .getViewers ().contains (playerId )) {
118+ entity .removeViewer (playerId );
119+ }
120+ });
92121 }
93- } else {
94- if (entity .getViewers ().contains (playerId )) {
95- entity .removeViewer (playerId );
122+ });
123+ } else {
124+ npc .getEntity ().ifPresent (entity -> {
125+ if (inRange ) {
126+ if (!entity .getViewers ().contains (playerId )) {
127+ entity .addViewer (playerId );
128+ }
129+ if (entity instanceof me .tofaa .entitylib .wrapper .WrapperPlayer ) {
130+ npc .doStupidDogshitForOldClients (player );
131+ }
132+ } else {
133+ if (entity .getViewers ().contains (playerId )) {
134+ entity .removeViewer (playerId );
135+ }
96136 }
97- }
98- });
99-
100- npc .getSittingEntity ().ifPresent (sitting -> {
101- if (inRange ) {
102- if (!sitting .getViewers ().contains (playerId )) {
103- sitting .addViewer (playerId );
104- }
105- } else {
106- if (sitting .getViewers ().contains (playerId )) {
107- sitting .removeViewer (playerId );
108- }
109- }
110- });
137+ });
138+ }
111139
112140 npc .getHologram ().ifPresent (hologram -> {
113141 if (inRange ) {
0 commit comments