mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 05:17:05 +02:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fc1a2af011 | ||
|
82e92ce777 | ||
|
9b317c2210 | ||
|
927f942236 | ||
|
75c3027e05 | ||
|
a2d408aea9 | ||
|
5386b7c23d | ||
|
a741f35139 | ||
|
1e25f35aac | ||
|
3042e49ddb | ||
|
6495a386a0 | ||
|
cee214cc98 | ||
|
41390d8ef4 | ||
|
c0f6cf225f | ||
|
16d0a4f690 | ||
|
8f600aec25 |
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
|
||||
<version>2.10.0</version>
|
||||
<version>2.10.1</version>
|
||||
<name>PlaceholderAPI</name>
|
||||
<description>An awesome placeholder provider!</description>
|
||||
<url>http://extendedclip.com</url>
|
||||
|
@@ -30,6 +30,7 @@ import me.clip.placeholderapi.expansion.ExpansionManager;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Version;
|
||||
import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager;
|
||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||
import me.clip.placeholderapi.updatechecker.UpdateChecker;
|
||||
import me.clip.placeholderapi.util.TimeUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -132,8 +133,23 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
setupOptions();
|
||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||
new PlaceholderListener(this);
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
expansionManager.registerAllExpansions();
|
||||
try {
|
||||
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
||||
new ServerLoadEventListener(this);
|
||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
//fetch any hooks that may have registered externally onEnable first otherwise they will be lost
|
||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||
getExpansionManager().registerAllExpansions();
|
||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||
alreadyRegistered.entrySet().stream().forEach(hook -> PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue()));
|
||||
}
|
||||
}
|
||||
}, 20*15);
|
||||
}
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
@@ -141,13 +157,13 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
getServer().getScheduler().runTaskLater(this, this::checkHook, 20 * 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager.clean();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
@@ -156,7 +172,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
expansionManager.clean();
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
@@ -171,6 +186,22 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
+ " &aplaceholder hooks successfully registered!"));
|
||||
}
|
||||
|
||||
private void checkHook() {
|
||||
Map<String, PlaceholderHook> loaded = PlaceholderAPI.getPlaceholders();
|
||||
loaded.values().forEach(h -> {
|
||||
if (h instanceof EZPlaceholderHook) {
|
||||
String author;
|
||||
try {
|
||||
author = Bukkit.getPluginManager().getPlugin(((EZPlaceholderHook) h).getPluginName()).getDescription().getAuthors().toString();
|
||||
} catch (Exception ex) {
|
||||
author = "the author of the hook's plugin";
|
||||
}
|
||||
getLogger().warning(((EZPlaceholderHook) h).getPluginName() + " is currently using a deprecated method to hook into PlaceholderAPI. This will be disabled after the next update. " +
|
||||
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupOptions() {
|
||||
booleanTrue = config.booleanTrue();
|
||||
if (booleanTrue == null) {
|
||||
|
@@ -26,11 +26,9 @@ import java.util.Set;
|
||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||
import me.clip.placeholderapi.expansion.Cacheable;
|
||||
import me.clip.placeholderapi.expansion.Cleanable;
|
||||
import me.clip.placeholderapi.expansion.ExpansionManager;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Taskable;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -38,7 +36,6 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
|
||||
public class PlaceholderListener implements Listener {
|
||||
@@ -77,17 +74,6 @@ public class PlaceholderListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEnable(PluginEnableEvent event) {
|
||||
ExpansionManager m = plugin.getExpansionManager();
|
||||
PlaceholderExpansion e = m.getCachedExpansion(event.getPlugin().getName().toLowerCase());
|
||||
if (e != null && e.canRegister()) {
|
||||
if (e.isRegistered() || m.registerExpansion(e)) {
|
||||
m.removeCachedExpansion(e.getRequiredPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPluginUnload(PluginDisableEvent e) {
|
||||
|
||||
@@ -107,22 +93,7 @@ public class PlaceholderListener implements Listener {
|
||||
|
||||
PlaceholderHook i = hook.getValue();
|
||||
|
||||
if (i instanceof EZPlaceholderHook) {
|
||||
|
||||
EZPlaceholderHook h = (EZPlaceholderHook) i;
|
||||
|
||||
if (h.getPluginName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (h.getPluginName().equalsIgnoreCase(n)) {
|
||||
if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) {
|
||||
plugin.getLogger()
|
||||
.info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (i instanceof PlaceholderExpansion) {
|
||||
if (i instanceof PlaceholderExpansion) {
|
||||
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) i;
|
||||
|
||||
|
@@ -0,0 +1,29 @@
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class ServerLoadEventListener implements Listener {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public ServerLoadEventListener(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
Bukkit.getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent e) {
|
||||
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||
plugin.getExpansionManager().registerAllExpansions();
|
||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||
alreadyRegistered.entrySet().stream().forEach(hook -> {
|
||||
PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,6 @@ package me.clip.placeholderapi.expansion;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -36,8 +35,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public final class ExpansionManager {
|
||||
|
||||
private final Map<String, PlaceholderExpansion> cache = new HashMap<>();
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
||||
@@ -48,18 +45,6 @@ public final class ExpansionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getCachedExpansion(String plugin) {
|
||||
return cache.getOrDefault(plugin, null);
|
||||
}
|
||||
|
||||
public boolean removeCachedExpansion(String identifier) {
|
||||
return cache.remove(identifier) != null;
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getRegisteredExpansion(String name) {
|
||||
for (Entry<String, PlaceholderHook> hook : PlaceholderAPI.getPlaceholders().entrySet()) {
|
||||
if (hook.getValue() instanceof PlaceholderExpansion) {
|
||||
@@ -112,9 +97,6 @@ public final class ExpansionManager {
|
||||
}
|
||||
}
|
||||
if (!expansion.canRegister()) {
|
||||
if (expansion.getRequiredPlugin() != null) {
|
||||
cache.put(expansion.getRequiredPlugin().toLowerCase(), expansion);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!expansion.register()) {
|
||||
|
@@ -4,7 +4,6 @@ version: ${project.version}
|
||||
author: [extended_clip]
|
||||
description: ${project.description}
|
||||
api-version: 1.13
|
||||
load: STARTUP
|
||||
permissions:
|
||||
placeholderapi.*:
|
||||
description: ability to use all commands
|
||||
|
Reference in New Issue
Block a user