|
2 | 2 |
|
3 | 3 | import com.github.retrooper.packetevents.event.PacketListenerAbstract; |
4 | 4 | import com.github.retrooper.packetevents.event.PacketSendEvent; |
| 5 | +import com.github.retrooper.packetevents.event.UserDisconnectEvent; |
5 | 6 | import com.github.retrooper.packetevents.protocol.packettype.PacketType; |
6 | 7 | import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; |
7 | 8 | import com.github.retrooper.packetevents.protocol.player.User; |
|
11 | 12 | import me.tofaa.entitylib.utils.Check; |
12 | 13 | import me.tofaa.entitylib.wrapper.WrapperEntity; |
13 | 14 |
|
| 15 | +import java.util.UUID; |
14 | 16 | import java.util.function.Consumer; |
15 | 17 |
|
16 | 18 | final class ViewerEngineListener extends PacketListenerAbstract { |
@@ -81,6 +83,24 @@ else if (type == PacketType.Play.Server.CHUNK_DATA) { |
81 | 83 | } |
82 | 84 | } |
83 | 85 |
|
| 86 | + @Override |
| 87 | + public void onUserDisconnect(final UserDisconnectEvent event) { |
| 88 | + engine.getExecutor().execute(() -> { |
| 89 | + final UUID uniqueId = event.getUser().getUUID(); |
| 90 | + |
| 91 | + // Note from Chubbyduck1: While this says it's non-null, it can actually be null in this case. Not sure why. When run without this, it would spam NPEs for me. |
| 92 | + if (uniqueId == null) { |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + engine.getTracked0().forEach(entity -> { |
| 97 | + if (entity.hasViewer(uniqueId)) { |
| 98 | + entity.removeViewerSilently(uniqueId); |
| 99 | + } |
| 100 | + }); |
| 101 | + }); |
| 102 | + } |
| 103 | + |
84 | 104 | private void genericSpawnCheck(int entityId, User user) { |
85 | 105 | WrapperEntity entity = EntityLib.getApi().getEntity(entityId); |
86 | 106 | if (entity == null) return; |
|
0 commit comments