From 587f0567d8ccced0747a431ee813ce33f2b6d8ed Mon Sep 17 00:00:00 2001 From: Ajneb97 Date: Thu, 12 Mar 2026 15:13:58 -0300 Subject: [PATCH] 1.21.2 --- pom.xml | 2 +- .../java/pk/ajneb97/libs/titles/TitleAPI.java | 2 +- .../pk/ajneb97/managers/InventoryManager.java | 11 +- .../pk/ajneb97/managers/KitItemManager.java | 45 +- .../managers/dependencies/Metrics.java | 402 ++++++++++-------- .../edit/InventoryEditPositionManager.java | 28 +- .../pk/ajneb97/utils/MiniMessageUtils.java | 33 +- 7 files changed, 272 insertions(+), 251 deletions(-) diff --git a/pom.xml b/pom.xml index 7c98403..3a48c2d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ pk.ajneb97 PlayerKits2 - 1.21.1 + 1.21.2 21 diff --git a/src/main/java/pk/ajneb97/libs/titles/TitleAPI.java b/src/main/java/pk/ajneb97/libs/titles/TitleAPI.java index 54eebb2..13913f9 100644 --- a/src/main/java/pk/ajneb97/libs/titles/TitleAPI.java +++ b/src/main/java/pk/ajneb97/libs/titles/TitleAPI.java @@ -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); } diff --git a/src/main/java/pk/ajneb97/managers/InventoryManager.java b/src/main/java/pk/ajneb97/managers/InventoryManager.java index 77799d7..ec4c77b 100644 --- a/src/main/java/pk/ajneb97/managers/InventoryManager.java +++ b/src/main/java/pk/ajneb97/managers/InventoryManager.java @@ -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 lore = kitItem.getLore(); if(lore != null) { List 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); diff --git a/src/main/java/pk/ajneb97/managers/KitItemManager.java b/src/main/java/pk/ajneb97/managers/KitItemManager.java index dc9c015..2f4bcc5 100644 --- a/src/main/java/pk/ajneb97/managers/KitItemManager.java +++ b/src/main/java/pk/ajneb97/managers/KitItemManager.java @@ -811,39 +811,26 @@ public class KitItemManager { return kitItem; } - public void replaceVariables(ItemStack item, ArrayList 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(); - for(KitVariable variable : variables){ - newName = newName.replace(variable.getVariable(),variable.getValue()); - } - meta.setDisplayName(MessagesManager.getLegacyColoredMessage(newName)); - } + public void replaceVariables(KitItem commonItem, ArrayList variables, Player player){ + if(commonItem.getName() != null){ + String newName = commonItem.getName(); + for(KitVariable variable : variables){ + newName = newName.replace(variable.getVariable(),variable.getValue()); } + newName = OtherUtils.replaceGlobalVariables(newName,player,plugin); + commonItem.setName(newName); + } - if(meta.hasLore()){ - if(useMiniMessage){ - MiniMessageUtils.replaceVariablesItemLore(meta,variables); - }else{ - List lore = meta.getLore(); - for(int i=0;i lore = commonItem.getLore(); + for(int i=0;iWhat is my plugin id? */ - 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 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; - checkRelocation(); + 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 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 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 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 callable) { + public SingleLineChart(String chartId, Callable 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>> 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>> callable) { + super(chartId); + this.callable = callable; + } + + @Override + public JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); + boolean allSkipped = true; + for (Map.Entry 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> 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> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry 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> 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> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry 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> callable; @@ -490,9 +686,9 @@ public class Metrics { } } - public static class SimpleBarChart extends CustomChart { + public static class SimplePie extends CustomChart { - private final Callable> callable; + private final Callable 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> callable) { + public SimplePie(String chartId, Callable callable) { super(chartId); this.callable = callable; } @Override protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry 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> 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> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry 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>> 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>> callable) { - super(chartId); - this.callable = callable; - } - - @Override - public JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); - boolean allSkipped = true; - for (Map.Entry 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 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 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 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; } diff --git a/src/main/java/pk/ajneb97/managers/edit/InventoryEditPositionManager.java b/src/main/java/pk/ajneb97/managers/edit/InventoryEditPositionManager.java index 272c4cb..f8e9212 100644 --- a/src/main/java/pk/ajneb97/managers/edit/InventoryEditPositionManager.java +++ b/src/main/java/pk/ajneb97/managers/edit/InventoryEditPositionManager.java @@ -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 extraLore = new ArrayList<>(); + List currentLore = kitItem.getLore(); extraLore.add(" "); - extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHIS IS THE CURRENT POSITION OF")); - extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHE KIT.")); + if(mainConfigManager.isUseMiniMessage()){ + extraLore.add(MessagesManager.getLegacyColoredMessage("THIS IS THE CURRENT POSITION OF")); + extraLore.add(MessagesManager.getLegacyColoredMessage("THE KIT.")); + }else{ + extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHIS IS THE CURRENT POSITION OF")); + extraLore.add(MessagesManager.getLegacyColoredMessage("&a&lTHE KIT.")); + } + List 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 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); } diff --git a/src/main/java/pk/ajneb97/utils/MiniMessageUtils.java b/src/main/java/pk/ajneb97/utils/MiniMessageUtils.java index dcc9aef..93f5d33 100644 --- a/src/main/java/pk/ajneb97/utils/MiniMessageUtils.java +++ b/src/main/java/pk/ajneb97/utils/MiniMessageUtils.java @@ -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 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 variables){ - List lore = meta.lore(); - List 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 newLore = new ArrayList<>(); PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();