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.bukkit.placeholder; 020 021import com.plotsquared.core.PlotSquared; 022import com.plotsquared.core.player.PlotPlayer; 023import me.clip.placeholderapi.PlaceholderAPIPlugin; 024import me.clip.placeholderapi.expansion.PlaceholderExpansion; 025import org.bukkit.entity.Player; 026 027public class PAPIPlaceholders extends PlaceholderExpansion { 028 029 public PAPIPlaceholders() { 030 } 031 032 @Override 033 public boolean persist() { 034 return true; 035 } 036 037 @Override 038 public boolean canRegister() { 039 return true; 040 } 041 042 @Override 043 public String getAuthor() { 044 return "IntellectualSites"; 045 } 046 047 @Override 048 public String getIdentifier() { 049 return "plotsquared"; 050 } 051 052 @Override 053 public String getVersion() { 054 return "3"; 055 } 056 057 @Override 058 public String onPlaceholderRequest(Player p, String identifier) { 059 final PlotPlayer<?> pl = PlotSquared.platform().playerManager().getPlayerIfExists(p.getUniqueId()); 060 061 if (pl == null) { 062 return ""; 063 } 064 065 // PAPI specific ones that don't translate well over into other placeholder APIs 066 if (identifier.startsWith("has_plot_")) { 067 identifier = identifier.substring("has_plot_".length()); 068 if (identifier.isEmpty()) { 069 return ""; 070 } 071 072 return pl.getPlotCount(identifier) > 0 ? 073 PlaceholderAPIPlugin.booleanTrue() : 074 PlaceholderAPIPlugin.booleanFalse(); 075 } 076 077 if (identifier.startsWith("plot_count_")) { 078 identifier = identifier.substring("plot_count_".length()); 079 if (identifier.isEmpty()) { 080 return ""; 081 } 082 083 return String.valueOf(pl.getPlotCount(identifier)); 084 } 085 086 // PlotSquared placeholders 087 return PlotSquared.platform().placeholderRegistry().getPlaceholderValue(identifier, pl); 088 } 089 090}