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.util.placeholders;
020
021import com.plotsquared.core.player.PlotPlayer;
022import com.plotsquared.core.plot.Plot;
023import org.checkerframework.checker.nullness.qual.NonNull;
024
025/**
026 * A {@link Placeholder placeholder} that requires a {@link com.plotsquared.core.plot.Plot plot}
027 */
028public abstract class PlotSpecificPlaceholder extends Placeholder {
029
030    public PlotSpecificPlaceholder(final @NonNull String key) {
031        super(key);
032    }
033
034    @Override
035    public @NonNull
036    final String getValue(final @NonNull PlotPlayer<?> player) {
037        final Plot plot = player.getCurrentPlot();
038        if (plot == null) {
039            return "";
040        }
041        return this.getValue(player, plot);
042    }
043
044    /**
045     * Get the value of the placeholder for the {@link PlotPlayer player} in a specific {@link Plot plot}
046     *
047     * @param player Player that the placeholder is evaluated for
048     * @param plot   Plot that the player is in
049     * @return Placeholder value, or {@code ""} if the placeholder does not apply
050     */
051    public @NonNull
052    abstract String getValue(
053            final @NonNull PlotPlayer<?> player,
054            final @NonNull Plot plot
055    );
056
057}