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 private final boolean requireAbsolute; 031 032 public PlotSpecificPlaceholder(final @NonNull String key) { 033 this(key, false); 034 } 035 036 /** 037 * Create a functional placeholder 038 * 039 * @param key Placeholder key 040 * @param requireAbsolute If the plot given to the placeholder should be the absolute (not base) plot 041 * @since 7.5.9 042 */ 043 public PlotSpecificPlaceholder(final @NonNull String key, final boolean requireAbsolute) { 044 super(key); 045 this.requireAbsolute = requireAbsolute; 046 } 047 048 @Override 049 public @NonNull 050 final String getValue(final @NonNull PlotPlayer<?> player) { 051 final Plot plot = requireAbsolute ? player.getLocation().getPlotAbs() : player.getCurrentPlot(); 052 if (plot == null) { 053 return ""; 054 } 055 return this.getValue(player, plot); 056 } 057 058 /** 059 * Get the value of the placeholder for the {@link PlotPlayer player} in a specific {@link Plot plot} 060 * 061 * @param player Player that the placeholder is evaluated for 062 * @param plot Plot that the player is in 063 * @return Placeholder value, or {@code ""} if the placeholder does not apply 064 */ 065 public @NonNull 066 abstract String getValue( 067 final @NonNull PlotPlayer<?> player, 068 final @NonNull Plot plot 069 ); 070 071}