001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.configuration.caption; 020 021import net.kyori.adventure.text.Component; 022import net.kyori.adventure.text.event.ClickEvent; 023import org.checkerframework.checker.nullness.qual.NonNull; 024 025import java.util.Set; 026 027public interface ComponentTransform { 028 029 /** 030 * Creates a transform that applies the given transform on all child components and the 031 * component itself. The children are transformed before the component itself is transformed. 032 * 033 * @param transform the transform to apply. 034 * @return a new transform which is applied on all child components and the component itself. 035 * @since 6.0.10 036 */ 037 static ComponentTransform nested(ComponentTransform transform) { 038 return new NestedComponentTransform(transform); 039 } 040 041 /** 042 * Creates a transform that removes click events of the given actions from a component. 043 * Note: To remove click events from children too, the returned transform must be wrapped 044 * using {@link #nested(ComponentTransform)}. 045 * 046 * @param actionsToRemove the actions used to filter which click events should be removed. 047 * @return a new transform that removes click events from a component. 048 * @since 6.0.10 049 */ 050 static ComponentTransform stripClicks(ClickEvent.Action... actionsToRemove) { 051 return new ClickStripTransform(Set.of(actionsToRemove)); 052 } 053 054 /** 055 * Applies this transform on the given component and returns the result. 056 * 057 * @param original the component to transform. 058 * @return the transformed component. 059 * @since 6.0.10 060 */ 061 @NonNull Component transform(@NonNull Component original); 062 063}