net.minestom.server.registry.ObjectSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.registry;
import net.minestom.server.gamedata.tags.Tag;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.nbt.BinaryTagSerializer;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Set;
/**
* A set of some protocol objects. May contain a single element, multiple elements, or a single tag (which itself contains multiple elements).
*
* @param The type of protocol object represented by this set.
*/
public sealed interface ObjectSet permits ObjectSetImpl {
static @NotNull ObjectSet empty() {
//noinspection unchecked
return (ObjectSet) ObjectSetImpl.Empty.INSTANCE;
}
static @NotNull ObjectSet of(@NotNull Collection entries) {
return new ObjectSetImpl.Entries<>(Set.copyOf(entries));
}
static @NotNull ObjectSet of(@NotNull Tag tag) {
return new ObjectSetImpl.Tag<>(tag);
}
static @NotNull BinaryTagSerializer> nbtType(@NotNull Tag.BasicType tagType) {
return new ObjectSetImpl.NbtType<>(tagType);
}
/**
* Check if this set contains the given object, tested against its namespace id.
*
* Present for compatibility with non-dynamic registries. Will be removed in the future.
*
* @param object The object to check for.
* @return True if this set contains the object, false otherwise.
*/
default boolean contains(@NotNull StaticProtocolObject object) {
return contains(object.namespace());
}
default boolean contains(@NotNull DynamicRegistry.Key key) {
return contains(key.namespace());
}
boolean contains(@NotNull NamespaceID namespace);
}