- Fixed plugin not loading on versions < 1.21
- Fixed empty lines on some items in some GUIs.
This commit is contained in:
nulli0n committed 2025-04-08 01:44:02 +05:00
1 parent 8562f69011
commit b7495ac492
5 files changed
+44 -13

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>su.nightexpress.nightcore</groupId> <groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId> <artifactId>nightcore</artifactId>
<version>2.7.5</version> <version>2.7.5.1</version>
<properties> <properties>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
@@ -27,12 +27,13 @@ public class LangUIButton implements LangElement {
return new Builder(path, name); return new Builder(path, name);
} }
protected record Details(String name, List<String> description, Map<String, String> currentInfo, Map<ClickKey, String> clickActions){} protected record Details(String name, List<String> description, boolean formatted, Map<String, String> currentInfo, Map<ClickKey, String> clickActions){}
@Override @Override
public void write(@NotNull FileConfig config) { public void write(@NotNull FileConfig config) {
config.set(this.path + ".Name", this.defaults.name); config.set(this.path + ".Name", this.defaults.name);
config.set(this.path + ".Description", this.defaults.description); config.set(this.path + ".Description", this.defaults.description);
config.set(this.path + ".Formatted", this.defaults.formatted);
config.remove(this.path + ".CurrentInfo"); config.remove(this.path + ".CurrentInfo");
this.defaults.currentInfo.forEach((name, value) -> config.set(this.path + ".CurrentInfo." + name, value)); 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) { public void load(@NotNull NightCorePlugin plugin) {
FileConfig config = plugin.getLang(); 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); this.write(config);
} }
String name = ConfigValue.create(this.path + ".Name", this.defaults.name).read(config); String name = ConfigValue.create(this.path + ".Name", this.defaults.name).read(config);
List<String> description = ConfigValue.create(this.path + ".Description", this.defaults.description).read(config); List<String> description = ConfigValue.create(this.path + ".Description", this.defaults.description).read(config);
boolean formatted = ConfigValue.create(this.path + ".Formatted", this.defaults.formatted).read(config);
Map<String, String> currentInfo = new LinkedHashMap<>(); Map<String, String> currentInfo = new LinkedHashMap<>();
config.getSection(this.path + ".CurrentInfo").forEach(sId -> { config.getSection(this.path + ".CurrentInfo").forEach(sId -> {
@@ -71,7 +73,7 @@ public class LangUIButton implements LangElement {
clickActions.put(key, action); clickActions.put(key, action);
}); });
this.details = new Details(name, description, currentInfo, clickActions); this.details = new Details(name, description, formatted, currentInfo, clickActions);
} }
@NotNull @NotNull
@@ -84,6 +86,10 @@ public class LangUIButton implements LangElement {
return this.details.description; return this.details.description;
} }
public boolean isFormatted() {
return this.details.formatted;
}
@NotNull @NotNull
public Map<String, String> getCurrentInfo() { public Map<String, String> getCurrentInfo() {
return this.details.currentInfo; return this.details.currentInfo;
@@ -103,10 +109,12 @@ public class LangUIButton implements LangElement {
private final Map<ClickKey, String> clickActions; private final Map<ClickKey, String> clickActions;
private String name; private String name;
private boolean formatted;
public Builder(@NotNull String path, @NotNull String name) { public Builder(@NotNull String path, @NotNull String name) {
this.path = path; this.path = path;
this.name = name; this.name = name;
this.formatted = true;
this.description = new ArrayList<>(); this.description = new ArrayList<>();
this.currentInfo = new LinkedHashMap<>(); this.currentInfo = new LinkedHashMap<>();
this.clickActions = new LinkedHashMap<>(); this.clickActions = new LinkedHashMap<>();
@@ -114,7 +122,7 @@ public class LangUIButton implements LangElement {
@NotNull @NotNull
public LangUIButton build() { 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 @NotNull
@@ -129,6 +137,12 @@ public class LangUIButton implements LangElement {
return this; return this;
} }
@NotNull
public Builder formatted(boolean formatted) {
this.formatted = formatted;
return this;
}
@NotNull @NotNull
public Builder current(@NotNull String value) { public Builder current(@NotNull String value) {
return this.current(CoreLang.EDITOR_BUTTON_CURRENT_DEFAULT_NAME.getString(), value); return this.current(CoreLang.EDITOR_BUTTON_CURRENT_DEFAULT_NAME.getString(), value);
@@ -5,21 +5,31 @@ import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.NightCore; import su.nightexpress.nightcore.NightCore;
import su.nightexpress.nightcore.ui.menu.confirmation.ConfirmMenu; import su.nightexpress.nightcore.ui.menu.confirmation.ConfirmMenu;
import su.nightexpress.nightcore.ui.menu.confirmation.Confirmation; import su.nightexpress.nightcore.ui.menu.confirmation.Confirmation;
import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.Version;
public class UIUtils { public class UIUtils {
private static ConfirmMenu confirmMenu; private static ConfirmMenu confirmMenu;
public static void load(@NotNull NightCore plugin) { 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() { public static void clear() {
confirmMenu.clear(); if (confirmMenu != null) {
confirmMenu = null; confirmMenu.clear();
confirmMenu = null;
}
} }
public static void openConfirmation(@NotNull Player player, @NotNull Confirmation confirmation) { 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); confirmMenu.open(player, confirmation);
} }
} }
@@ -353,7 +353,9 @@ public class NightMeta implements Writeable {
@NotNull @NotNull
public NightMeta localized(@NotNull LangUIButton locale) { 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<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
locale.getCurrentInfo().forEach((title, value) -> { locale.getCurrentInfo().forEach((title, value) -> {
@@ -364,9 +366,9 @@ public class NightMeta implements Writeable {
lore.add(Placeholders.EMPTY_IF_ABOVE); lore.add(Placeholders.EMPTY_IF_ABOVE);
for (String entry : locale.getDescription()) { 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) -> { locale.getClickActions().forEach((key, action) -> {
lore.add(CoreLang.EDITOR_BUTTON_CLICK_KEY.getString() lore.add(CoreLang.EDITOR_BUTTON_CLICK_KEY.getString()
@@ -47,12 +47,17 @@ public class HoverTag extends Tag implements ContentTag {
@NotNull @NotNull
public String wrapShowText(@NotNull String string, @NotNull String text) { 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 @NotNull
public String wrapShowItem(@NotNull String string, @NotNull ItemStack itemStack) { 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 @NotNull