player = BukkitUtil.getPlayer(placeholderReplaceEvent.getPlayer());
+ if (player == null) {
+ return "";
+ }
+ String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
+ return registry.getPlaceholderValue(key, player);
+ });
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java
new file mode 100644
index 000000000..52d30d5ed
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java
@@ -0,0 +1,89 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.placeholder;
+
+import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.player.PlotPlayer;
+import me.clip.placeholderapi.PlaceholderAPIPlugin;
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+import org.bukkit.entity.Player;
+
+public class PAPIPlaceholders extends PlaceholderExpansion {
+
+ public PAPIPlaceholders() {
+ }
+
+ @Override public boolean persist() {
+ return true;
+ }
+
+ @Override public boolean canRegister() {
+ return true;
+ }
+
+ @Override public String getAuthor() {
+ return "IntellectualSites";
+ }
+
+ @Override public String getIdentifier() {
+ return "plotsquared";
+ }
+
+ @Override public String getVersion() {
+ return "3";
+ }
+
+ @Override public String onPlaceholderRequest(Player p, String identifier) {
+ final PlotPlayer> pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
+
+ if (pl == null) {
+ return "";
+ }
+
+ // PAPI specific ones that don't translate well over into other placeholder APIs
+ if (identifier.startsWith("has_plot_")) {
+ identifier = identifier.substring("has_plot_".length());
+ if (identifier.isEmpty())
+ return "";
+
+ return pl.getPlotCount(identifier) > 0 ?
+ PlaceholderAPIPlugin.booleanTrue() :
+ PlaceholderAPIPlugin.booleanFalse();
+ }
+
+ if (identifier.startsWith("plot_count_")) {
+ identifier = identifier.substring("plot_count_".length());
+ if (identifier.isEmpty())
+ return "";
+
+ return String.valueOf(pl.getPlotCount(identifier));
+ }
+
+ // PlotSquared placeholders
+ return PlotSquared.get().getPlaceholderRegistry().getPlaceholderValue(identifier, pl);
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
deleted file mode 100644
index c61b29f37..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * _____ _ _ _____ _
- * | __ \| | | | / ____| | |
- * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
- * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
- * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
- * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
- * | |
- * |_|
- * PlotSquared plot management system for Minecraft
- * Copyright (C) 2020 IntellectualSites
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.plotsquared.bukkit.placeholder;
-
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.player.PlotPlayer;
-import com.plotsquared.core.plot.Plot;
-import com.plotsquared.core.plot.flag.GlobalFlagContainer;
-import com.plotsquared.core.plot.flag.PlotFlag;
-import com.plotsquared.core.util.MainUtil;
-import me.clip.placeholderapi.PlaceholderAPIPlugin;
-import me.clip.placeholderapi.expansion.PlaceholderExpansion;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-
-import java.util.UUID;
-
-public class Placeholders extends PlaceholderExpansion {
-
- public Placeholders() {
- }
-
- @Override public boolean persist() {
- return true;
- }
-
- @Override public boolean canRegister() {
- return true;
- }
-
- @Override public String getAuthor() {
- return "NotMyFault";
- }
-
- @Override public String getIdentifier() {
- return "plotsquared";
- }
-
- @Override public String getVersion() {
- return "2.5";
- }
-
- @Override public String onPlaceholderRequest(Player p, String identifier) {
- final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
-
- if (pl == null) {
- return "";
- }
-
- if (identifier.startsWith("has_plot_")) {
- identifier = identifier.substring("has_plot_".length());
- if (identifier.isEmpty())
- return "";
-
- return pl.getPlotCount(identifier) > 0 ?
- PlaceholderAPIPlugin.booleanTrue() :
- PlaceholderAPIPlugin.booleanFalse();
- }
-
- if (identifier.startsWith("plot_count_")) {
- identifier = identifier.substring("plot_count_".length());
- if (identifier.isEmpty())
- return "";
-
- return String.valueOf(pl.getPlotCount(identifier));
- }
-
- switch (identifier) {
- case "currentplot_world": {
- return p.getWorld().getName();
- }
- case "has_plot": {
- return (pl.getPlotCount() > 0) ?
- PlaceholderAPIPlugin.booleanTrue() :
- PlaceholderAPIPlugin.booleanFalse();
- }
- case "allowed_plot_count": {
- return String.valueOf(pl.getAllowedPlots());
- }
- case "plot_count": {
- return String.valueOf(pl.getPlotCount());
- }
- }
-
- Plot plot = pl.getCurrentPlot();
-
- if (plot == null) {
- return "";
- }
-
- switch (identifier) {
- case "currentplot_alias": {
- return plot.getAlias();
- }
- case "currentplot_owner": {
- final UUID plotOwner = plot.getOwnerAbs();
- if (plotOwner == null) {
- return "";
- }
-
- try {
- return MainUtil.getName(plotOwner, false);
- } catch (final Exception ignored) {}
-
- final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
- return name != null ? name : "unknown";
- }
- case "currentplot_members": {
- if (plot.getMembers() == null && plot.getTrusted() == null) {
- return "0";
- }
- return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
- }
- case "currentplot_members_added": {
- if (plot.getMembers() == null) {
- return "0";
- }
- return String.valueOf(plot.getMembers().size());
- }
- case "currentplot_members_trusted": {
- if (plot.getTrusted() == null) {
- return "0";
- }
- return String.valueOf(plot.getTrusted().size());
- }
- case "currentplot_members_denied": {
- if (plot.getDenied() == null) {
- return "0";
- }
- return String.valueOf(plot.getDenied().size());
- }
- case "has_build_rights": {
- return plot.isAdded(pl.getUUID()) ?
- PlaceholderAPIPlugin.booleanTrue() :
- PlaceholderAPIPlugin.booleanFalse();
- }
- case "currentplot_x": {
- return String.valueOf(plot.getId().getX());
- }
- case "currentplot_y": {
- return String.valueOf(plot.getId().getY());
- }
- case "currentplot_xy": {
- return plot.getId().getX() + ";" + plot.getId().getY();
- }
- case "currentplot_rating": {
- return String.valueOf(plot.getAverageRating());
- }
- case "currentplot_biome": {
- return plot.getBiomeSynchronous() + "";
- }
- default:
- break;
- }
- if (identifier.startsWith("currentplot_localflag_")) {
- return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
- false);
- }
- if (identifier.startsWith("currentplot_flag_")) {
- return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
- }
- return "";
- }
-
- /**
- * Return the flag value from its name on the current plot.
- * If the flag doesn't exist it returns an empty string.
- * If the flag exists but it is not set on current plot and the parameter inherit is set to true,
- * it returns the default value.
- *
- * @param plot Current plot where the player is
- * @param flagName Name of flag to get from current plot
- * @param inherit Define if it returns only the flag set on currentplot or also inherited flag
- * @return The value of flag serialized in string
- */
- private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
- if (flagName.isEmpty())
- return "";
- final PlotFlag, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
- if (flag == null)
- return "";
-
- if (inherit) {
- return plot.getFlag(flag).toString();
- } else {
- final PlotFlag, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
- return (plotFlag != null) ? plotFlag.getValue().toString() : "";
- }
- }
-}
diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml
index 41967220c..2dd7edbac 100644
--- a/Bukkit/src/main/resources/plugin.yml
+++ b/Bukkit/src/main/resources/plugin.yml
@@ -6,7 +6,7 @@ load: STARTUP
description: "Easy, yet powerful Plot World generation and management."
authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell]
website: https://www.spigotmc.org/resources/77506/
-softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms]
+softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms, MVdWPlaceholderAPI]
loadbefore: [MultiWorld, Multiverse-Core]
depend: [WorldEdit]
database: false
diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java
index d88d7ccb9..190457ef3 100644
--- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java
+++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java
@@ -270,6 +270,11 @@ public interface IPlotMain extends ILogger {
*/
void registerWorldEvents();
+ /**
+ * Register events related to the server
+ */
+ void registerServerEvents();
+
/**
* Usually HybridGen
*
diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
index 3e0e0443b..1cab0ba4c 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
@@ -62,6 +62,7 @@ import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.ExpiryTask;
+import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
@@ -82,6 +83,7 @@ import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
+import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDPipeline;
@@ -171,6 +173,7 @@ public class PlotSquared {
private File storageFile;
@Getter private PlotAreaManager plotAreaManager;
@Getter private EventDispatcher eventDispatcher;
+ @Getter private PlaceholderRegistry placeholderRegistry;
/**
* Initialize PlotSquared with the desired Implementation class.
@@ -194,6 +197,9 @@ public class PlotSquared {
//
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
+ // Setup the global flag container
+ GlobalFlagContainer.setup();
+
try {
new ReflectionUtils(this.IMP.getNMSPackage());
try {
@@ -209,6 +215,7 @@ public class PlotSquared {
"PlotSquared-" + platform + ".jar");
}
}
+
TaskManager.IMP = this.IMP.getTaskManager();
// World Util. Has to be done before config files are loaded
@@ -255,6 +262,7 @@ public class PlotSquared {
this.IMP.registerEvents();
}
// Required
+ this.IMP.registerServerEvents();
this.IMP.registerWorldEvents();
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.IMP.registerChunkProcessor();
@@ -262,6 +270,8 @@ public class PlotSquared {
startExpiryTasks();
// Create Event utility class
eventDispatcher = new EventDispatcher();
+ // Create placeholder registry
+ placeholderRegistry = new PlaceholderRegistry(eventDispatcher);
// create Hybrid utility class
HybridUtils.manager = this.IMP.initHybridUtils();
// Inventory utility class
diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
index 2adca5334..ac1766e93 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -2256,7 +2256,7 @@ public class Plot {
*
* @return The plot alias
*/
- public String getAlias() {
+ @NotNull public String getAlias() {
if (this.settings == null) {
return "";
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java
index 4d7fdd396..3c44a8b5a 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java
@@ -25,6 +25,7 @@
*/
package com.plotsquared.core.plot.flag;
+import com.google.common.base.Preconditions;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag;
import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag;
@@ -114,7 +115,13 @@ import java.util.Map;
public final class GlobalFlagContainer extends FlagContainer {
- @Getter private static final GlobalFlagContainer instance = new GlobalFlagContainer();
+ @Getter private static GlobalFlagContainer instance;
+
+ public static void setup() {
+ Preconditions.checkState(instance == null, "Cannot setup the container twice");
+ instance = new GlobalFlagContainer();
+ }
+
private static Map> stringClassMap;
private GlobalFlagContainer() {
@@ -124,6 +131,7 @@ public final class GlobalFlagContainer extends FlagContainer {
}
});
stringClassMap = new HashMap<>();
+
// Register all default flags here
// Boolean flags
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
diff --git a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java
index cb554b754..23d5dd15f 100644
--- a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java
+++ b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java
@@ -80,9 +80,9 @@ import java.util.UUID;
public class EventDispatcher {
- private EventBus eventBus = new EventBus("PlotSquaredEvents");
+ private final EventBus eventBus = new EventBus("PlotSquaredEvents");
- private List