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>
|
||||
<artifactId>PlayerKits2</artifactId>
|
||||
<version>1.21.1</version>
|
||||
<version>1.21.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class TitleAPI implements Listener {
|
|||
}
|
||||
|
||||
if(PlayerKitsAPI.getPlugin().getConfigsManager().getMainConfigManager().isUseMiniMessage()){
|
||||
MiniMessageUtils.title(player,title,subtitle);
|
||||
MiniMessageUtils.title(player,title,subtitle,fadeIn,stay,fadeOut);
|
||||
}else{
|
||||
player.sendTitle(MessagesManager.getLegacyColoredMessage(title), MessagesManager.getLegacyColoredMessage(subtitle), fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,20 +347,24 @@ public class InventoryManager {
|
|||
newStatus = "default";
|
||||
}
|
||||
|
||||
kitItem = kitItem.clone();
|
||||
|
||||
boolean useMiniMessage = plugin.getConfigsManager().getMainConfigManager().isUseMiniMessage();
|
||||
if(newStatus.equals(currentStatus) && currentItem != null){
|
||||
// Name and Lore update
|
||||
kitItemManager.replaceVariables(kitItem,variablesToReplace,player);
|
||||
|
||||
ItemMeta meta = currentItem.getItemMeta();
|
||||
|
||||
String name = kitItem.getName();
|
||||
if(name != null){
|
||||
name = OtherUtils.replaceGlobalVariables(name,player,plugin);
|
||||
if(useMiniMessage){
|
||||
MiniMessageUtils.setItemName(meta,name);
|
||||
}else{
|
||||
meta.setDisplayName(MessagesManager.getLegacyColoredMessage(name));
|
||||
}
|
||||
}
|
||||
|
||||
List<String> lore = kitItem.getLore();
|
||||
if(lore != null) {
|
||||
List<String> loreCopy = new ArrayList<>(lore);
|
||||
|
|
@ -374,13 +378,12 @@ public class InventoryManager {
|
|||
meta.setLore(loreCopy);
|
||||
}
|
||||
}
|
||||
currentItem.setItemMeta(meta);
|
||||
|
||||
kitItemManager.replaceVariables(currentItem,variablesToReplace);
|
||||
currentItem.setItemMeta(meta);
|
||||
}else{
|
||||
// Full update
|
||||
kitItemManager.replaceVariables(kitItem,variablesToReplace,player);
|
||||
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_status", newStatus);
|
||||
inv.setItem(slot,item);
|
||||
|
|
|
|||
|
|
@ -811,39 +811,26 @@ public class KitItemManager {
|
|||
return kitItem;
|
||||
}
|
||||
|
||||
public void replaceVariables(ItemStack item, ArrayList<KitVariable> variables){
|
||||
boolean useMiniMessage = plugin.getConfigsManager().getMainConfigManager().isUseMiniMessage();
|
||||
if(item.hasItemMeta()){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta.hasDisplayName()){
|
||||
if(useMiniMessage){
|
||||
MiniMessageUtils.replaceVariablesItemName(meta,variables);
|
||||
}else{
|
||||
String newName = meta.getDisplayName();
|
||||
public void replaceVariables(KitItem commonItem, ArrayList<KitVariable> variables, Player player){
|
||||
if(commonItem.getName() != null){
|
||||
String newName = commonItem.getName();
|
||||
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(useMiniMessage){
|
||||
MiniMessageUtils.replaceVariablesItemLore(meta,variables);
|
||||
}else{
|
||||
List<String> lore = meta.getLore();
|
||||
if(commonItem.getLore() != null){
|
||||
List<String> lore = commonItem.getLore();
|
||||
for(int i=0;i<lore.size();i++){
|
||||
for(KitVariable variable : variables){
|
||||
String line = lore.get(i).replace(variable.getVariable(),variable.getValue());
|
||||
lore.set(i,MessagesManager.getLegacyColoredMessage(line));
|
||||
line = OtherUtils.replaceGlobalVariables(line,player,plugin);
|
||||
lore.set(i,line);
|
||||
}
|
||||
}
|
||||
meta.setLore(lore);
|
||||
commonItem.setLore(lore);
|
||||
}
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,19 @@
|
|||
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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
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.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
|
@ -37,6 +55,11 @@ import java.util.function.Supplier;
|
|||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
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 {
|
||||
|
||||
|
|
@ -51,7 +74,7 @@ public class Metrics {
|
|||
* @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>
|
||||
*/
|
||||
public Metrics(JavaPlugin plugin, int serviceId) {
|
||||
public Metrics(Plugin plugin, int serviceId) {
|
||||
this.plugin = plugin;
|
||||
// Get the config file
|
||||
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"
|
||||
+ "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"
|
||||
+ "anonymous.")
|
||||
+ "anonymous.\n"
|
||||
+ "Learn more here: https://bstats.org/docs/server-owners")
|
||||
.copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
|
|
@ -84,21 +108,36 @@ public class Metrics {
|
|||
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||
boolean logSentData = config.getBoolean("logSentData", false);
|
||||
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
boolean isFolia = false;
|
||||
try {
|
||||
isFolia = Class.forName("io.papermc.paper.threadedregions.RegionizedServer") != null;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
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",
|
||||
serverUUID,
|
||||
serviceId,
|
||||
enabled,
|
||||
this::appendPlatformData,
|
||||
this::appendServiceData,
|
||||
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||
isFolia
|
||||
? null
|
||||
: submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||
plugin::isEnabled,
|
||||
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||
logErrors,
|
||||
logSentData,
|
||||
logResponseStatusText);
|
||||
logResponseStatusText,
|
||||
false);
|
||||
}
|
||||
|
||||
/** Shuts down the underlying scheduler service. */
|
||||
|
|
@ -149,7 +188,7 @@ public class Metrics {
|
|||
public static class MetricsBase {
|
||||
|
||||
/** 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";
|
||||
|
||||
|
|
@ -203,6 +242,7 @@ public class Metrics {
|
|||
* @param logErrors Whether or not errors 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 skipRelocateCheck Whether or not the relocate check should be skipped.
|
||||
*/
|
||||
public MetricsBase(
|
||||
String platform,
|
||||
|
|
@ -217,9 +257,16 @@ public class Metrics {
|
|||
Consumer<String> infoLogger,
|
||||
boolean logErrors,
|
||||
boolean logSentData,
|
||||
boolean logResponseStatusText) {
|
||||
boolean logResponseStatusText,
|
||||
boolean skipRelocateCheck) {
|
||||
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
|
||||
// cancelled when the scheduler is shutdown.
|
||||
// Otherwise, we risk preventing the server from shutting down even when
|
||||
|
|
@ -239,7 +286,9 @@ public class Metrics {
|
|||
this.logErrors = logErrors;
|
||||
this.logSentData = logSentData;
|
||||
this.logResponseStatusText = logResponseStatusText;
|
||||
if (!skipRelocateCheck) {
|
||||
checkRelocation();
|
||||
}
|
||||
if (enabled) {
|
||||
// WARNING: Removing the option to opt-out will get your plugin banned from
|
||||
// bStats
|
||||
|
|
@ -303,7 +352,6 @@ public class Metrics {
|
|||
scheduler.execute(
|
||||
() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
// 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.
|
||||
|
|
@ -394,15 +476,15 @@ public class Metrics {
|
|||
* @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) {
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
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 {
|
||||
|
||||
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.
|
||||
|
|
@ -500,163 +696,15 @@ public class Metrics {
|
|||
* @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) {
|
||||
public SimplePie(String chartId, Callable<String> 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 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) {
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import pk.ajneb97.model.internal.KitVariable;
|
|||
import pk.ajneb97.model.inventory.InventoryPlayer;
|
||||
import pk.ajneb97.model.inventory.ItemKitInventory;
|
||||
import pk.ajneb97.model.inventory.KitInventory;
|
||||
import pk.ajneb97.model.item.KitItem;
|
||||
import pk.ajneb97.utils.InventoryItem;
|
||||
import pk.ajneb97.utils.InventoryUtils;
|
||||
import pk.ajneb97.utils.ItemUtils;
|
||||
|
|
@ -58,26 +59,35 @@ public class InventoryEditPositionManager {
|
|||
if(kit == null){
|
||||
continue;
|
||||
}
|
||||
ItemStack item = kitItemManager.createItemFromKitItem(kit.getDisplayItemDefault(),null,kit);
|
||||
|
||||
KitItem kitItem = kit.getDisplayItemDefault().clone();
|
||||
|
||||
//Check if it is the same kit
|
||||
if(kitName.equals(inventoryPlayer.getKitName())){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> extraLore = new ArrayList<>();
|
||||
List<String> currentLore = kitItem.getLore();
|
||||
extraLore.add(" ");
|
||||
if(mainConfigManager.isUseMiniMessage()){
|
||||
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<>();
|
||||
if(meta.hasLore()){
|
||||
itemLore = new ArrayList<>(meta.getLore());
|
||||
if(currentLore != null){
|
||||
itemLore = new ArrayList<>(currentLore);
|
||||
}
|
||||
itemLore.addAll(extraLore);
|
||||
meta.setLore(itemLore);
|
||||
item.setItemMeta(meta);
|
||||
kitItem.setLore(itemLore);
|
||||
}
|
||||
|
||||
ArrayList<KitVariable> variablesToReplace = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
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);
|
||||
}
|
||||
|
||||
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){
|
||||
List<Component> newLore = new ArrayList<>();
|
||||
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue