mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-07 00:27:12 +01:00
Reformatted project to conform to google style guide.
This commit is contained in:
@@ -20,6 +20,10 @@
|
||||
*/
|
||||
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.configuration.PlaceholderAPIConfig;
|
||||
import me.clip.placeholderapi.expansion.ExpansionManager;
|
||||
@@ -34,235 +38,223 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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...
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
private static SimpleDateFormat dateFormat;
|
||||
private static String booleanTrue;
|
||||
private static String booleanFalse;
|
||||
private static Version serverVersion;
|
||||
private PlaceholderAPIConfig config;
|
||||
private ExpansionManager expansionManager;
|
||||
private ExpansionCloudManager expansionCloud;
|
||||
private long startTime;
|
||||
|
||||
private PlaceholderAPIConfig config;
|
||||
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);
|
||||
}
|
||||
|
||||
private ExpansionManager expansionManager;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
private ExpansionCloudManager expansionCloud;
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
private static SimpleDateFormat dateFormat;
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
private static String booleanTrue;
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
private static String booleanFalse;
|
||||
public static Version getServerVersion() {
|
||||
return serverVersion != null ? serverVersion : getVersion();
|
||||
}
|
||||
|
||||
private static Version serverVersion;
|
||||
@Override
|
||||
public void onLoad() {
|
||||
startTime = System.currentTimeMillis();
|
||||
instance = this;
|
||||
serverVersion = getVersion();
|
||||
config = new PlaceholderAPIConfig(this);
|
||||
expansionManager = new ExpansionManager(this);
|
||||
}
|
||||
|
||||
private long startTime;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
config.loadDefConfig();
|
||||
setupOptions();
|
||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||
new PlaceholderListener(this);
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
expansionManager.registerAllExpansions();
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
if (config.isCloudEnabled()) {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
startTime = System.currentTimeMillis();
|
||||
instance = this;
|
||||
serverVersion = getVersion();
|
||||
config = new PlaceholderAPIConfig(this);
|
||||
expansionManager = new ExpansionManager(this);
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager.clean();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
config.loadDefConfig();
|
||||
setupOptions();
|
||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||
new PlaceholderListener(this);
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
expansionManager.registerAllExpansions();
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
if (config.isCloudEnabled()) {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
}
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
expansionManager.clean();
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
expansionManager.registerAllExpansions();
|
||||
if (!config.isCloudEnabled()) {
|
||||
disableCloud();
|
||||
} else if (!cloudEnabled) {
|
||||
enableCloud();
|
||||
}
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
PlaceholderAPI.getRegisteredIdentifiers().size()
|
||||
+ " &aplaceholder hooks successfully registered!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager.clean();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
instance = null;
|
||||
}
|
||||
private void setupOptions() {
|
||||
booleanTrue = config.booleanTrue();
|
||||
if (booleanTrue == null) {
|
||||
booleanTrue = "true";
|
||||
}
|
||||
booleanFalse = config.booleanFalse();
|
||||
if (booleanFalse == null) {
|
||||
booleanFalse = "false";
|
||||
}
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat(config.dateFormat());
|
||||
} catch (Exception e) {
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
expansionManager.clean();
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
expansionManager.registerAllExpansions();
|
||||
if (!config.isCloudEnabled()) {
|
||||
disableCloud();
|
||||
} else if (!cloudEnabled) {
|
||||
enableCloud();
|
||||
}
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!"));
|
||||
}
|
||||
private void setupMetrics() {
|
||||
Metrics m = new Metrics(this);
|
||||
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud",
|
||||
() -> getExpansionCloud() != null ? "yes" : "no"));
|
||||
|
||||
private void setupOptions() {
|
||||
booleanTrue = config.booleanTrue();
|
||||
if (booleanTrue == null) {
|
||||
booleanTrue = "true";
|
||||
}
|
||||
booleanFalse = config.booleanFalse();
|
||||
if (booleanFalse == null) {
|
||||
booleanFalse = "false";
|
||||
}
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat(config.dateFormat());
|
||||
} catch (Exception e) {
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
m.addCustomChart(
|
||||
new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
|
||||
private void setupMetrics() {
|
||||
Metrics m = new Metrics(this);
|
||||
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.AdvancedPie("expansions_used", () -> {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders();
|
||||
|
||||
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders();
|
||||
if (!p.isEmpty()) {
|
||||
|
||||
if (!p.isEmpty()) {
|
||||
for (PlaceholderHook hook : p.values()) {
|
||||
if (hook instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) hook;
|
||||
map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier()
|
||||
: ex.getRequiredPlugin(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
||||
for (PlaceholderHook hook : p.values()) {
|
||||
if (hook instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) hook;
|
||||
map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier()
|
||||
: ex.getRequiredPlugin(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}));
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
public void enableCloud() {
|
||||
if (expansionCloud == null) {
|
||||
expansionCloud = new ExpansionCloudManager(this);
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
} else {
|
||||
expansionCloud.clean();
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
}
|
||||
}
|
||||
|
||||
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 disableCloud() {
|
||||
if (expansionCloud != null) {
|
||||
expansionCloud.clean();
|
||||
expansionCloud = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void enableCloud() {
|
||||
if (expansionCloud == null) {
|
||||
expansionCloud = new ExpansionCloudManager(this);
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
} else {
|
||||
expansionCloud.clean();
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void disableCloud() {
|
||||
if (expansionCloud != null) {
|
||||
expansionCloud.clean();
|
||||
expansionCloud = null;
|
||||
}
|
||||
}
|
||||
public ExpansionManager getExpansionManager() {
|
||||
return expansionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
public ExpansionCloudManager getExpansionCloud() {
|
||||
return expansionCloud;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
public String getUptime() {
|
||||
return TimeUtil
|
||||
.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public ExpansionManager getExpansionManager() {
|
||||
return expansionManager;
|
||||
}
|
||||
|
||||
public ExpansionCloudManager getExpansionCloud() {
|
||||
return expansionCloud;
|
||||
}
|
||||
|
||||
public String getUptime() {
|
||||
return TimeUtil.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
public long getUptimeMillis() {
|
||||
return (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
public long getUptimeMillis() {
|
||||
return (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user