1.16.3 Update / Added bstats Metrics

This commit is contained in:
LOOHP 2020-09-11 11:02:35 +08:00
parent 10789c3c60
commit 26c4b9d960
6 changed files with 1001 additions and 958 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>Limbo</groupId> <groupId>Limbo</groupId>
<artifactId>Limbo</artifactId> <artifactId>Limbo</artifactId>
<version>0.3.2-ALPHA</version> <version>0.3.3-ALPHA</version>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>
@ -53,7 +53,7 @@
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
<finalName>${project.artifactId}-${project.version}-1.16.2</finalName> <finalName>${project.artifactId}-${project.version}-1.16.3</finalName>
</build> </build>
<repositories> <repositories>

View File

@ -18,26 +18,30 @@ import com.loohp.limbo.Utils.YamlOrder;
public class FileConfiguration { public class FileConfiguration {
File file;
Map<String, Object> mapping; Map<String, Object> mapping;
String header; String header;
public FileConfiguration(File file) { public FileConfiguration(File file) throws FileNotFoundException {
this.file = file;
if (file.exists()) { if (file.exists()) {
try { reloadConfig();
reloadConfig(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else { } else {
mapping = new LinkedHashMap<>(); mapping = new LinkedHashMap<>();
} }
} }
@Deprecated
public FileConfiguration(InputStream input){ public FileConfiguration(InputStream input){
reloadConfig(input); reloadConfig(input);
} }
public FileConfiguration reloadConfig(InputStream input) { public FileConfiguration reloadConfig() throws FileNotFoundException {
return reloadConfig(new FileInputStream(file));
}
private FileConfiguration reloadConfig(InputStream input) {
Yaml yml = new Yaml(); Yaml yml = new Yaml();
mapping = yml.load(input); mapping = yml.load(input);
return this; return this;
@ -76,7 +80,7 @@ public class FileConfiguration {
} }
map = map1; map = map1;
} }
if (value == null) { if (value != null) {
map.put(tree[tree.length - 1], (T) value); map.put(tree[tree.length - 1], (T) value);
} else { } else {
map.remove(tree[tree.length - 1]); map.remove(tree[tree.length - 1]);
@ -93,9 +97,13 @@ public class FileConfiguration {
customRepresenter.setPropertyUtils(customProperty); customRepresenter.setPropertyUtils(customProperty);
Yaml yaml = new Yaml(customRepresenter, options); Yaml yaml = new Yaml(customRepresenter, options);
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
PrintWriter pw = new PrintWriter(file, StandardCharsets.UTF_8.toString()); PrintWriter pw = new PrintWriter(file, StandardCharsets.UTF_8.toString());
if (header != null) { if (header != null) {
pw.println(header); pw.println("#" + header.replace("\n", "\n#"));
} }
yaml.dump(mapping, pw); yaml.dump(mapping, pw);
pw.flush(); pw.flush();

View File

@ -17,8 +17,6 @@ import com.loohp.limbo.World.World;
public class ServerProperties { public class ServerProperties {
public static final String JSON_BASE_RESPONSE = "{\"version\":{\"name\":\"%VERSION%\",\"protocol\":%PROTOCOL%},\"players\":{\"max\":%MAXPLAYERS%,\"online\":%ONLINECLIENTS%},\"description\":%MOTD%,%FAVICON%\"modinfo\":{\"type\":\"FML\",\"modList\":[]}}";
File file; File file;
int maxPlayers; int maxPlayers;
int serverPort; int serverPort;
@ -146,10 +144,6 @@ public class ServerProperties {
return allowFlight; return allowFlight;
} }
public static String getJsonBaseResponse() {
return JSON_BASE_RESPONSE;
}
public String getMotdJson() { public String getMotdJson() {
return motdJson; return motdJson;
} }

View File

@ -2,11 +2,13 @@ package com.loohp.limbo;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
@ -36,6 +38,7 @@ import com.loohp.limbo.Events.EventsManager;
import com.loohp.limbo.File.ServerProperties; import com.loohp.limbo.File.ServerProperties;
import com.loohp.limbo.GUI.GUI; import com.loohp.limbo.GUI.GUI;
import com.loohp.limbo.Location.Location; import com.loohp.limbo.Location.Location;
import com.loohp.limbo.Metrics.Metrics;
import com.loohp.limbo.Permissions.PermissionsManager; import com.loohp.limbo.Permissions.PermissionsManager;
import com.loohp.limbo.Player.Player; import com.loohp.limbo.Player.Player;
import com.loohp.limbo.Plugins.LimboPlugin; import com.loohp.limbo.Plugins.LimboPlugin;
@ -97,8 +100,8 @@ public class Limbo {
//=========================== //===========================
public final String serverImplementationVersion = "1.16.2"; public final String serverImplementationVersion = "1.16.3";
public final int serverImplmentationProtocol = 751; public final int serverImplmentationProtocol = 753;
private ServerConnection server; private ServerConnection server;
private Console console; private Console console;
@ -118,6 +121,8 @@ public class Limbo {
private DimensionRegistry dimensionRegistry; private DimensionRegistry dimensionRegistry;
private Metrics metrics;
public AtomicInteger entityIdCount = new AtomicInteger(); public AtomicInteger entityIdCount = new AtomicInteger();
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -136,6 +141,8 @@ public class Limbo {
console = new Console(System.in, System.out, System.err); console = new Console(System.in, System.out, System.err);
} }
console.sendMessage("Loading Limbo Version " + new BufferedReader(new InputStreamReader(Limbo.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF"))).lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst().orElse("Limbo-Version: unknown").substring(14).trim());
String spName = "server.properties"; String spName = "server.properties";
File sp = new File(spName); File sp = new File(spName);
if (!sp.exists()) { if (!sp.exists()) {
@ -283,6 +290,8 @@ public class Limbo {
server = new ServerConnection(properties.getServerIp(), properties.getServerPort()); server = new ServerConnection(properties.getServerIp(), properties.getServerPort());
metrics = new Metrics();
console.run(); console.run();
} }
@ -354,6 +363,10 @@ public class Limbo {
return console; return console;
} }
public Metrics getMetrics() {
return metrics;
}
public Set<Player> getPlayers() { public Set<Player> getPlayers() {
return new HashSet<>(playersByUUID.values()); return new HashSet<>(playersByUUID.values());
} }

View File

@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
@ -15,6 +16,7 @@ import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -33,38 +35,40 @@ import com.loohp.limbo.File.FileConfiguration;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class Metrics { public class Metrics {
static {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's' });
final String examplePackage = new String(new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' });
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
// The version of this bStats class // The version of this bStats class
public static final int B_STATS_VERSION = 1; public static final int B_STATS_VERSION = 1;
// The url to which the data is sent // The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit"; private static final String URL = "https://bStats.org/submitData/server-implementation";
// Should failed requests be logged? // Should failed requests be logged?
private static boolean logFailedRequests; private static boolean logFailedRequests = false;
// The name of the server software
private final String name;
// The uuid of the server // The uuid of the server
private static String serverUUID; private final String serverUUID;
private final String limboVersion;
// A list with all custom charts // A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>(); private final List<CustomChart> charts = new ArrayList<>();
/** /**
* Class constructor. * Class constructor.
*
* @param name The name of the server software.
* @param serverUUID The uuid of the server.
* @param logFailedRequests Whether failed requests should be logged or not.
* @param logger The logger for the failed requests.
* @throws FileNotFoundException
*/ */
public Metrics() { public Metrics() throws FileNotFoundException {
name = "Limbo";
// Get the config file // Get the config file
File configFile = new File(new File("plugins", "bStats"), "config.yml"); File configFile = new File("plugins/bStats", "config.yml");
FileConfiguration config = new FileConfiguration(configFile); FileConfiguration config = new FileConfiguration(configFile);
// Check if the config file exists // Check if the config file exists
@ -86,8 +90,12 @@ public class Metrics {
); );
try { try {
config.saveConfig(configFile); config.saveConfig(configFile);
} catch (IOException ignored) {} } catch (IOException e) {
e.printStackTrace();
} }
}
limboVersion = new BufferedReader(new InputStreamReader(Limbo.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF"))).lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst().orElse("Limbo-Version: unknown").substring(14).trim();
// Load the data // Load the data
serverUUID = config.get("serverUuid", String.class); serverUUID = config.get("serverUuid", String.class);
@ -95,6 +103,20 @@ public class Metrics {
if (config.get("enabled", Boolean.class)) { if (config.get("enabled", Boolean.class)) {
startSubmitting(); startSubmitting();
} }
addCustomChart(new Metrics.SingleLineChart("players", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return Limbo.getInstance().getPlayers().size();
}
}));
addCustomChart(new Metrics.SimplePie("limbo_version", new Callable<String>() {
@Override
public String call() throws Exception {
return limboVersion;
}
}));
} }
/** /**
@ -130,14 +152,10 @@ public class Metrics {
* *
* @return The plugin specific data. * @return The plugin specific data.
*/ */
public JSONObject getPluginData() { private JSONObject getPluginData() {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
String pluginName = "Limbo"; data.put("pluginName", name); // Append the name of the server software
String pluginVersion = new BufferedReader(new InputStreamReader(Limbo.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF"))).lines().filter(each -> each.startsWith("Limbo-Version:")).findFirst().orElse("Limbo-Version: unknown").substring(14).trim();
data.put("pluginName", pluginName); // Append the name of the plugin
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
JSONArray customCharts = new JSONArray(); JSONArray customCharts = new JSONArray();
for (CustomChart customChart : charts) { for (CustomChart customChart : charts) {
// Add the data of the custom charts // Add the data of the custom charts
@ -158,14 +176,7 @@ public class Metrics {
* @return The server specific data. * @return The server specific data.
*/ */
private JSONObject getServerData() { private JSONObject getServerData() {
// Minecraft specific data // OS specific data
int playerAmount = Limbo.getInstance().getPlayers().size();
int onlineMode = 0;
String limboVersion = Limbo.getInstance().serverImplementationVersion;
limboVersion = limboVersion.substring(limboVersion.indexOf("MC: ") + 4, limboVersion.length() - 1);
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch"); String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version"); String osVersion = System.getProperty("os.version");
@ -175,11 +186,7 @@ public class Metrics {
data.put("serverUUID", serverUUID); data.put("serverUUID", serverUUID);
data.put("playerAmount", playerAmount); data.put("playerAmount", Limbo.getInstance().getPlayers().size());
data.put("onlineMode", onlineMode);
data.put("limboVersion", limboVersion);
data.put("javaVersion", javaVersion);
data.put("osName", osName); data.put("osName", osName);
data.put("osArch", osArch); data.put("osArch", osArch);
data.put("osVersion", osVersion); data.put("osVersion", osVersion);
@ -195,21 +202,18 @@ public class Metrics {
final JSONObject data = getServerData(); final JSONObject data = getServerData();
JSONArray pluginData = new JSONArray(); JSONArray pluginData = new JSONArray();
pluginData.add(this.getPluginData()); pluginData.add(getPluginData());
data.put("plugins", pluginData); data.put("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try { try {
// Send the data // We are still in the Thread of the timer, so nothing get blocked :)
sendData(data); sendData(data);
} catch (Exception e) { } catch (Exception e) {
// Something went wrong! :( // Something went wrong! :(
if (logFailedRequests) { if (logFailedRequests) {
System.err.println("Could not submit stats for Limbo " + e); Limbo.getInstance().getConsole().sendMessage("Could not submit stats of " + name + "\n" + e);
} }
} }
}, "Limbo Metrics Submission Thread").start();
} }
/** /**
@ -270,21 +274,21 @@ public class Metrics {
public static abstract class CustomChart { public static abstract class CustomChart {
// The id of the chart // The id of the chart
protected final String chartId; final String chartId;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
*/ */
public CustomChart(String chartId) { CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) { if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!"); throw new IllegalArgumentException("ChartId cannot be null or empty!");
} }
this.chartId = chartId; this.chartId = chartId;
} }
protected JSONObject getRequestJsonObject() { private JSONObject getRequestJsonObject() {
JSONObject chart = new JSONObject(); JSONObject chart = new JSONObject();
chart.put("chartId", chartId); chart.put("chartId", chartId);
try { try {
@ -296,42 +300,39 @@ public class Metrics {
chart.put("data", data); chart.put("data", data);
} catch (Throwable t) { } catch (Throwable t) {
if (logFailedRequests) { if (logFailedRequests) {
System.err.println("Failed to get data for custom chart with id " + chartId + t); Limbo.getInstance().getConsole().sendMessage("Failed to get data for custom chart with id " + chartId + "\n" + t);
} }
return null; return null;
} }
return chart; return chart;
} }
protected abstract JSONObject getChartData(); protected abstract JSONObject getChartData() throws Exception;
} }
/** /**
* Represents a custom simple pie. * Represents a custom simple pie.
*/ */
public static abstract class SimplePie extends CustomChart { public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public SimplePie(String chartId) { public SimplePie(String chartId, Callable<String> callable) {
super(chartId); super(chartId);
this.callable = callable;
} }
/**
* Gets the value of the pie.
*
* @return The value of the pie.
*/
public abstract String getValue();
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
String value = getValue(); String value = callable.call();
if (value == null || value.isEmpty()) { if (value == null || value.isEmpty()) {
// Null = skip the chart // Null = skip the chart
return null; return null;
@ -344,31 +345,26 @@ public class Metrics {
/** /**
* Represents a custom advanced pie. * Represents a custom advanced pie.
*/ */
public static abstract class AdvancedPie extends CustomChart { public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public AdvancedPie(String chartId) { public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId); super(chartId);
this.callable = callable;
} }
/**
* Gets the values of the pie.
*
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
* You don't have to create a map yourself!
* @return The values of the pie.
*/
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
JSONObject values = new JSONObject(); JSONObject values = new JSONObject();
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>()); Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) { if (map == null || map.isEmpty()) {
// Null = skip the chart // Null = skip the chart
return null; return null;
@ -391,30 +387,76 @@ public class Metrics {
} }
/** /**
* Represents a custom single line chart. * Represents a custom drilldown pie.
*/ */
public static abstract class SingleLineChart extends CustomChart { public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public SingleLineChart(String chartId) { public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId); super(chartId);
this.callable = callable;
}
@Override
public JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JSONObject value = new JSONObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.put(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.put(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
} }
/** /**
* Gets the value of the chart. * Represents a custom single line chart.
*
* @return The value of the chart.
*/ */
public abstract int getValue(); public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
int value = getValue(); int value = callable.call();
if (value == 0) { if (value == 0) {
// Null = skip the chart // Null = skip the chart
return null; return null;
@ -428,31 +470,26 @@ public class Metrics {
/** /**
* Represents a custom multi line chart. * Represents a custom multi line chart.
*/ */
public static abstract class MultiLineChart extends CustomChart { public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public MultiLineChart(String chartId) { public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId); super(chartId);
this.callable = callable;
} }
/**
* Gets the values of the chart.
*
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
* You don't have to create a map yourself!
* @return The values of the chart.
*/
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
JSONObject values = new JSONObject(); JSONObject values = new JSONObject();
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>()); Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) { if (map == null || map.isEmpty()) {
// Null = skip the chart // Null = skip the chart
return null; return null;
@ -478,31 +515,26 @@ public class Metrics {
/** /**
* Represents a custom simple bar chart. * Represents a custom simple bar chart.
*/ */
public static abstract class SimpleBarChart extends CustomChart { public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public SimpleBarChart(String chartId) { public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId); super(chartId);
this.callable = callable;
} }
/**
* Gets the value of the chart.
*
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
* You don't have to create a map yourself!
* @return The value of the chart.
*/
public abstract HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap);
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
JSONObject values = new JSONObject(); JSONObject values = new JSONObject();
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>()); Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) { if (map == null || map.isEmpty()) {
// Null = skip the chart // Null = skip the chart
return null; return null;
@ -521,31 +553,26 @@ public class Metrics {
/** /**
* Represents a custom advanced bar chart. * Represents a custom advanced bar chart.
*/ */
public static abstract class AdvancedBarChart extends CustomChart { public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/** /**
* Class constructor. * Class constructor.
* *
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/ */
public AdvancedBarChart(String chartId) { public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId); super(chartId);
this.callable = callable;
} }
/**
* Gets the value of the chart.
*
* @param valueMap Just an empty map. The only reason it exists is to make your life easier.
* You don't have to create a map yourself!
* @return The value of the chart.
*/
public abstract HashMap<String, int[]> getValues(HashMap<String, int[]> valueMap);
@Override @Override
protected JSONObject getChartData() { protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
JSONObject values = new JSONObject(); JSONObject values = new JSONObject();
HashMap<String, int[]> map = getValues(new HashMap<String, int[]>()); Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) { if (map == null || map.isEmpty()) {
// Null = skip the chart // Null = skip the chart
return null; return null;

View File

@ -43,6 +43,7 @@ public class PluginManager {
if (name.endsWith("plugin.yml") || name.endsWith("limbo.yml")) { if (name.endsWith("plugin.yml") || name.endsWith("limbo.yml")) {
found = true; found = true;
@SuppressWarnings("deprecation")
FileConfiguration pluginYaml = new FileConfiguration(zip); FileConfiguration pluginYaml = new FileConfiguration(zip);
String main = pluginYaml.get("main", String.class); String main = pluginYaml.get("main", String.class);
String pluginName = pluginYaml.get("name", String.class); String pluginName = pluginYaml.get("name", String.class);