diff --git a/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java b/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java index 9fd6025..80a8fff 100644 --- a/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java +++ b/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java @@ -63,6 +63,15 @@ public class EntityMeta implements EntityMetadataProvider { 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) { metadata.setNotifyAboutChanges(notifyAboutChanges); } diff --git a/api/src/main/java/me/tofaa/entitylib/meta/Metadata.java b/api/src/main/java/me/tofaa/entitylib/meta/Metadata.java index 9841a8b..5f91115 100644 --- a/api/src/main/java/me/tofaa/entitylib/meta/Metadata.java +++ b/api/src/main/java/me/tofaa/entitylib/meta/Metadata.java @@ -19,13 +19,33 @@ public class Metadata { private final int entityId; private volatile boolean notifyAboutChanges = true; - private final Map notNotifiedChanges = new HashMap<>(); - private final Map metadataMap = new ConcurrentHashMap<>(); + private final HashMap notNotifiedChanges = new HashMap<>(); + private final ConcurrentHashMap metadataMap = new ConcurrentHashMap<>(); public Metadata(int 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 getIndex(byte index, @Nullable T defaultValue) { EntityData value = this.metadataMap.get(index); return value != null ? (T) value.getValue() : defaultValue; diff --git a/build.gradle.kts b/build.gradle.kts index 3548b0c..4d833fc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ import java.io.ByteArrayOutputStream -val fullVersion = "3.0.0" +val fullVersion = "3.0.1" val snapshot = true group = "me.tofaa.entitylib"