Metadata utilities
This commit is contained in:
parent
9e530ebed8
commit
f7fe6a3187
3 changed files with 32 additions and 3 deletions
|
@ -63,6 +63,15 @@ public class EntityMeta implements EntityMetadataProvider {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityMeta(EntityMeta other) {
|
||||||
|
this(other.entityId, new Metadata(other.entityId));
|
||||||
|
metadata.setMetaFromPacket(other.createPacket());
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMeta(int entityId) {
|
||||||
|
this(entityId, new Metadata(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
public void setNotifyAboutChanges(boolean notifyAboutChanges) {
|
public void setNotifyAboutChanges(boolean notifyAboutChanges) {
|
||||||
metadata.setNotifyAboutChanges(notifyAboutChanges);
|
metadata.setNotifyAboutChanges(notifyAboutChanges);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,33 @@ public class Metadata {
|
||||||
|
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private volatile boolean notifyAboutChanges = true;
|
private volatile boolean notifyAboutChanges = true;
|
||||||
private final Map<Byte, EntityData> notNotifiedChanges = new HashMap<>();
|
private final HashMap<Byte, EntityData> notNotifiedChanges = new HashMap<>();
|
||||||
private final Map<Byte, EntityData> metadataMap = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Byte, EntityData> metadataMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public Metadata(int entityId) {
|
public Metadata(int entityId) {
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void copyTo(Metadata other) {
|
||||||
|
other.clear();
|
||||||
|
synchronized (other.notNotifiedChanges) {
|
||||||
|
other.notNotifiedChanges.putAll(notNotifiedChanges);
|
||||||
|
}
|
||||||
|
other.metadataMap.putAll(metadataMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyFrom(Metadata other) {
|
||||||
|
other.copyTo(this); // Scuffed pepelaugh
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the internal metadata map, is not responsible for informing the clients entity view with the newly reset information
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
this.metadataMap.clear();
|
||||||
|
this.notNotifiedChanges.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public <T> T getIndex(byte index, @Nullable T defaultValue) {
|
public <T> T getIndex(byte index, @Nullable T defaultValue) {
|
||||||
EntityData value = this.metadataMap.get(index);
|
EntityData value = this.metadataMap.get(index);
|
||||||
return value != null ? (T) value.getValue() : defaultValue;
|
return value != null ? (T) value.getValue() : defaultValue;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
val fullVersion = "3.0.0"
|
val fullVersion = "3.0.1"
|
||||||
val snapshot = true
|
val snapshot = true
|
||||||
|
|
||||||
group = "me.tofaa.entitylib"
|
group = "me.tofaa.entitylib"
|
||||||
|
|
Loading…
Reference in a new issue