mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-02-05 15:55:28 +01:00
Reformatted project to conform to google style guide.
This commit is contained in:
parent
bc915af13e
commit
9cc5a9678f
12
placeholderapi.iml
Normal file
12
placeholderapi.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="minecraft" name="Minecraft">
|
||||||
|
<configuration>
|
||||||
|
<autoDetectTypes>
|
||||||
|
<platformType>SPIGOT</platformType>
|
||||||
|
</autoDetectTypes>
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
</module>
|
3
pom.xml
3
pom.xml
@ -1,4 +1,5 @@
|
|||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
|
@ -46,8 +46,10 @@ public class PlaceholderAPI {
|
|||||||
|
|
||||||
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
|
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
|
||||||
private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
|
private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
|
||||||
private static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern.compile("[%](rel_)([^%]+)[%]");
|
private static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern
|
||||||
|
.compile("[%](rel_)([^%]+)[%]");
|
||||||
private static final Map<String, PlaceholderHook> placeholders = new HashMap<>();
|
private static final Map<String, PlaceholderHook> placeholders = new HashMap<>();
|
||||||
|
|
||||||
private PlaceholderAPI() {
|
private PlaceholderAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,21 +376,21 @@ public class PlaceholderAPI {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String setPlaceholders(Player p, String text) {
|
public static String setPlaceholders(Player p, String text) {
|
||||||
return setPlaceholders((OfflinePlayer)p, text, PLACEHOLDER_PATTERN);
|
return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static List<String> setPlaceholders(Player p, List<String> text) {
|
public static List<String> setPlaceholders(Player p, List<String> text) {
|
||||||
return setPlaceholders((OfflinePlayer)p, text, PLACEHOLDER_PATTERN);
|
return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String setBracketPlaceholders(Player p, String text) {
|
public static String setBracketPlaceholders(Player p, String text) {
|
||||||
return setPlaceholders((OfflinePlayer)p, text, BRACKET_PLACEHOLDER_PATTERN);
|
return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static List<String> setBracketPlaceholders(Player p, List<String> text) {
|
public static List<String> setBracketPlaceholders(Player p, List<String> text) {
|
||||||
return setPlaceholders((OfflinePlayer)p, text, BRACKET_PLACEHOLDER_PATTERN);
|
return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi;
|
package me.clip.placeholderapi;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import me.clip.placeholderapi.commands.PlaceholderAPICommands;
|
import me.clip.placeholderapi.commands.PlaceholderAPICommands;
|
||||||
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
|
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
|
||||||
import me.clip.placeholderapi.expansion.ExpansionManager;
|
import me.clip.placeholderapi.expansion.ExpansionManager;
|
||||||
@ -34,38 +38,85 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Yes I have a shit load of work to do...
|
* Yes I have a shit load of work to do...
|
||||||
*
|
*
|
||||||
* @author Ryan McCarthy
|
* @author Ryan McCarthy
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlaceholderAPIPlugin extends JavaPlugin {
|
public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private static PlaceholderAPIPlugin instance;
|
private static PlaceholderAPIPlugin instance;
|
||||||
|
|
||||||
private PlaceholderAPIConfig config;
|
|
||||||
|
|
||||||
private ExpansionManager expansionManager;
|
|
||||||
|
|
||||||
private ExpansionCloudManager expansionCloud;
|
|
||||||
|
|
||||||
private static SimpleDateFormat dateFormat;
|
private static SimpleDateFormat dateFormat;
|
||||||
|
|
||||||
private static String booleanTrue;
|
private static String booleanTrue;
|
||||||
|
|
||||||
private static String booleanFalse;
|
private static String booleanFalse;
|
||||||
|
|
||||||
private static Version serverVersion;
|
private static Version serverVersion;
|
||||||
|
private PlaceholderAPIConfig config;
|
||||||
|
private ExpansionManager expansionManager;
|
||||||
|
private ExpansionCloudManager expansionCloud;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
|
private static Version getVersion() {
|
||||||
|
String v = "unknown";
|
||||||
|
boolean spigot = false;
|
||||||
|
try {
|
||||||
|
v = Bukkit.getServer().getClass().getPackage().getName()
|
||||||
|
.split("\\.")[3];
|
||||||
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName("org.spigotmc.SpigotConfig");
|
||||||
|
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
||||||
|
spigot = true;
|
||||||
|
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||||
|
}
|
||||||
|
return new Version(v, spigot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
|
||||||
|
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
|
||||||
|
* available from the class: {@link PlaceholderAPI}
|
||||||
|
*
|
||||||
|
* @return PlaceholderAPIPlugin instance
|
||||||
|
*/
|
||||||
|
public static PlaceholderAPIPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
|
||||||
|
* generic time based placeholders
|
||||||
|
*
|
||||||
|
* @return date format
|
||||||
|
*/
|
||||||
|
public static SimpleDateFormat getDateFormat() {
|
||||||
|
return dateFormat != null ? dateFormat : new SimpleDateFormat(
|
||||||
|
"MM/dd/yy HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
|
||||||
|
*
|
||||||
|
* @return string value of true
|
||||||
|
*/
|
||||||
|
public static String booleanTrue() {
|
||||||
|
return booleanTrue != null ? booleanTrue : "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
|
||||||
|
*
|
||||||
|
* @return string value of false
|
||||||
|
*/
|
||||||
|
public static String booleanFalse() {
|
||||||
|
return booleanFalse != null ? booleanFalse : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Version getServerVersion() {
|
||||||
|
return serverVersion != null ? serverVersion : getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
@ -115,7 +166,9 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
} else if (!cloudEnabled) {
|
} else if (!cloudEnabled) {
|
||||||
enableCloud();
|
enableCloud();
|
||||||
}
|
}
|
||||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!"));
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
PlaceholderAPI.getRegisteredIdentifiers().size()
|
||||||
|
+ " &aplaceholder hooks successfully registered!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupOptions() {
|
private void setupOptions() {
|
||||||
@ -136,9 +189,11 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private void setupMetrics() {
|
private void setupMetrics() {
|
||||||
Metrics m = new Metrics(this);
|
Metrics m = new Metrics(this);
|
||||||
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getExpansionCloud() != null ? "yes" : "no"));
|
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud",
|
||||||
|
() -> getExpansionCloud() != null ? "yes" : "no"));
|
||||||
|
|
||||||
m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
m.addCustomChart(
|
||||||
|
new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||||
|
|
||||||
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
||||||
Map<String, Integer> map = new HashMap<>();
|
Map<String, Integer> map = new HashMap<>();
|
||||||
@ -160,23 +215,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Version getVersion() {
|
|
||||||
String v = "unknown";
|
|
||||||
boolean spigot = false;
|
|
||||||
try {
|
|
||||||
v = Bukkit.getServer().getClass().getPackage().getName()
|
|
||||||
.split("\\.")[3];
|
|
||||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Class.forName("org.spigotmc.SpigotConfig");
|
|
||||||
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
|
||||||
spigot = true;
|
|
||||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
|
||||||
}
|
|
||||||
return new Version(v, spigot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableCloud() {
|
public void enableCloud() {
|
||||||
if (expansionCloud == null) {
|
if (expansionCloud == null) {
|
||||||
expansionCloud = new ExpansionCloudManager(this);
|
expansionCloud = new ExpansionCloudManager(this);
|
||||||
@ -194,53 +232,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the static instance of the main class for PlaceholderAPI. This class
|
|
||||||
* is not the actual API class, this is the main class that extends
|
|
||||||
* JavaPlugin. For most API methods, use static methods available from the
|
|
||||||
* class: {@link PlaceholderAPI}
|
|
||||||
*
|
|
||||||
* @return PlaceholderAPIPlugin instance
|
|
||||||
*/
|
|
||||||
public static PlaceholderAPIPlugin getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the configurable {@linkplain SimpleDateFormat} object that is used to
|
|
||||||
* parse time for generic time based placeholders
|
|
||||||
*
|
|
||||||
* @return date format
|
|
||||||
*/
|
|
||||||
public static SimpleDateFormat getDateFormat() {
|
|
||||||
return dateFormat != null ? dateFormat : new SimpleDateFormat(
|
|
||||||
"MM/dd/yy HH:mm:ss");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the configurable {@linkplain String} value that should be returned
|
|
||||||
* when a boolean is true
|
|
||||||
*
|
|
||||||
* @return string value of true
|
|
||||||
*/
|
|
||||||
public static String booleanTrue() {
|
|
||||||
return booleanTrue != null ? booleanTrue : "true";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the configurable {@linkplain String} value that should be returned
|
|
||||||
* when a boolean is false
|
|
||||||
*
|
|
||||||
* @return string value of false
|
|
||||||
*/
|
|
||||||
public static String booleanFalse() {
|
|
||||||
return booleanFalse != null ? booleanFalse : "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Version getServerVersion() {
|
|
||||||
return serverVersion != null ? serverVersion : getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the configuration class for PlaceholderAPI.
|
* Obtain the configuration class for PlaceholderAPI.
|
||||||
*
|
*
|
||||||
@ -259,7 +250,8 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getUptime() {
|
public String getUptime() {
|
||||||
return TimeUtil.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
return TimeUtil
|
||||||
|
.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUptimeMillis() {
|
public long getUptimeMillis() {
|
||||||
|
@ -27,7 +27,9 @@ public abstract class PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* called when a placeholder value is requested from this hook
|
* called when a placeholder value is requested from this hook
|
||||||
* @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a player
|
*
|
||||||
|
* @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a
|
||||||
|
* player
|
||||||
* @param params String passed to the hook to determine what value to return
|
* @param params String passed to the hook to determine what value to return
|
||||||
* @return value for the requested player and params
|
* @return value for the requested player and params
|
||||||
*/
|
*/
|
||||||
@ -40,6 +42,7 @@ public abstract class PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* called when a placeholder is requested from this hook
|
* called when a placeholder is requested from this hook
|
||||||
|
*
|
||||||
* @param p {@link Player} to request the placeholder value for, null if not needed for a player
|
* @param p {@link Player} to request the placeholder value for, null if not needed for a player
|
||||||
* @param params String passed to the hook to determine what value to return
|
* @param params String passed to the hook to determine what value to return
|
||||||
* @return value for the requested player and params
|
* @return value for the requested player and params
|
||||||
|
@ -20,9 +20,15 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi;
|
package me.clip.placeholderapi;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||||
import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent;
|
import me.clip.placeholderapi.expansion.Cacheable;
|
||||||
import me.clip.placeholderapi.expansion.*;
|
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.expansion.cloud.CloudExpansion;
|
||||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -34,10 +40,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
public class PlaceholderListener implements Listener {
|
public class PlaceholderListener implements Listener {
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ public class PlaceholderListener implements Listener {
|
|||||||
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
||||||
|
|
||||||
if (event.getExpansion() instanceof Listener) {
|
if (event.getExpansion() instanceof Listener) {
|
||||||
HandlerList.unregisterAll((Listener)event.getExpansion());
|
HandlerList.unregisterAll((Listener) event.getExpansion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getExpansion() instanceof Taskable) {
|
if (event.getExpansion() instanceof Taskable) {
|
||||||
@ -65,7 +67,8 @@ public class PlaceholderListener implements Listener {
|
|||||||
|
|
||||||
if (plugin.getExpansionCloud() != null) {
|
if (plugin.getExpansionCloud() != null) {
|
||||||
|
|
||||||
CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName());
|
CloudExpansion ex = plugin.getExpansionCloud()
|
||||||
|
.getCloudExpansion(event.getExpansion().getName());
|
||||||
|
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
ex.setHasExpansion(false);
|
ex.setHasExpansion(false);
|
||||||
@ -114,7 +117,8 @@ public class PlaceholderListener implements Listener {
|
|||||||
|
|
||||||
if (h.getPluginName().equalsIgnoreCase(n)) {
|
if (h.getPluginName().equalsIgnoreCase(n)) {
|
||||||
if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) {
|
if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) {
|
||||||
plugin.getLogger().info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName());
|
plugin.getLogger()
|
||||||
|
.info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.commands;
|
package me.clip.placeholderapi.commands;
|
||||||
|
|
||||||
|
import static me.clip.placeholderapi.util.Msg.color;
|
||||||
|
import static me.clip.placeholderapi.util.Msg.msg;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
@ -30,13 +36,6 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import static me.clip.placeholderapi.util.Msg.color;
|
|
||||||
import static me.clip.placeholderapi.util.Msg.msg;
|
|
||||||
|
|
||||||
public class ExpansionCloudCommands implements CommandExecutor {
|
public class ExpansionCloudCommands implements CommandExecutor {
|
||||||
|
|
||||||
private PlaceholderAPIPlugin plugin;
|
private PlaceholderAPIPlugin plugin;
|
||||||
@ -70,10 +69,12 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1].equalsIgnoreCase("fetch")) {
|
if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1]
|
||||||
|
.equalsIgnoreCase("fetch")) {
|
||||||
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||||
plugin.getExpansionCloud().clean();
|
plugin.getExpansionCloud().clean();
|
||||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
plugin.getExpansionCloud()
|
||||||
|
.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +91,10 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (args[1].equalsIgnoreCase("status")) {
|
if (args[1].equalsIgnoreCase("status")) {
|
||||||
|
|
||||||
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() + " &bexpansions available on the cloud.",
|
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size()
|
||||||
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount() + " &7authors have contributed to the expansion cloud.");
|
+ " &bexpansions available on the cloud.",
|
||||||
|
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount()
|
||||||
|
+ " &7authors have contributed to the expansion cloud.");
|
||||||
if (plugin.getExpansionCloud().getToUpdateCount() > 0) {
|
if (plugin.getExpansionCloud().getToUpdateCount() > 0) {
|
||||||
msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount()
|
msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount()
|
||||||
+ " &eexpansions installed that have updates available.");
|
+ " &eexpansions installed that have updates available.");
|
||||||
@ -115,7 +118,9 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(s instanceof Player)) {
|
if (!(s instanceof Player)) {
|
||||||
msg(s, (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion.getVersion().getUrl());
|
msg(s,
|
||||||
|
(expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion
|
||||||
|
.getVersion().getUrl());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,21 +132,25 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// latest version
|
// latest version
|
||||||
JSONMessage latestVersion = JSONMessage.create(color("&bLatest version: &f" + expansion.getLatestVersion()));
|
JSONMessage latestVersion = JSONMessage
|
||||||
|
.create(color("&bLatest version: &f" + expansion.getLatestVersion()));
|
||||||
latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate()
|
latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate()
|
||||||
+ "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes()
|
+ "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes()
|
||||||
));
|
));
|
||||||
latestVersion.send(p);
|
latestVersion.send(p);
|
||||||
|
|
||||||
// versions
|
// versions
|
||||||
JSONMessage versions = JSONMessage.create(color("&bVersions available: &f" + expansion.getVersions().size()));
|
JSONMessage versions = JSONMessage
|
||||||
|
.create(color("&bVersions available: &f" + expansion.getVersions().size()));
|
||||||
versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions())));
|
versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions())));
|
||||||
versions.suggestCommand("/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion());
|
versions.suggestCommand(
|
||||||
|
"/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion());
|
||||||
versions.send(p);
|
versions.send(p);
|
||||||
|
|
||||||
// placeholders
|
// placeholders
|
||||||
if (expansion.getPlaceholders() != null) {
|
if (expansion.getPlaceholders() != null) {
|
||||||
JSONMessage placeholders = JSONMessage.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size()));
|
JSONMessage placeholders = JSONMessage
|
||||||
|
.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size()));
|
||||||
placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders())));
|
placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders())));
|
||||||
placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName());
|
placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName());
|
||||||
placeholders.send(p);
|
placeholders.send(p);
|
||||||
@ -182,7 +191,8 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
Player p = (Player) s;
|
Player p = (Player) s;
|
||||||
|
|
||||||
JSONMessage download = JSONMessage.create(color("&7Click to download this version"));
|
JSONMessage download = JSONMessage.create(color("&7Click to download this version"));
|
||||||
download.suggestCommand("/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
download.suggestCommand(
|
||||||
|
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||||
download.send(p);
|
download.send(p);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -204,12 +214,14 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
List<String> placeholders = expansion.getPlaceholders();
|
List<String> placeholders = expansion.getPlaceholders();
|
||||||
|
|
||||||
if (placeholders == null) {
|
if (placeholders == null) {
|
||||||
msg(s, "&cThe expansion: &f" + expansion.getName() + " &cdoes not have any placeholders listed.",
|
msg(s, "&cThe expansion: &f" + expansion.getName()
|
||||||
|
+ " &cdoes not have any placeholders listed.",
|
||||||
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(s instanceof Player) || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
if (!(s instanceof Player)
|
||||||
|
|| plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
||||||
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
||||||
String.join("&a, &f", placeholders));
|
String.join("&a, &f", placeholders));
|
||||||
return true;
|
return true;
|
||||||
@ -219,8 +231,8 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size()));
|
JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size()));
|
||||||
message.then("\n");
|
message.then("\n");
|
||||||
|
|
||||||
for (int i = 0 ; i < placeholders.size() ; i++) {
|
for (int i = 0; i < placeholders.size(); i++) {
|
||||||
if (i == placeholders.size()-1) {
|
if (i == placeholders.size() - 1) {
|
||||||
message.then(placeholders.get(i));
|
message.then(placeholders.get(i));
|
||||||
} else {
|
} else {
|
||||||
message.then(color(placeholders.get(i) + "&b, &f"));
|
message.then(color(placeholders.get(i) + "&b, &f"));
|
||||||
@ -287,11 +299,14 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
||||||
|
|
||||||
if (page > avail) {
|
if (page > avail) {
|
||||||
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!" : "are only &f" + avail + " &cpages available!"));
|
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!"
|
||||||
|
: "are only &f" + avail + " &cpages available!"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg(s, "&bShowing expansions for&7: &f" + (author != null ? author : (installed ? "all installed" : "all available"))+ " &8&m--&r &bamount&7: &f" + ex.size() + " &bpage&7: &f" + page + "&7/&f" + avail);
|
msg(s, "&bShowing expansions for&7: &f" + (author != null ? author
|
||||||
|
: (installed ? "all installed" : "all available")) + " &8&m--&r &bamount&7: &f" + ex
|
||||||
|
.size() + " &bpage&7: &f" + page + "&7/&f" + avail);
|
||||||
|
|
||||||
ex = plugin.getExpansionCloud().getPage(ex, page, 10);
|
ex = plugin.getExpansionCloud().getPage(ex, page, 10);
|
||||||
|
|
||||||
@ -306,8 +321,13 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
if (!(s instanceof Player)) {
|
if (!(s instanceof Player)) {
|
||||||
|
|
||||||
for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) {
|
for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) {
|
||||||
if (expansion == null || expansion.getValue() == null) continue;
|
if (expansion == null || expansion.getValue() == null) {
|
||||||
msg(s, "&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "&7")) + expansion.getValue().getName() + " &8&m-- &r" + expansion.getValue().getVersion().getUrl());
|
continue;
|
||||||
|
}
|
||||||
|
msg(s,
|
||||||
|
"&b" + (expansion.getKey() + 1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6"
|
||||||
|
: (expansion.getValue().hasExpansion() ? "&a" : "&7")) + expansion.getValue()
|
||||||
|
.getName() + " &8&m-- &r" + expansion.getValue().getVersion().getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -332,10 +352,14 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
sb.append("&bAuthor&7: &f" + expansion.getValue().getAuthor() + "\n");
|
sb.append("&bAuthor&7: &f" + expansion.getValue().getAuthor() + "\n");
|
||||||
sb.append("&bVerified&7: &f" + expansion.getValue().isVerified() + "\n");
|
sb.append("&bVerified&7: &f" + expansion.getValue().isVerified() + "\n");
|
||||||
sb.append("&bLatest version&7: &f" + expansion.getValue().getVersion().getVersion() + "\n");
|
sb.append("&bLatest version&7: &f" + expansion.getValue().getVersion().getVersion() + "\n");
|
||||||
sb.append("&bLast updated&7: &f" + expansion.getValue().getTimeSinceLastUpdate() + " ago\n");
|
sb.append(
|
||||||
|
"&bLast updated&7: &f" + expansion.getValue().getTimeSinceLastUpdate() + " ago\n");
|
||||||
sb.append("\n" + expansion.getValue().getDescription());
|
sb.append("\n" + expansion.getValue().getDescription());
|
||||||
|
|
||||||
String msg = color("&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "")) + expansion.getValue().getName());
|
String msg = color(
|
||||||
|
"&b" + (expansion.getKey() + 1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6"
|
||||||
|
: (expansion.getValue().hasExpansion() ? "&a" : "")) + expansion.getValue()
|
||||||
|
.getName());
|
||||||
|
|
||||||
String hover = color(sb.toString());
|
String hover = color(sb.toString());
|
||||||
|
|
||||||
@ -348,7 +372,6 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("download")) {
|
if (args[1].equalsIgnoreCase("download")) {
|
||||||
|
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
@ -381,7 +404,8 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version);
|
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f"
|
||||||
|
+ version);
|
||||||
String player = ((s instanceof Player) ? s.getName() : null);
|
String player = ((s instanceof Player) ? s.getName() : null);
|
||||||
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
||||||
return true;
|
return true;
|
||||||
@ -392,5 +416,4 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ public class ExpansionRegisterEvent extends Event {
|
|||||||
this.expansion = expansion;
|
this.expansion = expansion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static HandlerList getHandlerList() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.events;
|
package me.clip.placeholderapi.events;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderHook;
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -34,12 +33,12 @@ public class ExpansionUnregisterEvent extends Event {
|
|||||||
this.expansion = expansion;
|
this.expansion = expansion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static HandlerList getHandlerList() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +36,12 @@ public class PlaceholderHookUnloadEvent extends Event {
|
|||||||
this.hook = placeholderHook;
|
this.hook = placeholderHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static HandlerList getHandlerList() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,11 @@
|
|||||||
package me.clip.placeholderapi.expansion;
|
package me.clip.placeholderapi.expansion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface allows a class which extends a {@link PlaceholderExpansion}
|
* This interface allows a class which extends a {@link PlaceholderExpansion} to have the clear
|
||||||
* to have the clear method called when the implementing expansion is unregistered
|
* method called when the implementing expansion is unregistered from PlaceholderAPI. This is useful
|
||||||
* from PlaceholderAPI.
|
* if we want to do things when the implementing hook is unregistered
|
||||||
* This is useful if we want to do things when the implementing hook is unregistered
|
|
||||||
* @author Ryan McCarthy
|
|
||||||
*
|
*
|
||||||
|
* @author Ryan McCarthy
|
||||||
*/
|
*/
|
||||||
public interface Cacheable {
|
public interface Cacheable {
|
||||||
|
|
||||||
|
@ -23,16 +23,17 @@ package me.clip.placeholderapi.expansion;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface allows a class which extends a {@link PlaceholderExpansion}
|
* This interface allows a class which extends a {@link PlaceholderExpansion} to have the cleanup
|
||||||
* to have the cleanup method called every time a player leaves the server.
|
* method called every time a player leaves the server. This is useful if we want to clean up after
|
||||||
* This is useful if we want to clean up after the player
|
* the player
|
||||||
* @author Ryan McCarthy
|
|
||||||
*
|
*
|
||||||
|
* @author Ryan McCarthy
|
||||||
*/
|
*/
|
||||||
public interface Cleanable {
|
public interface Cleanable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player leaves the server
|
* Called when a player leaves the server
|
||||||
|
*
|
||||||
* @param p (@link Player} who left the server
|
* @param p (@link Player} who left the server
|
||||||
*/
|
*/
|
||||||
void cleanup(Player p);
|
void cleanup(Player p);
|
||||||
|
@ -23,19 +23,21 @@ package me.clip.placeholderapi.expansion;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any {@link PlaceholderExpansion} class which implements configurable will
|
* Any {@link PlaceholderExpansion} class which implements configurable will have any options listed
|
||||||
* have any options listed in the getDefaults map automatically added to the PlaceholderAPI config.yml file
|
* in the getDefaults map automatically added to the PlaceholderAPI config.yml file
|
||||||
* @author Ryan McCarthy
|
|
||||||
*
|
*
|
||||||
|
* @author Ryan McCarthy
|
||||||
*/
|
*/
|
||||||
public interface Configurable {
|
public interface Configurable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be called before the implementing class is registered
|
* This method will be called before the implementing class is registered to obtain a map of
|
||||||
* to obtain a map of configuration options that the implementing class needs
|
* configuration options that the implementing class needs These paths and values will be added to
|
||||||
* These paths and values will be added to the PlaceholderAPI config.yml in the configuration section
|
* the PlaceholderAPI config.yml in the configuration section expansions.(placeholder
|
||||||
* expansions.(placeholder identifier).(your key): (your value)
|
* identifier).(your key): (your value)
|
||||||
* @return Map of config path / values which need to be added / removed from the PlaceholderAPI config.yml file
|
*
|
||||||
|
* @return Map of config path / values which need to be added / removed from the PlaceholderAPI
|
||||||
|
* config.yml file
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getDefaults();
|
Map<String, Object> getDefaults();
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,6 @@ public enum NMSVersion {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NMSVersion getVersion(String version) {
|
public static NMSVersion getVersion(String version) {
|
||||||
for (NMSVersion v : values()) {
|
for (NMSVersion v : values()) {
|
||||||
if (v.getVersion().equalsIgnoreCase(version)) {
|
if (v.getVersion().equalsIgnoreCase(version)) {
|
||||||
@ -54,4 +50,9 @@ public enum NMSVersion {
|
|||||||
}
|
}
|
||||||
return NMSVersion.UNKNOWN;
|
return NMSVersion.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.expansion;
|
package me.clip.placeholderapi.expansion;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.PlaceholderHook;
|
import me.clip.placeholderapi.PlaceholderHook;
|
||||||
@ -27,12 +28,11 @@ import org.apache.commons.lang.Validate;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this expansion
|
* The name of this expansion
|
||||||
|
*
|
||||||
* @return {@link #getIdentifier()} by default, name of this expansion if specified
|
* @return {@link #getIdentifier()} by default, name of this expansion if specified
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -41,25 +41,29 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The placeholder identifier of this expanion
|
* The placeholder identifier of this expanion
|
||||||
|
*
|
||||||
* @return placeholder identifier that is associated with this expansion
|
* @return placeholder identifier that is associated with this expansion
|
||||||
*/
|
*/
|
||||||
public abstract String getIdentifier();
|
public abstract String getIdentifier();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The author of this expansion
|
* The author of this expansion
|
||||||
|
*
|
||||||
* @return name of the author for this expansion
|
* @return name of the author for this expansion
|
||||||
*/
|
*/
|
||||||
public abstract String getAuthor();
|
public abstract String getAuthor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version of this expansion
|
* The version of this expansion
|
||||||
|
*
|
||||||
* @return current version of this expansion
|
* @return current version of this expansion
|
||||||
*/
|
*/
|
||||||
public abstract String getVersion();
|
public abstract String getVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the plugin that this expansion hooks into.
|
* The name of the plugin that this expansion hooks into. by default will return the deprecated
|
||||||
* by default will return the deprecated {@link #getPlugin()} method
|
* {@link #getPlugin()} method
|
||||||
|
*
|
||||||
* @return plugin name that this expansion requires to function
|
* @return plugin name that this expansion requires to function
|
||||||
*/
|
*/
|
||||||
public String getRequiredPlugin() {
|
public String getRequiredPlugin() {
|
||||||
@ -68,6 +72,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The placeholders associated with this expansion
|
* The placeholders associated with this expansion
|
||||||
|
*
|
||||||
* @return placeholder list that this expansion provides
|
* @return placeholder list that this expansion provides
|
||||||
*/
|
*/
|
||||||
public List<String> getPlaceholders() {
|
public List<String> getPlaceholders() {
|
||||||
@ -75,8 +80,10 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expansions that do not use the ecloud and instead register from the dependency should set this to true
|
* Expansions that do not use the ecloud and instead register from the dependency should set this
|
||||||
* to ensure that your placeholder expansion is not unregistered when the papi reload command is used
|
* to true to ensure that your placeholder expansion is not unregistered when the papi reload
|
||||||
|
* command is used
|
||||||
|
*
|
||||||
* @return if this expansion should persist through placeholder reloads
|
* @return if this expansion should persist through placeholder reloads
|
||||||
*/
|
*/
|
||||||
public boolean persist() {
|
public boolean persist() {
|
||||||
@ -85,6 +92,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this placeholder identfier has already been registered
|
* Check if this placeholder identfier has already been registered
|
||||||
|
*
|
||||||
* @return true if the identifier for this expansion is already registered
|
* @return true if the identifier for this expansion is already registered
|
||||||
*/
|
*/
|
||||||
public boolean isRegistered() {
|
public boolean isRegistered() {
|
||||||
@ -93,16 +101,19 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any requirements need to be checked before this expansion should register,
|
* If any requirements need to be checked before this expansion should register, you can check
|
||||||
* you can check them here
|
* them here
|
||||||
|
*
|
||||||
* @return true if this hook meets all the requirements to register
|
* @return true if this hook meets all the requirements to register
|
||||||
*/
|
*/
|
||||||
public boolean canRegister() {
|
public boolean canRegister() {
|
||||||
return getRequiredPlugin() == null || Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null;
|
return getRequiredPlugin() == null
|
||||||
|
|| Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to register this PlaceholderExpansion
|
* Attempt to register this PlaceholderExpansion
|
||||||
|
*
|
||||||
* @return true if this expansion is now registered with PlaceholderAPI
|
* @return true if this expansion is now registered with PlaceholderAPI
|
||||||
*/
|
*/
|
||||||
public boolean register() {
|
public boolean register() {
|
||||||
@ -112,6 +123,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick getter for the {@link PlaceholderAPIPlugin} instance
|
* Quick getter for the {@link PlaceholderAPIPlugin} instance
|
||||||
|
*
|
||||||
* @return {@link PlaceholderAPIPlugin} instance
|
* @return {@link PlaceholderAPIPlugin} instance
|
||||||
*/
|
*/
|
||||||
public PlaceholderAPIPlugin getPlaceholderAPI() {
|
public PlaceholderAPIPlugin getPlaceholderAPI() {
|
||||||
@ -119,23 +131,28 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String path, String def) {
|
public String getString(String path, String def) {
|
||||||
return getPlaceholderAPI().getConfig().getString("expansions." + getIdentifier() + "." + path, def);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getString("expansions." + getIdentifier() + "." + path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(String path, int def) {
|
public int getInt(String path, int def) {
|
||||||
return getPlaceholderAPI().getConfig().getInt("expansions." + getIdentifier() + "." + path, def);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getInt("expansions." + getIdentifier() + "." + path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(String path, long def) {
|
public long getLong(String path, long def) {
|
||||||
return getPlaceholderAPI().getConfig().getLong("expansions." + getIdentifier() + "." + path, def);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getLong("expansions." + getIdentifier() + "." + path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(String path, double def) {
|
public double getDouble(String path, double def) {
|
||||||
return getPlaceholderAPI().getConfig().getDouble("expansions." + getIdentifier() + "." + path, def);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getDouble("expansions." + getIdentifier() + "." + path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getStringList(String path) {
|
public List<String> getStringList(String path) {
|
||||||
return getPlaceholderAPI().getConfig().getStringList("expansions." + getIdentifier() + "." + path);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getStringList("expansions." + getIdentifier() + "." + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(String path, Object def) {
|
public Object get(String path, Object def) {
|
||||||
@ -143,7 +160,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSection getConfigSection(String path) {
|
public ConfigurationSection getConfigSection(String path) {
|
||||||
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier() + "." + path);
|
return getPlaceholderAPI().getConfig()
|
||||||
|
.getConfigurationSection("expansions." + getIdentifier() + "." + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSection getConfigSection() {
|
public ConfigurationSection getConfigSection() {
|
||||||
@ -167,11 +185,15 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to show a description
|
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to show a description
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getDescription() { return null; }
|
public String getDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to display a link
|
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to display a link
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getLink() { return null; }
|
public String getLink() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,5 +23,6 @@ package me.clip.placeholderapi.expansion;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public interface Relational {
|
public interface Relational {
|
||||||
|
|
||||||
String onPlaceholderRequest(Player one, Player two, String identifier);
|
String onPlaceholderRequest(Player one, Player two, String identifier);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ public interface Taskable {
|
|||||||
void start();
|
void start();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the implementing class has been unregistered from PlaceholderAPI
|
* Called when the implementing class has been unregistered from PlaceholderAPI Tasks that need to
|
||||||
* Tasks that need to be performed when this expansion has unregistered should go here
|
* be performed when this expansion has unregistered should go here
|
||||||
*/
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
package me.clip.placeholderapi.expansion;
|
package me.clip.placeholderapi.expansion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder expansions which use NMS code should be version specific.
|
* Placeholder expansions which use NMS code should be version specific. Implementing this class
|
||||||
* Implementing this class allows you to perform checks based on the version the server is running.
|
* allows you to perform checks based on the version the server is running. The isCompatibleWith
|
||||||
* The isCompatibleWith method will be passed the server version and allow you to return if your expansion is compatible with that version.
|
* method will be passed the server version and allow you to return if your expansion is compatible
|
||||||
* @author Ryan McCarthy
|
* with that version.
|
||||||
*
|
*
|
||||||
|
* @author Ryan McCarthy
|
||||||
*/
|
*/
|
||||||
public interface VersionSpecific {
|
public interface VersionSpecific {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called before the expansion is attempted to be registered
|
* This method is called before the expansion is attempted to be registered The server version
|
||||||
* The server version will be passed to this method so you know what version the server is currently running.
|
* will be passed to this method so you know what version the server is currently running.
|
||||||
*
|
*
|
||||||
* @return true if your expansion is compatible with the version the server is running.
|
* @return true if your expansion is compatible with the version the server is running.
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
package me.clip.placeholderapi.expansion.cloud;
|
package me.clip.placeholderapi.expansion.cloud;
|
||||||
|
|
||||||
import me.clip.placeholderapi.util.TimeUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import me.clip.placeholderapi.util.TimeUtil;
|
||||||
|
|
||||||
|
|
||||||
public class CloudExpansion {
|
public class CloudExpansion {
|
||||||
@ -173,6 +172,7 @@ public class CloudExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Version {
|
public class Version {
|
||||||
|
|
||||||
private String url, version, release_notes;
|
private String url, version, release_notes;
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
|
@ -21,6 +21,22 @@
|
|||||||
package me.clip.placeholderapi.expansion.cloud;
|
package me.clip.placeholderapi.expansion.cloud;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
@ -32,21 +48,13 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
public class ExpansionCloudManager {
|
public class ExpansionCloudManager {
|
||||||
|
|
||||||
private PlaceholderAPIPlugin plugin;
|
|
||||||
private final String API = "http://api.extendedclip.com/v2/";
|
private final String API = "http://api.extendedclip.com/v2/";
|
||||||
private final File dir;
|
private final File dir;
|
||||||
private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>();
|
private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>();
|
||||||
private final List<String> downloading = new ArrayList<>();
|
private final List<String> downloading = new ArrayList<>();
|
||||||
|
private PlaceholderAPIPlugin plugin;
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
public ExpansionCloudManager(PlaceholderAPIPlugin instance) {
|
public ExpansionCloudManager(PlaceholderAPIPlugin instance) {
|
||||||
@ -76,15 +84,19 @@ public class ExpansionCloudManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CloudExpansion getCloudExpansion(String name) {
|
public CloudExpansion getCloudExpansion(String name) {
|
||||||
return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst()
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCloudAuthorCount() {
|
public int getCloudAuthorCount() {
|
||||||
return remote.values().stream().collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())).size();
|
return remote.values().stream()
|
||||||
|
.collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getToUpdateCount() {
|
public long getToUpdateCount() {
|
||||||
return PlaceholderAPI.getExpansions().stream().filter(ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()).shouldUpdate()).count();
|
return PlaceholderAPI.getExpansions().stream().filter(
|
||||||
|
ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName())
|
||||||
|
.shouldUpdate()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, CloudExpansion> getAllByAuthor(String author) {
|
public Map<Integer, CloudExpansion> getAllByAuthor(String author) {
|
||||||
@ -150,7 +162,8 @@ public class ExpansionCloudManager {
|
|||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, int size) {
|
public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page,
|
||||||
|
int size) {
|
||||||
if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) {
|
if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -182,7 +195,8 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
|
|
||||||
@ -235,7 +249,8 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
ce.setName(o.toString());
|
ce.setName(o.toString());
|
||||||
|
|
||||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(ce.getName());
|
PlaceholderExpansion ex = plugin.getExpansionManager()
|
||||||
|
.getRegisteredExpansion(ce.getName());
|
||||||
|
|
||||||
if (ex != null && ex.isRegistered()) {
|
if (ex != null && ex.isRegistered()) {
|
||||||
ce.setHasExpansion(true);
|
ce.setHasExpansion(true);
|
||||||
@ -280,7 +295,8 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
is = urlConn.getInputStream();
|
is = urlConn.getInputStream();
|
||||||
|
|
||||||
fos = new FileOutputStream(dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar");
|
fos = new FileOutputStream(
|
||||||
|
dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar");
|
||||||
|
|
||||||
byte[] buffer = new byte[is.available()];
|
byte[] buffer = new byte[is.available()];
|
||||||
|
|
||||||
@ -306,7 +322,8 @@ public class ExpansionCloudManager {
|
|||||||
downloadExpansion(player, ex, ex.getLatestVersion());
|
downloadExpansion(player, ex, ex.getLatestVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadExpansion(final String player, final CloudExpansion ex, final String version) {
|
public void downloadExpansion(final String player, final CloudExpansion ex,
|
||||||
|
final String version) {
|
||||||
|
|
||||||
if (downloading.contains(ex.getName())) {
|
if (downloading.contains(ex.getName())) {
|
||||||
return;
|
return;
|
||||||
@ -324,7 +341,9 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
downloading.add(ex.getName());
|
downloading.add(ex.getName());
|
||||||
|
|
||||||
plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl());
|
plugin.getLogger().info(
|
||||||
|
"Attempting download of expansion: " + ex.getName() + (player != null ? " by user: "
|
||||||
|
+ player : "") + " from url: " + ver.getUrl());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
|
||||||
@ -336,7 +355,8 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
plugin.getLogger().warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
plugin.getLogger()
|
||||||
|
.warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package me.clip.placeholderapi.updatechecker;
|
package me.clip.placeholderapi.updatechecker;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.util.Msg;
|
import me.clip.placeholderapi.util.Msg;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -8,15 +12,10 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class UpdateChecker implements Listener {
|
public class UpdateChecker implements Listener {
|
||||||
|
|
||||||
private PlaceholderAPIPlugin plugin;
|
|
||||||
private final int RESOURCE_ID = 6245;
|
private final int RESOURCE_ID = 6245;
|
||||||
|
private PlaceholderAPIPlugin plugin;
|
||||||
private String spigotVersion, pluginVersion;
|
private String spigotVersion, pluginVersion;
|
||||||
private boolean updateAvailable;
|
private boolean updateAvailable;
|
||||||
|
|
||||||
@ -25,7 +24,9 @@ public class UpdateChecker implements Listener {
|
|||||||
pluginVersion = i.getDescription().getVersion();
|
pluginVersion = i.getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasUpdateAvailable() { return updateAvailable; }
|
public boolean hasUpdateAvailable() {
|
||||||
|
return updateAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSpigotVersion() {
|
public String getSpigotVersion() {
|
||||||
return spigotVersion;
|
return spigotVersion;
|
||||||
@ -34,7 +35,8 @@ public class UpdateChecker implements Listener {
|
|||||||
public void fetch() {
|
public void fetch() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
HttpsURLConnection con = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
HttpsURLConnection con = (HttpsURLConnection) new URL(
|
||||||
|
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -53,15 +55,19 @@ public class UpdateChecker implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
plugin.getLogger().info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
|
plugin.getLogger()
|
||||||
plugin.getLogger().info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
|
||||||
|
plugin.getLogger()
|
||||||
|
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
||||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean spigotIsNewer() {
|
private boolean spigotIsNewer() {
|
||||||
if (spigotVersion == null || spigotVersion.isEmpty()) return false;
|
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
String plV = toReadable(pluginVersion);
|
String plV = toReadable(pluginVersion);
|
||||||
String spV = toReadable(spigotVersion);
|
String spV = toReadable(spigotVersion);
|
||||||
return plV.compareTo(spV) < 0;
|
return plV.compareTo(spV) < 0;
|
||||||
@ -71,14 +77,17 @@ public class UpdateChecker implements Listener {
|
|||||||
if (version.contains("-DEV-")) {
|
if (version.contains("-DEV-")) {
|
||||||
version = version.split("-DEV-")[0];
|
version = version.split("-DEV-")[0];
|
||||||
}
|
}
|
||||||
return version.replaceAll("\\.","");
|
return version.replaceAll("\\.", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
|
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
|
||||||
Msg.msg(e.getPlayer(), "&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion() + "&e)"
|
Msg.msg(e.getPlayer(),
|
||||||
, "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
"&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion()
|
||||||
|
+ "&e)"
|
||||||
|
, "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID
|
||||||
|
+ "/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class TimeUtil {
|
|||||||
public static String getRemaining(int seconds, TimeFormat type) {
|
public static String getRemaining(int seconds, TimeFormat type) {
|
||||||
|
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
return "0";
|
return "0";
|
||||||
case HOURS:
|
case HOURS:
|
||||||
@ -42,7 +42,7 @@ public class TimeUtil {
|
|||||||
int s = 60 * minutes;
|
int s = 60 * minutes;
|
||||||
int secondsLeft = seconds - s;
|
int secondsLeft = seconds - s;
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
return "0";
|
return "0";
|
||||||
case HOURS:
|
case HOURS:
|
||||||
@ -59,7 +59,7 @@ public class TimeUtil {
|
|||||||
int hours = minutes / 60;
|
int hours = minutes / 60;
|
||||||
int inMins = 60 * hours;
|
int inMins = 60 * hours;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
return "0";
|
return "0";
|
||||||
case HOURS:
|
case HOURS:
|
||||||
@ -110,7 +110,7 @@ public class TimeUtil {
|
|||||||
public static String getTime(int seconds) {
|
public static String getTime(int seconds) {
|
||||||
|
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
return seconds+"s";
|
return seconds + "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
@ -118,44 +118,44 @@ public class TimeUtil {
|
|||||||
int secondsLeft = seconds - s;
|
int secondsLeft = seconds - s;
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
return String.valueOf(minutes+"m "+secondsLeft+"s");
|
return String.valueOf(minutes + "m " + secondsLeft + "s");
|
||||||
} else {
|
} else {
|
||||||
return String.valueOf(minutes+"m");
|
return String.valueOf(minutes + "m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (minutes < 1440) {
|
if (minutes < 1440) {
|
||||||
String time;
|
String time;
|
||||||
int hours = minutes / 60;
|
int hours = minutes / 60;
|
||||||
time = hours+"h";
|
time = hours + "h";
|
||||||
int inMins = 60 * hours;
|
int inMins = 60 * hours;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
if (leftOver >= 1) {
|
if (leftOver >= 1) {
|
||||||
time = time+" "+leftOver+"m";
|
time = time + " " + leftOver + "m";
|
||||||
}
|
}
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
time = time+" "+secondsLeft+"s";
|
time = time + " " + secondsLeft + "s";
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
String time;
|
String time;
|
||||||
int days = minutes / 1440;
|
int days = minutes / 1440;
|
||||||
time = days+"d";
|
time = days + "d";
|
||||||
int inMins = 1440 * days;
|
int inMins = 1440 * days;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
if (leftOver >= 1) {
|
if (leftOver >= 1) {
|
||||||
if (leftOver < 60) {
|
if (leftOver < 60) {
|
||||||
time = time+" "+leftOver+"m";
|
time = time + " " + leftOver + "m";
|
||||||
} else {
|
} else {
|
||||||
int hours = leftOver / 60;
|
int hours = leftOver / 60;
|
||||||
time = time+" "+hours+"h";
|
time = time + " " + hours + "h";
|
||||||
int hoursInMins = 60 * hours;
|
int hoursInMins = 60 * hours;
|
||||||
int minsLeft = leftOver - hoursInMins;
|
int minsLeft = leftOver - hoursInMins;
|
||||||
time = time+" "+minsLeft+"m";
|
time = time + " " + minsLeft + "m";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
time = time+" "+secondsLeft+"s";
|
time = time + " " + secondsLeft + "s";
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user