diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 5ee38078c..fc3689dcd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -31,12 +31,12 @@ import com.plotsquared.bukkit.listener.ChunkListener; import com.plotsquared.bukkit.listener.EntitySpawnListener; import com.plotsquared.bukkit.listener.PaperListener; import com.plotsquared.bukkit.listener.PlayerEvents; +import com.plotsquared.bukkit.listener.ServerListener; import com.plotsquared.bukkit.listener.SingleWorldListener; import com.plotsquared.bukkit.listener.WorldEvents; import com.plotsquared.bukkit.managers.BukkitWorldManager; import com.plotsquared.bukkit.managers.HyperverseWorldManager; import com.plotsquared.bukkit.managers.MultiverseWorldManager; -import com.plotsquared.bukkit.placeholder.MVdWPlaceholders; import com.plotsquared.bukkit.placeholder.PlaceholderFormatter; import com.plotsquared.bukkit.placeholder.PAPIPlaceholders; import com.plotsquared.bukkit.player.BukkitPlayerManager; @@ -371,11 +371,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI"); } - if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null) { - new MVdWPlaceholders(this, PlotSquared.get().getPlaceholderRegistry()); - PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into MVdWPlaceholderAPI"); - } - this.startMetrics(); if (Settings.Enabled_Components.WORLDS) { TaskManager.IMP.taskRepeat(this::unload, 20); @@ -1052,6 +1047,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< getServer().getPluginManager().registerEvents(new WorldEvents(), this); } + @Override + public void registerServerEvents() { + getServer().getPluginManager().registerEvents(new ServerListener(this), this); + } + @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { return new HybridGen(); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ServerListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ServerListener.java new file mode 100644 index 000000000..c6f8b072e --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ServerListener.java @@ -0,0 +1,29 @@ +package com.plotsquared.bukkit.listener; + +import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.placeholder.MVdWPlaceholders; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.Captions; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; + +public class ServerListener implements Listener { + + private final BukkitMain plugin; + + public ServerListener(BukkitMain plugin) { + this.plugin = plugin; + } + + @EventHandler public void onServerLoad(ServerLoadEvent event) { + if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null) { + new MVdWPlaceholders(this.plugin, PlotSquared.get().getPlaceholderRegistry()); + PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into MVdWPlaceholderAPI"); + } else { + System.out.println("Nope"); + } + + } +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java index 5bd835de0..599a1122b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java @@ -41,6 +41,7 @@ import org.jetbrains.annotations.NotNull; */ public class MVdWPlaceholders { + private static final String PREFIX = "plotsquared_"; private final Plugin plugin; private final PlaceholderRegistry registry; @@ -60,7 +61,7 @@ public class MVdWPlaceholders { } private void addPlaceholder(@NotNull final Placeholder placeholder) { - PlaceholderAPI.registerPlaceholder(plugin, String.format("plotsquared_%s", placeholder.getKey()), + PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), placeholderReplaceEvent -> { if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) { return ""; @@ -69,7 +70,8 @@ public class MVdWPlaceholders { if (player == null) { return ""; } - return registry.getPlaceholderValue(placeholderReplaceEvent.getPlaceholder(), player); + String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length()); + return registry.getPlaceholderValue(key, player); }); } diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java index a38045acb..5dcc6d5a1 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 3451b0a1c..f1287dbcb 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -262,6 +262,7 @@ public class PlotSquared { this.IMP.registerPlayerEvents(); } // Required + this.IMP.registerServerEvents(); this.IMP.registerWorldEvents(); if (Settings.Enabled_Components.CHUNK_PROCESSOR) { this.IMP.registerChunkProcessor(); diff --git a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java index 243ca0909..d18859b2e 100644 --- a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java +++ b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java @@ -159,7 +159,7 @@ public final class PlaceholderRegistry { final Placeholder previous = this.placeholders .put(placeholder.getKey().toLowerCase(Locale.ENGLISH), Preconditions.checkNotNull(placeholder, "Placeholder may not be null")); - if (previous != null) { + if (previous == null) { this.eventDispatcher.callGenericEvent(new PlaceholderAddedEvent(placeholder)); } }