org.spongepowered.api.placeholder.PlaceholderContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spongeapi Show documentation
Show all versions of spongeapi Show documentation
A plugin API for Minecraft: Java Edition
The newest version!
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.placeholder;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;
/**
* Contains the context that a {@link PlaceholderParser} can use to determine
* what to display.
*/
public interface PlaceholderContext {
/**
* Creates a {@link PlaceholderContext} for a {@link PlaceholderParser} to
* consume.
*
* @return The builder.
*/
static Builder builder() {
return Sponge.game().builderProvider().provide(Builder.class);
}
/**
* If provided, the {@link Object} which to pull information from
* when building the placeholder text.
*
* Examples of how this might affect a placeholder are:
*
*
* -
* For a "name" placeholder that prints out the source's name,
* the name would be selected from this source.
*
* -
* For a "current world" placeholder that returns a player's current
* world, this would pull the name of that current world from the
* player.
*
*
*
* It is important to note that the associated context does not
* necessarily have to be the sender/invoker of a message, nor does it
* have to be the recipient. The source is selected by the context of
* builder. It is up to plugins that use such placeholders to be aware
* of the context of which the placeholder is used.
* {@link PlaceholderParser}s should make no assumption about the origin of
* the context.
*
* If an invalid {@link Object} is provided for the context
* of the placeholder, then the associated {@link PlaceholderParser} must
* return a {@link Component#empty()}.
*
* @return The associated {@link Object}, if any.
*/
Optional