From b7495ac492a1e45b45fa2df42c76b8c96f91eb31 Mon Sep 17 00:00:00 2001 From: nulli0n Date: Tue, 8 Apr 2025 01:44:02 +0500 Subject: [PATCH] v2.7.5.1 - Fixed plugin not loading on versions < 1.21 - Fixed empty lines on some items in some GUIs. --- pom.xml | 2 +- .../language/entry/LangUIButton.java | 22 +++++++++++++++---- .../su/nightexpress/nightcore/ui/UIUtils.java | 16 +++++++++++--- .../nightcore/util/bukkit/NightMeta.java | 8 ++++--- .../util/text/tag/impl/HoverTag.java | 9 ++++++-- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index bc81c33..9bed0db 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ su.nightexpress.nightcore nightcore - 2.7.5 + 2.7.5.1 21 diff --git a/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java b/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java index 448f6ef..e1ad735 100644 --- a/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java +++ b/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java @@ -27,12 +27,13 @@ public class LangUIButton implements LangElement { return new Builder(path, name); } - protected record Details(String name, List description, Map currentInfo, Map clickActions){} + protected record Details(String name, List description, boolean formatted, Map currentInfo, Map clickActions){} @Override public void write(@NotNull FileConfig config) { config.set(this.path + ".Name", this.defaults.name); config.set(this.path + ".Description", this.defaults.description); + config.set(this.path + ".Formatted", this.defaults.formatted); config.remove(this.path + ".CurrentInfo"); this.defaults.currentInfo.forEach((name, value) -> config.set(this.path + ".CurrentInfo." + name, value)); @@ -45,12 +46,13 @@ public class LangUIButton implements LangElement { public void load(@NotNull NightCorePlugin plugin) { FileConfig config = plugin.getLang(); - if (!config.contains(this.path) || !config.contains(this.path + ".ClickActions")) { + if (!config.contains(this.path) || (!config.contains(this.path + ".ClickActions") && !this.defaults.clickActions.isEmpty())) { this.write(config); } String name = ConfigValue.create(this.path + ".Name", this.defaults.name).read(config); List description = ConfigValue.create(this.path + ".Description", this.defaults.description).read(config); + boolean formatted = ConfigValue.create(this.path + ".Formatted", this.defaults.formatted).read(config); Map currentInfo = new LinkedHashMap<>(); config.getSection(this.path + ".CurrentInfo").forEach(sId -> { @@ -71,7 +73,7 @@ public class LangUIButton implements LangElement { clickActions.put(key, action); }); - this.details = new Details(name, description, currentInfo, clickActions); + this.details = new Details(name, description, formatted, currentInfo, clickActions); } @NotNull @@ -84,6 +86,10 @@ public class LangUIButton implements LangElement { return this.details.description; } + public boolean isFormatted() { + return this.details.formatted; + } + @NotNull public Map getCurrentInfo() { return this.details.currentInfo; @@ -103,10 +109,12 @@ public class LangUIButton implements LangElement { private final Map clickActions; private String name; + private boolean formatted; public Builder(@NotNull String path, @NotNull String name) { this.path = path; this.name = name; + this.formatted = true; this.description = new ArrayList<>(); this.currentInfo = new LinkedHashMap<>(); this.clickActions = new LinkedHashMap<>(); @@ -114,7 +122,7 @@ public class LangUIButton implements LangElement { @NotNull public LangUIButton build() { - return new LangUIButton(this.path, new Details(this.name, new ArrayList<>(this.description), this.currentInfo, new HashMap<>(this.clickActions))); + return new LangUIButton(this.path, new Details(this.name, new ArrayList<>(this.description), this.formatted, this.currentInfo, new HashMap<>(this.clickActions))); } @NotNull @@ -129,6 +137,12 @@ public class LangUIButton implements LangElement { return this; } + @NotNull + public Builder formatted(boolean formatted) { + this.formatted = formatted; + return this; + } + @NotNull public Builder current(@NotNull String value) { return this.current(CoreLang.EDITOR_BUTTON_CURRENT_DEFAULT_NAME.getString(), value); diff --git a/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java b/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java index a0f8601..95a52cf 100644 --- a/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java +++ b/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java @@ -5,21 +5,31 @@ import org.jetbrains.annotations.NotNull; import su.nightexpress.nightcore.NightCore; import su.nightexpress.nightcore.ui.menu.confirmation.ConfirmMenu; import su.nightexpress.nightcore.ui.menu.confirmation.Confirmation; +import su.nightexpress.nightcore.util.Plugins; +import su.nightexpress.nightcore.util.Version; public class UIUtils { private static ConfirmMenu confirmMenu; public static void load(@NotNull NightCore plugin) { - confirmMenu = new ConfirmMenu(plugin); + if (Version.isAtLeast(Version.MC_1_21)) { + confirmMenu = new ConfirmMenu(plugin); + } } public static void clear() { - confirmMenu.clear(); - confirmMenu = null; + if (confirmMenu != null) { + confirmMenu.clear(); + confirmMenu = null; + } } public static void openConfirmation(@NotNull Player player, @NotNull Confirmation confirmation) { + if (confirmMenu == null) { + Plugins.getCore().error("[UIUtils] Unsupported server version."); + return; + } confirmMenu.open(player, confirmation); } } diff --git a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java b/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java index 1bb7f93..a99ff39 100644 --- a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java +++ b/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java @@ -353,7 +353,9 @@ public class NightMeta implements Writeable { @NotNull public NightMeta localized(@NotNull LangUIButton locale) { - String name = CoreLang.EDITOR_BUTTON_NAME.getString().replace(Placeholders.GENERIC_NAME, locale.getName()); + boolean formatted = locale.isFormatted(); + + String name = formatted ? CoreLang.EDITOR_BUTTON_NAME.getString().replace(Placeholders.GENERIC_NAME, locale.getName()) : locale.getName(); List lore = new ArrayList<>(); locale.getCurrentInfo().forEach((title, value) -> { @@ -364,9 +366,9 @@ public class NightMeta implements Writeable { lore.add(Placeholders.EMPTY_IF_ABOVE); for (String entry : locale.getDescription()) { - lore.add(CoreLang.EDITOR_BUTTON_DESCRIPTION.getString().replace(Placeholders.GENERIC_ENTRY, entry)); + lore.add(formatted ? CoreLang.EDITOR_BUTTON_DESCRIPTION.getString().replace(Placeholders.GENERIC_ENTRY, entry) : entry); } - lore.add(Placeholders.EMPTY_IF_ABOVE); + lore.add(Placeholders.EMPTY_IF_BELOW); locale.getClickActions().forEach((key, action) -> { lore.add(CoreLang.EDITOR_BUTTON_CLICK_KEY.getString() diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java index 2b99a96..629c7e4 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java @@ -47,12 +47,17 @@ public class HoverTag extends Tag implements ContentTag { @NotNull public String wrapShowText(@NotNull String string, @NotNull String text) { - return this.enclose(string, HoverEventType.SHOW_TEXT, text); + return this.wrap(string, HoverEventType.SHOW_TEXT, text); } @NotNull public String wrapShowItem(@NotNull String string, @NotNull ItemStack itemStack) { - return this.enclose(string, HoverEventType.SHOW_ITEM, String.valueOf(ItemNbt.compress(itemStack))); + return this.wrapShowItem(string, String.valueOf(ItemNbt.compress(itemStack))); + } + + @NotNull + public String wrapShowItem(@NotNull String string, @NotNull String compressed) { + return this.wrap(string, HoverEventType.SHOW_ITEM, compressed); } @NotNull