1.21.2
This commit is contained in:
parent
750b549533
commit
587f0567d8
7 changed files with 272 additions and 251 deletions
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>pk.ajneb97</groupId>
|
<groupId>pk.ajneb97</groupId>
|
||||||
<artifactId>PlayerKits2</artifactId>
|
<artifactId>PlayerKits2</artifactId>
|
||||||
<version>1.21.1</version>
|
<version>1.21.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ public class TitleAPI implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PlayerKitsAPI.getPlugin().getConfigsManager().getMainConfigManager().isUseMiniMessage()){
|
if(PlayerKitsAPI.getPlugin().getConfigsManager().getMainConfigManager().isUseMiniMessage()){
|
||||||
MiniMessageUtils.title(player,title,subtitle);
|
MiniMessageUtils.title(player,title,subtitle,fadeIn,stay,fadeOut);
|
||||||
}else{
|
}else{
|
||||||
player.sendTitle(MessagesManager.getLegacyColoredMessage(title), MessagesManager.getLegacyColoredMessage(subtitle), fadeIn, stay, fadeOut);
|
player.sendTitle(MessagesManager.getLegacyColoredMessage(title), MessagesManager.getLegacyColoredMessage(subtitle), fadeIn, stay, fadeOut);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -347,20 +347,24 @@ public class InventoryManager {
|
||||||
newStatus = "default";
|
newStatus = "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kitItem = kitItem.clone();
|
||||||
|
|
||||||
boolean useMiniMessage = plugin.getConfigsManager().getMainConfigManager().isUseMiniMessage();
|
boolean useMiniMessage = plugin.getConfigsManager().getMainConfigManager().isUseMiniMessage();
|
||||||
if(newStatus.equals(currentStatus) && currentItem != null){
|
if(newStatus.equals(currentStatus) && currentItem != null){
|
||||||
// Name and Lore update
|
// Name and Lore update
|
||||||
|
kitItemManager.replaceVariables(kitItem,variablesToReplace,player);
|
||||||
|
|
||||||
ItemMeta meta = currentItem.getItemMeta();
|
ItemMeta meta = currentItem.getItemMeta();
|
||||||
|
|
||||||
String name = kitItem.getName();
|
String name = kitItem.getName();
|
||||||
if(name != null){
|
if(name != null){
|
||||||
name = OtherUtils.replaceGlobalVariables(name,player,plugin);
|
|
||||||
if(useMiniMessage){
|
if(useMiniMessage){
|
||||||
MiniMessageUtils.setItemName(meta,name);
|
MiniMessageUtils.setItemName(meta,name);
|
||||||
}else{
|
}else{
|
||||||
meta.setDisplayName(MessagesManager.getLegacyColoredMessage(name));
|
meta.setDisplayName(MessagesManager.getLegacyColoredMessage(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore = kitItem.getLore();
|
List<String> lore = kitItem.getLore();
|
||||||
if(lore != null) {
|
if(lore != null) {
|
||||||
List<String> loreCopy = new ArrayList<>(lore);
|
List<String> loreCopy = new ArrayList<>(lore);
|
||||||
|
|
@ -374,13 +378,12 @@ public class InventoryManager {
|
||||||
meta.setLore(loreCopy);
|
meta.setLore(loreCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentItem.setItemMeta(meta);
|
|
||||||
|
|
||||||
kitItemManager.replaceVariables(currentItem,variablesToReplace);
|
currentItem.setItemMeta(meta);
|
||||||
}else{
|
}else{
|
||||||
// Full update
|
// Full update
|
||||||
|
kitItemManager.replaceVariables(kitItem,variablesToReplace,player);
|
||||||
ItemStack item = kitItemManager.createItemFromKitItem(kitItem,player,kit);
|
ItemStack item = kitItemManager.createItemFromKitItem(kitItem,player,kit);
|
||||||
kitItemManager.replaceVariables(item,variablesToReplace);
|
|
||||||
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_kit", kitName);
|
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_kit", kitName);
|
||||||
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_kit_status", newStatus);
|
item = ItemUtils.setTagStringItem(plugin,item, "playerkits_kit_status", newStatus);
|
||||||
inv.setItem(slot,item);
|
inv.setItem(slot,item);
|
||||||
|
|
|
||||||
|
|
@ -811,39 +811,26 @@ public class KitItemManager {
|
||||||
return kitItem;
|
return kitItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceVariables(ItemStack item, ArrayList<KitVariable> variables){
|
public void replaceVariables(KitItem commonItem, ArrayList<KitVariable> variables, Player player){
|
||||||
boolean useMiniMessage = plugin.getConfigsManager().getMainConfigManager().isUseMiniMessage();
|
if(commonItem.getName() != null){
|
||||||
if(item.hasItemMeta()){
|
String newName = commonItem.getName();
|
||||||
ItemMeta meta = item.getItemMeta();
|
for(KitVariable variable : variables){
|
||||||
if(meta.hasDisplayName()){
|
newName = newName.replace(variable.getVariable(),variable.getValue());
|
||||||
if(useMiniMessage){
|
|
||||||
MiniMessageUtils.replaceVariablesItemName(meta,variables);
|
|
||||||
}else{
|
|
||||||
String newName = meta.getDisplayName();
|
|
||||||
for(KitVariable variable : variables){
|
|
||||||
newName = newName.replace(variable.getVariable(),variable.getValue());
|
|
||||||
}
|
|
||||||
meta.setDisplayName(MessagesManager.getLegacyColoredMessage(newName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
newName = OtherUtils.replaceGlobalVariables(newName,player,plugin);
|
||||||
|
commonItem.setName(newName);
|
||||||
|
}
|
||||||
|
|
||||||
if(meta.hasLore()){
|
if(commonItem.getLore() != null){
|
||||||
if(useMiniMessage){
|
List<String> lore = commonItem.getLore();
|
||||||
MiniMessageUtils.replaceVariablesItemLore(meta,variables);
|
for(int i=0;i<lore.size();i++){
|
||||||
}else{
|
for(KitVariable variable : variables){
|
||||||
List<String> lore = meta.getLore();
|
String line = lore.get(i).replace(variable.getVariable(),variable.getValue());
|
||||||
for(int i=0;i<lore.size();i++){
|
line = OtherUtils.replaceGlobalVariables(line,player,plugin);
|
||||||
for(KitVariable variable : variables){
|
lore.set(i,line);
|
||||||
String line = lore.get(i).replace(variable.getVariable(),variable.getValue());
|
|
||||||
lore.set(i,MessagesManager.getLegacyColoredMessage(line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
meta.setLore(lore);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item.setItemMeta(meta);
|
commonItem.setLore(lore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,19 @@
|
||||||
package pk.ajneb97.managers.dependencies;
|
package pk.ajneb97.managers.dependencies;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This Metrics class was auto-generated and can be copied into your project if you are
|
||||||
|
* not using a build tool like Gradle or Maven for dependency management.
|
||||||
|
*
|
||||||
|
* IMPORTANT: You are not allowed to modify this class, except changing the package.
|
||||||
|
*
|
||||||
|
* Disallowed modifications include but are not limited to:
|
||||||
|
* - Remove the option for users to opt-out
|
||||||
|
* - Change the frequency for data submission
|
||||||
|
* - Obfuscate the code (every obfuscator should allow you to make an exception for specific files)
|
||||||
|
* - Reformat the code (if you use a linter, add an exception)
|
||||||
|
*
|
||||||
|
* Violations will result in a ban of your plugin and account from bStats.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* This Metrics class was auto-generated and can be copied into your project if you are
|
* This Metrics class was auto-generated and can be copied into your project if you are
|
||||||
* not using a build tool like Gradle or Maven for dependency management.
|
* not using a build tool like Gradle or Maven for dependency management.
|
||||||
|
|
@ -15,18 +29,22 @@ package pk.ajneb97.managers.dependencies;
|
||||||
* Violations will result in a ban of your plugin and account from bStats.
|
* Violations will result in a ban of your plugin and account from bStats.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import java.io.BufferedReader;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import java.io.ByteArrayOutputStream;
|
||||||
import org.bukkit.entity.Player;
|
import java.io.DataOutputStream;
|
||||||
import org.bukkit.plugin.Plugin;
|
import java.io.File;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
|
@ -37,6 +55,11 @@ import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
|
||||||
|
|
@ -51,7 +74,7 @@ public class Metrics {
|
||||||
* @param serviceId The id of the service. It can be found at <a
|
* @param serviceId The id of the service. It can be found at <a
|
||||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||||
*/
|
*/
|
||||||
public Metrics(JavaPlugin plugin, int serviceId) {
|
public Metrics(Plugin plugin, int serviceId) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
// Get the config file
|
// Get the config file
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||||
|
|
@ -71,7 +94,8 @@ public class Metrics {
|
||||||
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
||||||
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
||||||
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
||||||
+ "anonymous.")
|
+ "anonymous.\n"
|
||||||
|
+ "Learn more here: https://bstats.org/docs/server-owners")
|
||||||
.copyDefaults(true);
|
.copyDefaults(true);
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
|
|
@ -84,21 +108,36 @@ public class Metrics {
|
||||||
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||||
boolean logSentData = config.getBoolean("logSentData", false);
|
boolean logSentData = config.getBoolean("logSentData", false);
|
||||||
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||||
|
boolean isFolia = false;
|
||||||
|
try {
|
||||||
|
isFolia = Class.forName("io.papermc.paper.threadedregions.RegionizedServer") != null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
metricsBase =
|
metricsBase =
|
||||||
new MetricsBase(
|
new // See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
// See https://github.com/Bastian/bstats-metrics/pull/126
|
||||||
|
MetricsBase(
|
||||||
"bukkit",
|
"bukkit",
|
||||||
serverUUID,
|
serverUUID,
|
||||||
serviceId,
|
serviceId,
|
||||||
enabled,
|
enabled,
|
||||||
this::appendPlatformData,
|
this::appendPlatformData,
|
||||||
this::appendServiceData,
|
this::appendServiceData,
|
||||||
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
isFolia
|
||||||
|
? null
|
||||||
|
: submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||||
plugin::isEnabled,
|
plugin::isEnabled,
|
||||||
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||||
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||||
logErrors,
|
logErrors,
|
||||||
logSentData,
|
logSentData,
|
||||||
logResponseStatusText);
|
logResponseStatusText,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Shuts down the underlying scheduler service. */
|
/** Shuts down the underlying scheduler service. */
|
||||||
|
|
@ -149,7 +188,7 @@ public class Metrics {
|
||||||
public static class MetricsBase {
|
public static class MetricsBase {
|
||||||
|
|
||||||
/** The version of the Metrics class. */
|
/** The version of the Metrics class. */
|
||||||
public static final String METRICS_VERSION = "3.0.2";
|
public static final String METRICS_VERSION = "3.2.1";
|
||||||
|
|
||||||
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||||
|
|
||||||
|
|
@ -203,6 +242,7 @@ public class Metrics {
|
||||||
* @param logErrors Whether or not errors should be logged.
|
* @param logErrors Whether or not errors should be logged.
|
||||||
* @param logSentData Whether or not the sent data should be logged.
|
* @param logSentData Whether or not the sent data should be logged.
|
||||||
* @param logResponseStatusText Whether or not the response status text should be logged.
|
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||||
|
* @param skipRelocateCheck Whether or not the relocate check should be skipped.
|
||||||
*/
|
*/
|
||||||
public MetricsBase(
|
public MetricsBase(
|
||||||
String platform,
|
String platform,
|
||||||
|
|
@ -217,9 +257,16 @@ public class Metrics {
|
||||||
Consumer<String> infoLogger,
|
Consumer<String> infoLogger,
|
||||||
boolean logErrors,
|
boolean logErrors,
|
||||||
boolean logSentData,
|
boolean logSentData,
|
||||||
boolean logResponseStatusText) {
|
boolean logResponseStatusText,
|
||||||
|
boolean skipRelocateCheck) {
|
||||||
ScheduledThreadPoolExecutor scheduler =
|
ScheduledThreadPoolExecutor scheduler =
|
||||||
new ScheduledThreadPoolExecutor(1, task -> new Thread(task, "bStats-Metrics"));
|
new ScheduledThreadPoolExecutor(
|
||||||
|
1,
|
||||||
|
task -> {
|
||||||
|
Thread thread = new Thread(task, "bStats-Metrics");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
// We want delayed tasks (non-periodic) that will execute in the future to be
|
// We want delayed tasks (non-periodic) that will execute in the future to be
|
||||||
// cancelled when the scheduler is shutdown.
|
// cancelled when the scheduler is shutdown.
|
||||||
// Otherwise, we risk preventing the server from shutting down even when
|
// Otherwise, we risk preventing the server from shutting down even when
|
||||||
|
|
@ -239,7 +286,9 @@ public class Metrics {
|
||||||
this.logErrors = logErrors;
|
this.logErrors = logErrors;
|
||||||
this.logSentData = logSentData;
|
this.logSentData = logSentData;
|
||||||
this.logResponseStatusText = logResponseStatusText;
|
this.logResponseStatusText = logResponseStatusText;
|
||||||
checkRelocation();
|
if (!skipRelocateCheck) {
|
||||||
|
checkRelocation();
|
||||||
|
}
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// WARNING: Removing the option to opt-out will get your plugin banned from
|
// WARNING: Removing the option to opt-out will get your plugin banned from
|
||||||
// bStats
|
// bStats
|
||||||
|
|
@ -303,7 +352,6 @@ public class Metrics {
|
||||||
scheduler.execute(
|
scheduler.execute(
|
||||||
() -> {
|
() -> {
|
||||||
try {
|
try {
|
||||||
// Send the data
|
|
||||||
sendData(data);
|
sendData(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Something went wrong! :(
|
// Something went wrong! :(
|
||||||
|
|
@ -384,9 +432,43 @@ public class Metrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SimplePie extends CustomChart {
|
public abstract static class CustomChart {
|
||||||
|
|
||||||
private final Callable<String> callable;
|
private final String chartId;
|
||||||
|
|
||||||
|
protected CustomChart(String chartId) {
|
||||||
|
if (chartId == null) {
|
||||||
|
throw new IllegalArgumentException("chartId must not be null");
|
||||||
|
}
|
||||||
|
this.chartId = chartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||||
|
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||||
|
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||||
|
builder.appendField("chartId", chartId);
|
||||||
|
try {
|
||||||
|
JsonObjectBuilder.JsonObject data = getChartData();
|
||||||
|
if (data == null) {
|
||||||
|
// If the data is null we don't send the chart.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
builder.appendField("data", data);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SingleLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Integer> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
|
|
@ -394,15 +476,15 @@ public class Metrics {
|
||||||
* @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.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public SimplePie(String chartId, Callable<String> callable) {
|
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
String value = callable.call();
|
int value = callable.call();
|
||||||
if (value == null || value.isEmpty()) {
|
if (value == 0) {
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -410,6 +492,120 @@ public class Metrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
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()) {
|
||||||
|
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||||
|
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||||
|
allSkipped = false;
|
||||||
|
}
|
||||||
|
if (!allSkipped) {
|
||||||
|
reallyAllSkipped = false;
|
||||||
|
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reallyAllSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
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) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
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()) {
|
||||||
|
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class MultiLineChart extends CustomChart {
|
public static class MultiLineChart extends CustomChart {
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
@ -490,9 +686,9 @@ public class Metrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SimpleBarChart extends CustomChart {
|
public static class SimplePie extends CustomChart {
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
private final Callable<String> callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
|
|
@ -500,163 +696,15 @@ public class Metrics {
|
||||||
* @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.
|
* @param callable The callable which is used to request the chart data.
|
||||||
*/
|
*/
|
||||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
public SimplePie(String chartId, Callable<String> callable) {
|
||||||
super(chartId);
|
super(chartId);
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
String value = callable.call();
|
||||||
Map<String, Integer> map = callable.call();
|
if (value == null || value.isEmpty()) {
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
||||||
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
|
|
||||||
}
|
|
||||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
|
||||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
|
||||||
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) {
|
|
||||||
// Skip this invalid
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
allSkipped = false;
|
|
||||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
if (allSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
|
||||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
|
||||||
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()) {
|
|
||||||
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
|
||||||
boolean allSkipped = true;
|
|
||||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
|
||||||
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
|
||||||
allSkipped = false;
|
|
||||||
}
|
|
||||||
if (!allSkipped) {
|
|
||||||
reallyAllSkipped = false;
|
|
||||||
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (reallyAllSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract static class CustomChart {
|
|
||||||
|
|
||||||
private final String chartId;
|
|
||||||
|
|
||||||
protected CustomChart(String chartId) {
|
|
||||||
if (chartId == null) {
|
|
||||||
throw new IllegalArgumentException("chartId must not be null");
|
|
||||||
}
|
|
||||||
this.chartId = chartId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
|
||||||
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
|
||||||
JsonObjectBuilder builder = new JsonObjectBuilder();
|
|
||||||
builder.appendField("chartId", chartId);
|
|
||||||
try {
|
|
||||||
JsonObjectBuilder.JsonObject data = getChartData();
|
|
||||||
if (data == null) {
|
|
||||||
// If the data is null we don't send the chart.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
builder.appendField("data", data);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (logErrors) {
|
|
||||||
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
|
||||||
int value = callable.call();
|
|
||||||
if (value == 0) {
|
|
||||||
// Null = skip the chart
|
// Null = skip the chart
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import pk.ajneb97.model.internal.KitVariable;
|
||||||
import pk.ajneb97.model.inventory.InventoryPlayer;
|
import pk.ajneb97.model.inventory.InventoryPlayer;
|
||||||
import pk.ajneb97.model.inventory.ItemKitInventory;
|
import pk.ajneb97.model.inventory.ItemKitInventory;
|
||||||
import pk.ajneb97.model.inventory.KitInventory;
|
import pk.ajneb97.model.inventory.KitInventory;
|
||||||
|
import pk.ajneb97.model.item.KitItem;
|
||||||
import pk.ajneb97.utils.InventoryItem;
|
import pk.ajneb97.utils.InventoryItem;
|
||||||
import pk.ajneb97.utils.InventoryUtils;
|
import pk.ajneb97.utils.InventoryUtils;
|
||||||
import pk.ajneb97.utils.ItemUtils;
|
import pk.ajneb97.utils.ItemUtils;
|
||||||
|
|
@ -58,26 +59,35 @@ public class InventoryEditPositionManager {
|
||||||
if(kit == null){
|
if(kit == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ItemStack item = kitItemManager.createItemFromKitItem(kit.getDisplayItemDefault(),null,kit);
|
|
||||||
|
KitItem kitItem = kit.getDisplayItemDefault().clone();
|
||||||
|
|
||||||
//Check if it is the same kit
|
//Check if it is the same kit
|
||||||
if(kitName.equals(inventoryPlayer.getKitName())){
|
if(kitName.equals(inventoryPlayer.getKitName())){
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
List<String> extraLore = new ArrayList<>();
|
List<String> extraLore = new ArrayList<>();
|
||||||
|
List<String> currentLore = kitItem.getLore();
|
||||||
extraLore.add(" ");
|
extraLore.add(" ");
|
||||||
extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHIS IS THE CURRENT POSITION OF"));
|
if(mainConfigManager.isUseMiniMessage()){
|
||||||
extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHE KIT."));
|
extraLore.add(MessagesManager.getLegacyColoredMessage("<green><b>THIS IS THE CURRENT POSITION OF</b>"));
|
||||||
|
extraLore.add(MessagesManager.getLegacyColoredMessage("<green><b>THE KIT.</b>"));
|
||||||
|
}else{
|
||||||
|
extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHIS IS THE CURRENT POSITION OF"));
|
||||||
|
extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHE KIT."));
|
||||||
|
}
|
||||||
|
|
||||||
List<String> itemLore = new ArrayList<>();
|
List<String> itemLore = new ArrayList<>();
|
||||||
if(meta.hasLore()){
|
if(currentLore != null){
|
||||||
itemLore = new ArrayList<>(meta.getLore());
|
itemLore = new ArrayList<>(currentLore);
|
||||||
}
|
}
|
||||||
itemLore.addAll(extraLore);
|
itemLore.addAll(extraLore);
|
||||||
meta.setLore(itemLore);
|
kitItem.setLore(itemLore);
|
||||||
item.setItemMeta(meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<KitVariable> variablesToReplace = new ArrayList<>();
|
ArrayList<KitVariable> variablesToReplace = new ArrayList<>();
|
||||||
variablesToReplace.add(new KitVariable("%kit_name%",kit.getName()));
|
variablesToReplace.add(new KitVariable("%kit_name%",kit.getName()));
|
||||||
kitItemManager.replaceVariables(item,variablesToReplace);
|
kitItemManager.replaceVariables(kitItem,variablesToReplace,inventoryPlayer.getPlayer());
|
||||||
|
|
||||||
|
ItemStack item = kitItemManager.createItemFromKitItem(kitItem,null,kit);
|
||||||
|
|
||||||
inv.setItem(slot,item);
|
inv.setItem(slot,item);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,10 @@ public class MiniMessageUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void title(Player player, String title, String subtitle){
|
public static void title(Player player, String title, String subtitle, Integer fadeIn, Integer stay, Integer fadeOut){
|
||||||
player.showTitle(Title.title(
|
player.showTitle(Title.title(
|
||||||
MiniMessage.miniMessage().deserialize(title),MiniMessage.miniMessage().deserialize(subtitle)
|
MiniMessage.miniMessage().deserialize(title),MiniMessage.miniMessage().deserialize(subtitle),
|
||||||
|
fadeIn,stay,fadeOut
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,34 +83,6 @@ public class MiniMessageUtils {
|
||||||
meta.lore(loreComponent);
|
meta.lore(loreComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceVariablesItemName(ItemMeta meta, ArrayList<KitVariable> variables){
|
|
||||||
Component name = meta.displayName();
|
|
||||||
Component newName = name;
|
|
||||||
for(KitVariable variable : variables){
|
|
||||||
newName = newName.replaceText(TextReplacementConfig.builder()
|
|
||||||
.matchLiteral(variable.getVariable())
|
|
||||||
.replacement(MiniMessage.miniMessage().deserialize(variable.getValue()))
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
meta.displayName(newName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void replaceVariablesItemLore(ItemMeta meta,ArrayList<KitVariable> variables){
|
|
||||||
List<Component> lore = meta.lore();
|
|
||||||
List<Component> newLore = new ArrayList<>();
|
|
||||||
for(Component c : lore){
|
|
||||||
Component newComponent = c;
|
|
||||||
for(KitVariable variable : variables){
|
|
||||||
newComponent = newComponent.replaceText(TextReplacementConfig.builder()
|
|
||||||
.matchLiteral(variable.getVariable())
|
|
||||||
.replacement(MiniMessage.miniMessage().deserialize(variable.getValue()))
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
newLore.add(newComponent);
|
|
||||||
}
|
|
||||||
meta.lore(newLore);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRequirementsMessage(ItemMeta meta, String kitName, Player player, InventoryRequirementsManager inventoryRequirementsManager){
|
public static void setRequirementsMessage(ItemMeta meta, String kitName, Player player, InventoryRequirementsManager inventoryRequirementsManager){
|
||||||
List<Component> newLore = new ArrayList<>();
|
List<Component> newLore = new ArrayList<>();
|
||||||
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();
|
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue