diff --git a/src/main/java/net/minestom/server/data/DataContainer.java b/src/main/java/net/minestom/server/data/DataContainer.java index e5dbddbde..050712399 100644 --- a/src/main/java/net/minestom/server/data/DataContainer.java +++ b/src/main/java/net/minestom/server/data/DataContainer.java @@ -6,7 +6,10 @@ import org.jetbrains.annotations.Nullable; * Represents an element which can have a {@link Data} attached to it. *

* The data will always be optional and can therefore be null. + * + * @deprecated switch to the Tag API instead */ +@Deprecated public interface DataContainer { /** diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 10c8e3336..5378f220d 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -34,6 +34,8 @@ import net.minestom.server.permission.PermissionHandler; import net.minestom.server.potion.Potion; import net.minestom.server.potion.PotionEffect; import net.minestom.server.potion.TimedPotion; +import net.minestom.server.tag.Tag; +import net.minestom.server.tag.TagHandler; import net.minestom.server.thread.ThreadProvider; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Position; @@ -50,6 +52,7 @@ import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -65,7 +68,7 @@ import java.util.function.UnaryOperator; *

* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead. */ -public class Entity implements Viewable, Tickable, EventHandler, DataContainer, PermissionHandler, HoverEventSource, Sound.Emitter { +public class Entity implements Viewable, Tickable, EventHandler, DataContainer, TagHandler, PermissionHandler, HoverEventSource, Sound.Emitter { private static final Map ENTITY_BY_ID = new ConcurrentHashMap<>(); private static final Map ENTITY_BY_UUID = new ConcurrentHashMap<>(); @@ -103,6 +106,7 @@ public class Entity implements Viewable, Tickable, EventHandler, Da protected final Set viewers = ConcurrentHashMap.newKeySet(); private final Set unmodifiableViewers = Collections.unmodifiableSet(viewers); private Data data; + private final NBTCompound nbtCompound = new NBTCompound(); private final Set permissions = new CopyOnWriteArraySet<>(); protected UUID uuid; @@ -1610,6 +1614,16 @@ public class Entity implements Viewable, Tickable, EventHandler, Da return (Acquirable) acquirable; } + @Override + public @Nullable T getTag(@NotNull Tag tag) { + return tag.read(nbtCompound); + } + + @Override + public void setTag(@NotNull Tag tag, @Nullable T value) { + tag.write(nbtCompound, value); + } + public enum Pose { STANDING, FALL_FLYING, diff --git a/src/main/java/net/minestom/server/item/ItemMeta.java b/src/main/java/net/minestom/server/item/ItemMeta.java index 2128a180a..862e9709e 100644 --- a/src/main/java/net/minestom/server/item/ItemMeta.java +++ b/src/main/java/net/minestom/server/item/ItemMeta.java @@ -117,11 +117,6 @@ public class ItemMeta implements TagReadable, Writeable { return tag.read(nbt); } - @Override - public boolean hasTag(@NotNull Tag tag) { - return nbt.containsKey(tag.getKey()); - } - public @NotNull NBTCompound toNBT() { return nbt.deepClone(); } diff --git a/src/main/java/net/minestom/server/item/ItemStack.java b/src/main/java/net/minestom/server/item/ItemStack.java index b5d6a0a80..a67d350f3 100644 --- a/src/main/java/net/minestom/server/item/ItemStack.java +++ b/src/main/java/net/minestom/server/item/ItemStack.java @@ -203,11 +203,6 @@ public final class ItemStack implements TagReadable, HoverEventSource tag) { - return meta.hasTag(tag); - } - @Override public @NotNull HoverEvent asHoverEvent(@NotNull UnaryOperator op) { return HoverEvent.showItem(op.apply(HoverEvent.ShowItem.of(this.material, diff --git a/src/main/java/net/minestom/server/tag/Tag.java b/src/main/java/net/minestom/server/tag/Tag.java index 80652cbac..641952cbe 100644 --- a/src/main/java/net/minestom/server/tag/Tag.java +++ b/src/main/java/net/minestom/server/tag/Tag.java @@ -212,4 +212,12 @@ public class Tag { nbtCompound -> serializer.read(TagReadable.fromCompound(nbtCompound)), (nbtCompound, value) -> serializer.write(TagWritable.fromCompound(nbtCompound), value)); } + + /** + * @deprecated use {@link #Structure(String, TagSerializer)} instead + */ + @Deprecated + public static @NotNull Tag Custom(@NotNull String key, @NotNull TagSerializer serializer) { + return Structure(key, serializer); + } } diff --git a/src/main/java/net/minestom/server/tag/TagReadable.java b/src/main/java/net/minestom/server/tag/TagReadable.java index b75d582ea..06a4a9cd2 100644 --- a/src/main/java/net/minestom/server/tag/TagReadable.java +++ b/src/main/java/net/minestom/server/tag/TagReadable.java @@ -40,11 +40,6 @@ public interface TagReadable { public @Nullable T getTag(@NotNull Tag tag) { return tag.read(compound); } - - @Override - public boolean hasTag(@NotNull Tag tag) { - return compound.containsKey(tag.getKey()); - } }; } }