Merge branch 'master' into new-block-api

# Conflicts:
#	src/main/java/net/minestom/server/tag/Tag.java
This commit is contained in:
TheMode 2021-06-22 03:09:02 +02:00
commit 2b817e5590
6 changed files with 26 additions and 16 deletions

View File

@ -6,7 +6,10 @@ import org.jetbrains.annotations.Nullable;
* Represents an element which can have a {@link Data} attached to it.
* <p>
* The data will always be optional and can therefore be null.
*
* @deprecated switch to the Tag API instead
*/
@Deprecated
public interface DataContainer {
/**

View File

@ -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;
* <p>
* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead.
*/
public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, DataContainer, PermissionHandler, HoverEventSource<ShowEntity>, Sound.Emitter {
public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, DataContainer, TagHandler, PermissionHandler, HoverEventSource<ShowEntity>, Sound.Emitter {
private static final Map<Integer, Entity> ENTITY_BY_ID = new ConcurrentHashMap<>();
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();
@ -103,6 +106,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
protected final Set<Player> viewers = ConcurrentHashMap.newKeySet();
private final Set<Player> unmodifiableViewers = Collections.unmodifiableSet(viewers);
private Data data;
private final NBTCompound nbtCompound = new NBTCompound();
private final Set<Permission> permissions = new CopyOnWriteArraySet<>();
protected UUID uuid;
@ -1610,6 +1614,16 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
return (Acquirable<T>) acquirable;
}
@Override
public <T> @Nullable T getTag(@NotNull Tag<T> tag) {
return tag.read(nbtCompound);
}
@Override
public <T> void setTag(@NotNull Tag<T> tag, @Nullable T value) {
tag.write(nbtCompound, value);
}
public enum Pose {
STANDING,
FALL_FLYING,

View File

@ -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();
}

View File

@ -203,11 +203,6 @@ public final class ItemStack implements TagReadable, HoverEventSource<HoverEvent
return meta.getTag(tag);
}
@Override
public boolean hasTag(@NotNull Tag<?> tag) {
return meta.hasTag(tag);
}
@Override
public @NotNull HoverEvent<HoverEvent.ShowItem> asHoverEvent(@NotNull UnaryOperator<HoverEvent.ShowItem> op) {
return HoverEvent.showItem(op.apply(HoverEvent.ShowItem.of(this.material,

View File

@ -212,4 +212,12 @@ public class Tag<T> {
nbtCompound -> serializer.read(TagReadable.fromCompound(nbtCompound)),
(nbtCompound, value) -> serializer.write(TagWritable.fromCompound(nbtCompound), value));
}
/**
* @deprecated use {@link #Structure(String, TagSerializer)} instead
*/
@Deprecated
public static <T> @NotNull Tag<T> Custom(@NotNull String key, @NotNull TagSerializer<T> serializer) {
return Structure(key, serializer);
}
}

View File

@ -40,11 +40,6 @@ public interface TagReadable {
public <T> @Nullable T getTag(@NotNull Tag<T> tag) {
return tag.read(compound);
}
@Override
public boolean hasTag(@NotNull Tag<?> tag) {
return compound.containsKey(tag.getKey());
}
};
}
}