1.4.0 & 1.4.1
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<groupId>us.ajg0702</groupId>
|
<groupId>us.ajg0702</groupId>
|
||||||
<artifactId>ajQueue</artifactId>
|
<artifactId>ajQueue</artifactId>
|
||||||
<name>ajQueue</name>
|
<name>ajQueue</name>
|
||||||
<version>1.3.8</version>
|
<version>1.4.1</version>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>us.ajg0702</groupId>
|
<groupId>us.ajg0702</groupId>
|
||||||
<artifactId>ajQueue</artifactId>
|
<artifactId>ajQueue</artifactId>
|
||||||
<version>1.3.8</version>
|
<version>1.4.1</version>
|
||||||
<name>ajQueue</name>
|
<name>ajQueue</name>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@@ -68,7 +70,12 @@ public class Main extends Plugin implements Listener {
|
|||||||
|
|
||||||
|
|
||||||
metrics = new BungeeStats(this, 7404);
|
metrics = new BungeeStats(this, 7404);
|
||||||
|
metrics.addCustomChart(new BungeeStats.SimplePie("premium", new Callable<String>() {
|
||||||
|
@Override
|
||||||
|
public String call() throws Exception {
|
||||||
|
return isp+"";
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -339,12 +339,21 @@ public class Manager {
|
|||||||
}
|
}
|
||||||
int pos = list.indexOf(p)+1;
|
int pos = list.indexOf(p)+1;
|
||||||
int len = list.size();
|
int len = list.size();
|
||||||
|
if(list.size() <= 1) {
|
||||||
|
p.sendMessage(Main.formatMessage(
|
||||||
|
msgs.get("status.now-in-empty-queue")
|
||||||
|
.replaceAll("\\{POS\\}", pos+"")
|
||||||
|
.replaceAll("\\{LEN\\}", len+"")
|
||||||
|
.replaceAll("\\{SERVER\\}", s)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
p.sendMessage(Main.formatMessage(
|
p.sendMessage(Main.formatMessage(
|
||||||
msgs.get("status.now-in-queue")
|
msgs.get("status.now-in-queue")
|
||||||
.replaceAll("\\{POS\\}", pos+"")
|
.replaceAll("\\{POS\\}", pos+"")
|
||||||
.replaceAll("\\{LEN\\}", len+"")
|
.replaceAll("\\{LEN\\}", len+"")
|
||||||
.replaceAll("\\{SERVER\\}", s)
|
.replaceAll("\\{SERVER\\}", s)
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
BungeeUtils.sendCustomData(p, "position", pos+"");
|
BungeeUtils.sendCustomData(p, "position", pos+"");
|
||||||
BungeeUtils.sendCustomData(p, "positionof", len+"");
|
BungeeUtils.sendCustomData(p, "positionof", len+"");
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
VersionSupport.sendActionBar(p, text);
|
VersionSupport.sendActionBar(p, text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(subchannel.equals("queuename")) {
|
if(subchannel.equals("queuename") && papi) {
|
||||||
String playername = in.readUTF();
|
String playername = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(playername);
|
Player p = Bukkit.getPlayer(playername);
|
||||||
if(p == null) return;
|
if(p == null) return;
|
||||||
@@ -70,7 +70,7 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
phs.put("queued", data);
|
phs.put("queued", data);
|
||||||
placeholders.responseCache.put(p, phs);
|
placeholders.responseCache.put(p, phs);
|
||||||
}
|
}
|
||||||
if(subchannel.equals("position")) {
|
if(subchannel.equals("position") && papi) {
|
||||||
String playername = in.readUTF();
|
String playername = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(playername);
|
Player p = Bukkit.getPlayer(playername);
|
||||||
if(p == null) return;
|
if(p == null) return;
|
||||||
@@ -82,7 +82,7 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
phs.put("position", data);
|
phs.put("position", data);
|
||||||
placeholders.responseCache.put(p, phs);
|
placeholders.responseCache.put(p, phs);
|
||||||
}
|
}
|
||||||
if(subchannel.equals("positionof")) {
|
if(subchannel.equals("positionof") && papi) {
|
||||||
String playername = in.readUTF();
|
String playername = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(playername);
|
Player p = Bukkit.getPlayer(playername);
|
||||||
if(p == null) return;
|
if(p == null) return;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class BungeeMessages {
|
|||||||
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
|
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
|
||||||
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
|
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
|
||||||
d.put("status.now-in-queue", "&aYou are now queued! &7You are in position &f{POS}&7 of &f{LEN}&7.\n&7Type &f/leavequeue&7 to leave the queue!");
|
d.put("status.now-in-queue", "&aYou are now queued! &7You are in position &f{POS}&7 of &f{LEN}&7.\n&7Type &f/leavequeue&7 to leave the queue!");
|
||||||
|
d.put("status.now-in-empty-queue", "");
|
||||||
|
|
||||||
d.put("errors.server-not-exist", "&cThat server does not exist!");
|
d.put("errors.server-not-exist", "&cThat server does not exist!");
|
||||||
d.put("errors.already-queued", "&cYou are already queued for that server!");
|
d.put("errors.already-queued", "&cYou are already queued for that server!");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package us.ajg0702.queue.utils;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
@@ -14,9 +15,12 @@ import java.net.URL;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,6 +28,7 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
* <p>
|
* <p>
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
* Check out https://bStats.org/ to learn more about bStats!
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||||
public class BungeeStats {
|
public class BungeeStats {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -70,6 +75,9 @@ public class BungeeStats {
|
|||||||
// A list with all known metrics class objects including this one
|
// A list with all known metrics class objects including this one
|
||||||
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
||||||
|
|
||||||
|
// A list with all custom charts
|
||||||
|
private final List<CustomChart> charts = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
@@ -124,6 +132,18 @@ public class BungeeStats {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom chart.
|
||||||
|
*
|
||||||
|
* @param chart The chart to add.
|
||||||
|
*/
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
if (chart == null) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Chart cannot be null");
|
||||||
|
}
|
||||||
|
charts.add(chart);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Links an other metrics class with this class.
|
* Links an other metrics class with this class.
|
||||||
* This method is called using Reflection.
|
* This method is called using Reflection.
|
||||||
@@ -151,6 +171,14 @@ public class BungeeStats {
|
|||||||
data.addProperty("pluginVersion", pluginVersion);
|
data.addProperty("pluginVersion", pluginVersion);
|
||||||
|
|
||||||
JsonArray customCharts = new JsonArray();
|
JsonArray customCharts = new JsonArray();
|
||||||
|
for (CustomChart customChart : charts) {
|
||||||
|
// Add the data of the custom charts
|
||||||
|
JsonObject chart = customChart.getRequestJsonObject(plugin.getLogger(), logFailedRequests);
|
||||||
|
if (chart == null) { // If the chart is null, we skip it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
customCharts.add(chart);
|
||||||
|
}
|
||||||
data.add("customCharts", customCharts);
|
data.add("customCharts", customCharts);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -170,7 +198,6 @@ public class BungeeStats {
|
|||||||
*
|
*
|
||||||
* @return The server specific data.
|
* @return The server specific data.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private JsonObject getServerData() {
|
private JsonObject getServerData() {
|
||||||
// Minecraft specific data
|
// Minecraft specific data
|
||||||
int playerAmount = Math.min(plugin.getProxy().getOnlineCount(), 500);
|
int playerAmount = Math.min(plugin.getProxy().getOnlineCount(), 500);
|
||||||
@@ -361,6 +388,7 @@ public class BungeeStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
@@ -391,4 +419,336 @@ public class BungeeStats {
|
|||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom chart.
|
||||||
|
*/
|
||||||
|
public static abstract class CustomChart {
|
||||||
|
|
||||||
|
// The id of the chart
|
||||||
|
private final String chartId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
*/
|
||||||
|
CustomChart(String chartId) {
|
||||||
|
if (chartId == null || chartId.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||||
|
}
|
||||||
|
this.chartId = chartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) {
|
||||||
|
JsonObject chart = new JsonObject();
|
||||||
|
chart.addProperty("chartId", chartId);
|
||||||
|
try {
|
||||||
|
JsonObject data = getChartData();
|
||||||
|
if (data == null) {
|
||||||
|
// If the data is null we don't send the chart.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
chart.add("data", data);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (logFailedRequests) {
|
||||||
|
logger.log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JsonObject getChartData() throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom simple pie.
|
||||||
|
*/
|
||||||
|
public static class SimplePie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<String> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimplePie(String chartId, Callable<String> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
String value = callable.call();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.addProperty("value", value);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom advanced pie.
|
||||||
|
*/
|
||||||
|
public static class AdvancedPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
JsonObject values = new JsonObject();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
continue; // Skip this invalid
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
values.addProperty(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.add("values", values);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom drilldown pie.
|
||||||
|
*/
|
||||||
|
public static class DrilldownPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||||
|
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.addProperty(valueEntry.getKey(), valueEntry.getValue());
|
||||||
|
allSkipped = false;
|
||||||
|
}
|
||||||
|
if (!allSkipped) {
|
||||||
|
reallyAllSkipped = false;
|
||||||
|
values.add(entryValues.getKey(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reallyAllSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.add("values", values);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom single line chart.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
int value = callable.call();
|
||||||
|
if (value == 0) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.addProperty("value", value);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom multi line chart.
|
||||||
|
*/
|
||||||
|
public static class MultiLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
JsonObject values = new JsonObject();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
continue; // Skip this invalid
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
values.addProperty(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.add("values", values);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom simple bar chart.
|
||||||
|
*/
|
||||||
|
public static class SimpleBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
JsonObject values = new JsonObject();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
JsonArray categoryValues = new JsonArray();
|
||||||
|
categoryValues.add(new JsonPrimitive(entry.getValue()));
|
||||||
|
values.add(entry.getKey(), categoryValues);
|
||||||
|
}
|
||||||
|
data.add("values", values);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom advanced bar chart.
|
||||||
|
*/
|
||||||
|
public static class AdvancedBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, int[]>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObject getChartData() throws Exception {
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
JsonObject values = new JsonObject();
|
||||||
|
Map<String, int[]> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue().length == 0) {
|
||||||
|
continue; // Skip this invalid
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
JsonArray categoryValues = new JsonArray();
|
||||||
|
for (int categoryValue : entry.getValue()) {
|
||||||
|
categoryValues.add(new JsonPrimitive(categoryValue));
|
||||||
|
}
|
||||||
|
values.add(entry.getKey(), categoryValues);
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
data.add("values", values);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
main: us.ajg0702.queue.spigot.Main
|
main: us.ajg0702.queue.spigot.Main
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
|
api-version: 1.13
|
||||||
author: ajgeiss0702
|
author: ajgeiss0702
|
||||||
name: ajQueue
|
name: ajQueue
|
||||||
softdepend: [PlaceholderAPI]
|
softdepend: [PlaceholderAPI]
|
||||||
|
|||||||
Reference in New Issue
Block a user