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

net.minestom.server.adventure.ComponentHolder Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.adventure;

import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

/**
 * Represents an object that holds some amount of components.
 *
 * @param  the holding class
 */
public interface ComponentHolder {

    /**
     * Gets the components held by this object.
     *
     * @return the components
     */
    @NotNull Collection components();

    /**
     * Returns a copy of this object. For each component this object holds, the operator
     * is applied to the copy before returning.
     *
     * @param operator the operator
     * @return the copy
     */
    @NotNull T copyWithOperator(@NotNull UnaryOperator operator);

    /**
     * Visits each component held by this object.
     *
     * @param visitor the visitor
     */
    default void visitComponents(@NotNull Consumer visitor) {
        for (Component component : this.components()) {
            visitor.accept(component);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy