mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-27 17:28:28 +01:00
Get placeholders working
This commit is contained in:
parent
e8c155763b
commit
2d9cf8b759
@ -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();
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -270,6 +270,11 @@ public interface IPlotMain<P> extends ILogger {
|
||||
*/
|
||||
void registerWorldEvents();
|
||||
|
||||
/**
|
||||
* Register events related to the server
|
||||
*/
|
||||
void registerServerEvents();
|
||||
|
||||
/**
|
||||
* Usually HybridGen
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user