mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 17:47:35 +01:00
Make more async friendly
This commit is contained in:
parent
ea34a18ebe
commit
ad89e9aa83
@ -125,18 +125,20 @@ public class ProtocolLibListener implements Listener {
|
||||
uuid -> mirrorTraits.get(uuid));
|
||||
return;
|
||||
}
|
||||
|
||||
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().readSafely(0);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
boolean changed = false;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
PlayerInfoData npcInfo = list.get(i);
|
||||
if (npcInfo == null)
|
||||
continue;
|
||||
MirrorTrait trait = mirrorTraits.get(npcInfo.getProfile().getUUID());
|
||||
if (trait == null || !trait.isMirroring(event.getPlayer())) {
|
||||
if (trait == null || !trait.isMirroring(event.getPlayer()))
|
||||
continue;
|
||||
}
|
||||
|
||||
GameProfile playerProfile = NMS.getProfile(event.getPlayer());
|
||||
if (trait.mirrorName()) {
|
||||
list.set(i,
|
||||
@ -166,7 +168,7 @@ public class ProtocolLibListener implements Listener {
|
||||
}
|
||||
});
|
||||
manager.addPacketListener(new PacketAdapter(
|
||||
plugin, ListenerPriority.MONITOR, Arrays.asList(Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK,
|
||||
plugin, ListenerPriority.HIGHEST, Arrays.asList(Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK,
|
||||
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_MOVE_LOOK, Server.POSITION, Server.ENTITY_TELEPORT),
|
||||
ListenerOptions.ASYNC) {
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ public class RotationTrait extends Trait {
|
||||
@Persist(reify = true)
|
||||
private final RotationParams globalParameters = new RotationParams();
|
||||
private final RotationSession globalSession = new RotationSession(globalParameters);
|
||||
private final List<PacketRotationSession> packetSessions = Lists.newArrayList();
|
||||
private final List<PacketRotationSession> packetSessions = Lists.newCopyOnWriteArrayList();
|
||||
private final Map<UUID, PacketRotationSession> packetSessionsByUUID = Maps.newConcurrentMap();
|
||||
|
||||
public RotationTrait() {
|
||||
@ -60,6 +60,7 @@ public class RotationTrait extends Trait {
|
||||
} else {
|
||||
packetSessions.add(lrs);
|
||||
}
|
||||
|
||||
return lrs;
|
||||
}
|
||||
|
||||
@ -79,11 +80,13 @@ public class RotationTrait extends Trait {
|
||||
PacketRotationSession lrs = packetSessionsByUUID.get(player.getUniqueId());
|
||||
if (lrs != null && lrs.triple != null)
|
||||
return lrs;
|
||||
|
||||
for (PacketRotationSession session : packetSessions) {
|
||||
if (session.accepts(player) && session.triple != null) {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -95,6 +98,7 @@ public class RotationTrait extends Trait {
|
||||
public void run() {
|
||||
if (!npc.isSpawned())
|
||||
return;
|
||||
|
||||
if (npc.data().get(NPC.Metadata.RESET_PITCH_ON_TICK, false)) {
|
||||
NMS.setPitch(npc.getEntity(), 0);
|
||||
}
|
||||
@ -180,6 +184,7 @@ public class RotationTrait extends Trait {
|
||||
public void onPacketOverwritten() {
|
||||
if (triple == null)
|
||||
return;
|
||||
|
||||
triple.record();
|
||||
}
|
||||
|
||||
@ -224,7 +229,7 @@ public class RotationTrait extends Trait {
|
||||
private boolean linkedBody;
|
||||
private float maxPitchPerTick = 10;
|
||||
private float maxYawPerTick = 40;
|
||||
private boolean persist = false;
|
||||
private volatile boolean persist = false;
|
||||
private float[] pitchRange = { -180, 180 };
|
||||
private List<UUID> uuidFilter;
|
||||
private float[] yawRange = { -180, 180 };
|
||||
@ -383,7 +388,7 @@ public class RotationTrait extends Trait {
|
||||
|
||||
public class RotationSession {
|
||||
private final RotationParams params;
|
||||
private int t = -1;
|
||||
private volatile int t = -1;
|
||||
private Supplier<Float> targetPitch = () -> 0F;
|
||||
private Supplier<Float> targetYaw = targetPitch;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user