mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 05:17:05 +02:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
9377129554 | ||
|
f4409a6d92 | ||
|
c902485718 | ||
|
09db82a840 | ||
|
9b667fe383 | ||
|
00333f9a4e | ||
|
5472be631c | ||
|
68fa793354 | ||
|
111f5462fc | ||
|
62e282cc0e | ||
|
5aaa9720c8 | ||
|
9a2fb89e43 | ||
|
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.2</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,20 @@ 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, () -> {
|
||||
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.forEach(PlaceholderAPI::registerPlaceholderHook);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
@@ -141,13 +154,13 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
getServer().getScheduler().runTaskLater(this, this::checkHook, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager.clean();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
@@ -156,7 +169,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
expansionManager.clean();
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
@@ -171,6 +183,24 @@ 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().severe(((EZPlaceholderHook) h).getPluginName() + " is currently using a deprecated method to hook into PlaceholderAPI. Placeholders for that plugin no longer work. " +
|
||||
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
|
||||
// disable the hook on startup
|
||||
PlaceholderAPI.unregisterPlaceholderHook(((EZPlaceholderHook) h).getPlaceholderName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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,37 @@
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when the server is first loaded
|
||||
*
|
||||
* The goal of the method is to register all the expansions as soon as possible
|
||||
* especially before players can join
|
||||
*
|
||||
* This will ensure no issues with expanions and hooks.
|
||||
* @param e the server load event
|
||||
*/
|
||||
@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.forEach(PlaceholderAPI::registerPlaceholderHook);
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,13 +20,6 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
import static me.clip.placeholderapi.util.Msg.msg;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
@@ -37,6 +30,14 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
import static me.clip.placeholderapi.util.Msg.msg;
|
||||
|
||||
public class ExpansionCloudCommands implements CommandExecutor {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
@@ -327,7 +328,7 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
int i = 1;
|
||||
int i = (int) ex.keySet().toArray()[0]+1;
|
||||
for (String name : ce) {
|
||||
if (expansions.get(name) == null) {
|
||||
continue;
|
||||
|
@@ -49,7 +49,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
||||
if (args.length == 0) {
|
||||
|
||||
Msg.msg(s, "PlaceholderAPI &7version &b&o" + plugin.getDescription().getVersion(),
|
||||
"&fCreated by&7: &bextended_clip",
|
||||
"&fCreated by&7: &b" + plugin.getDescription().getAuthors(),
|
||||
"&fPapi commands: &b/papi help",
|
||||
"&fEcloud commands: &b/papi ecloud");
|
||||
return true;
|
||||
|
@@ -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()) {
|
||||
|
@@ -27,9 +27,7 @@ public class TimeUtil {
|
||||
if (seconds < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
return "0";
|
||||
case SECONDS:
|
||||
@@ -44,7 +42,6 @@ public class TimeUtil {
|
||||
if (minutes < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
@@ -118,9 +115,9 @@ public class TimeUtil {
|
||||
int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
if (secondsLeft > 0) {
|
||||
return String.valueOf(minutes + "m " + secondsLeft + "s");
|
||||
return minutes + "m " + secondsLeft + "s";
|
||||
} else {
|
||||
return String.valueOf(minutes + "m");
|
||||
return minutes + "m";
|
||||
}
|
||||
}
|
||||
if (minutes < 1440) {
|
||||
|
@@ -1,10 +1,8 @@
|
||||
name: ${project.name}
|
||||
main: me.clip.placeholderapi.PlaceholderAPIPlugin
|
||||
version: ${project.version}
|
||||
author: [extended_clip]
|
||||
authors: [extended_clip, Glare]
|
||||
description: ${project.description}
|
||||
api-version: 1.13
|
||||
load: STARTUP
|
||||
permissions:
|
||||
placeholderapi.*:
|
||||
description: ability to use all commands
|
||||
@@ -40,4 +38,4 @@ permissions:
|
||||
commands:
|
||||
placeholderapi:
|
||||
description: PlaceholderAPI command
|
||||
aliases: [clipsplaceholderapi, papi]
|
||||
aliases: [papi]
|
||||
|
Reference in New Issue
Block a user