mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-22 16:11:44 +01:00
Avoid entity field lookup
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
0f2be00291
commit
765d6057da
@ -174,25 +174,27 @@ public final class Metadata {
|
|||||||
public void setIndex(int index, @NotNull Entry<?> entry) {
|
public void setIndex(int index, @NotNull Entry<?> entry) {
|
||||||
this.metadataMap.put(index, entry);
|
this.metadataMap.put(index, entry);
|
||||||
// Send metadata packet to update viewers and self
|
// Send metadata packet to update viewers and self
|
||||||
if (this.entity != null && this.entity.isActive()) {
|
final Entity entity = this.entity;
|
||||||
|
if (entity != null && entity.isActive()) {
|
||||||
if (!this.notifyAboutChanges) {
|
if (!this.notifyAboutChanges) {
|
||||||
synchronized (this.notNotifiedChanges) {
|
synchronized (this.notNotifiedChanges) {
|
||||||
this.notNotifiedChanges.put(index, entry);
|
this.notNotifiedChanges.put(index, entry);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), Map.of(index, entry)));
|
entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), Map.of(index, entry)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotifyAboutChanges(boolean notifyAboutChanges) {
|
public void setNotifyAboutChanges(boolean notifyAboutChanges) {
|
||||||
if (!NOTIFIED_CHANGES.compareAndSet(this, !notifyAboutChanges, notifyAboutChanges)) {
|
if (!NOTIFIED_CHANGES.compareAndSet(this, !notifyAboutChanges, notifyAboutChanges))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!notifyAboutChanges) {
|
if (!notifyAboutChanges) {
|
||||||
// Ask future metadata changes to be cached
|
// Ask future metadata changes to be cached
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final Entity entity = this.entity;
|
||||||
|
if (entity == null || !entity.isActive()) return;
|
||||||
Map<Integer, Entry<?>> entries;
|
Map<Integer, Entry<?>> entries;
|
||||||
synchronized (this.notNotifiedChanges) {
|
synchronized (this.notNotifiedChanges) {
|
||||||
Map<Integer, Entry<?>> awaitingChanges = this.notNotifiedChanges;
|
Map<Integer, Entry<?>> awaitingChanges = this.notNotifiedChanges;
|
||||||
@ -200,10 +202,7 @@ public final class Metadata {
|
|||||||
entries = Map.copyOf(awaitingChanges);
|
entries = Map.copyOf(awaitingChanges);
|
||||||
awaitingChanges.clear();
|
awaitingChanges.clear();
|
||||||
}
|
}
|
||||||
if (entries == null || this.entity == null || !this.entity.isActive()) {
|
entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), entries));
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), entries));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Map<Integer, Entry<?>> getEntries() {
|
public @NotNull Map<Integer, Entry<?>> getEntries() {
|
||||||
|
Loading…
Reference in New Issue
Block a user