All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.registry.ObjectSet Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
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); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy