registry) {
+ return new LangRegistry<>(path, registry);
+ }
+
+ @Override
+ public void write(@NotNull FileConfig config) {
+
+ }
+
+ public void load(@NotNull NightCorePlugin plugin) {
+ FileConfig config = plugin.getLang();
+
+ BukkitThing.getAll(this.registry).forEach(keyed -> {
+ String value = BukkitThing.getValue(keyed);
+ String localized = StringUtil.capitalizeUnderscored(value);
+
+ String text = ConfigValue.create(this.path + "." + value, localized).read(config);
+ this.localeMap.put(value, text);
+ });
+ }
+
+ @NotNull
+ public String getLocalized(@NotNull E keyed) {
+ String value = BukkitThing.getValue(keyed);
+
+ return this.localeMap.getOrDefault(value, value);
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/language/entry/LangString.java b/main/src/main/java/su/nightexpress/nightcore/language/entry/LangString.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/entry/LangString.java
rename to main/src/main/java/su/nightexpress/nightcore/language/entry/LangString.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/entry/LangText.java b/main/src/main/java/su/nightexpress/nightcore/language/entry/LangText.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/entry/LangText.java
rename to main/src/main/java/su/nightexpress/nightcore/language/entry/LangText.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java b/main/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java
rename to main/src/main/java/su/nightexpress/nightcore/language/entry/LangUIButton.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java b/main/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
rename to main/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/message/MessageOptions.java b/main/src/main/java/su/nightexpress/nightcore/language/message/MessageOptions.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/message/MessageOptions.java
rename to main/src/main/java/su/nightexpress/nightcore/language/message/MessageOptions.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/message/OutputType.java b/main/src/main/java/su/nightexpress/nightcore/language/message/OutputType.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/message/OutputType.java
rename to main/src/main/java/su/nightexpress/nightcore/language/message/OutputType.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/MessageTag.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/MessageTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/MessageTag.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/MessageTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/MessageTags.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/MessageTags.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/MessageTags.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/MessageTags.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/impl/NoPrefixTag.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/impl/NoPrefixTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/impl/NoPrefixTag.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/impl/NoPrefixTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/impl/OutputTag.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/impl/OutputTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/impl/OutputTag.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/impl/OutputTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/impl/PlaceholderTag.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/impl/PlaceholderTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/impl/PlaceholderTag.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/impl/PlaceholderTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/language/tag/impl/SoundTag.java b/main/src/main/java/su/nightexpress/nightcore/language/tag/impl/SoundTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/language/tag/impl/SoundTag.java
rename to main/src/main/java/su/nightexpress/nightcore/language/tag/impl/SoundTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/manager/AbstractFileData.java b/main/src/main/java/su/nightexpress/nightcore/manager/AbstractFileData.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/manager/AbstractFileData.java
rename to main/src/main/java/su/nightexpress/nightcore/manager/AbstractFileData.java
diff --git a/src/main/java/su/nightexpress/nightcore/manager/AbstractListener.java b/main/src/main/java/su/nightexpress/nightcore/manager/AbstractListener.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/manager/AbstractListener.java
rename to main/src/main/java/su/nightexpress/nightcore/manager/AbstractListener.java
diff --git a/src/main/java/su/nightexpress/nightcore/manager/AbstractManager.java b/main/src/main/java/su/nightexpress/nightcore/manager/AbstractManager.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/manager/AbstractManager.java
rename to main/src/main/java/su/nightexpress/nightcore/manager/AbstractManager.java
diff --git a/src/main/java/su/nightexpress/nightcore/manager/SimpeListener.java b/main/src/main/java/su/nightexpress/nightcore/manager/SimpeListener.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/manager/SimpeListener.java
rename to main/src/main/java/su/nightexpress/nightcore/manager/SimpeListener.java
diff --git a/src/main/java/su/nightexpress/nightcore/manager/SimpleManager.java b/main/src/main/java/su/nightexpress/nightcore/manager/SimpleManager.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/manager/SimpleManager.java
rename to main/src/main/java/su/nightexpress/nightcore/manager/SimpleManager.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/MenuListener.java b/main/src/main/java/su/nightexpress/nightcore/menu/MenuListener.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/MenuListener.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/MenuListener.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/MenuOptions.java b/main/src/main/java/su/nightexpress/nightcore/menu/MenuOptions.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/MenuOptions.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/MenuOptions.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/MenuSize.java b/main/src/main/java/su/nightexpress/nightcore/menu/MenuSize.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/MenuSize.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/MenuSize.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/MenuViewer.java b/main/src/main/java/su/nightexpress/nightcore/menu/MenuViewer.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/MenuViewer.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/MenuViewer.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/api/AutoFill.java b/main/src/main/java/su/nightexpress/nightcore/menu/api/AutoFill.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/api/AutoFill.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/api/AutoFill.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/api/AutoFilled.java b/main/src/main/java/su/nightexpress/nightcore/menu/api/AutoFilled.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/api/AutoFilled.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/api/AutoFilled.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java b/main/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/api/Menu.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/click/ClickAction.java b/main/src/main/java/su/nightexpress/nightcore/menu/click/ClickAction.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/click/ClickAction.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/click/ClickAction.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/click/ClickResult.java b/main/src/main/java/su/nightexpress/nightcore/menu/click/ClickResult.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/click/ClickResult.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/click/ClickResult.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/click/ClickType.java b/main/src/main/java/su/nightexpress/nightcore/menu/click/ClickType.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/click/ClickType.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/click/ClickType.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java b/main/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java b/main/src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java
index 8a8379c..76e3eff 100644
--- a/src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java
+++ b/main/src/main/java/su/nightexpress/nightcore/menu/impl/ConfigMenu.java
@@ -123,7 +123,7 @@ public abstract class ConfigMenu extends AbstractMenu
comments.add("> Priority: Button priority. Better values will override other item(s) in the same slot(s).");
comments.add("> Slots: Button slots. From [0] to [Size - 1]. Split with commas.");
comments.add("> Click_Commands: Execute custom commands on click. " + Plugins.PLACEHOLDER_API + " available here.");
- comments.add(" Available click types: " + String.join(", ", Lists.getEnums(ClickType.class)));
+ comments.add(" Available click types: " + Enums.inline(ClickType.class));
comments.add(" Use prefix '" + Players.PLAYER_COMMAND_PREFIX + "' to run command by a player.");
comments.add(" Click_Commands:");
comments.add(" LEFT:");
diff --git a/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java b/main/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/impl/EditorMenu.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/item/ItemHandler.java b/main/src/main/java/su/nightexpress/nightcore/menu/item/ItemHandler.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/item/ItemHandler.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/item/ItemHandler.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/item/ItemOptions.java b/main/src/main/java/su/nightexpress/nightcore/menu/item/ItemOptions.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/item/ItemOptions.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/item/ItemOptions.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/item/MenuItem.java b/main/src/main/java/su/nightexpress/nightcore/menu/item/MenuItem.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/item/MenuItem.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/item/MenuItem.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/link/Linked.java b/main/src/main/java/su/nightexpress/nightcore/menu/link/Linked.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/link/Linked.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/link/Linked.java
diff --git a/src/main/java/su/nightexpress/nightcore/menu/link/ViewLink.java b/main/src/main/java/su/nightexpress/nightcore/menu/link/ViewLink.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/menu/link/ViewLink.java
rename to main/src/main/java/su/nightexpress/nightcore/menu/link/ViewLink.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/UIListener.java b/main/src/main/java/su/nightexpress/nightcore/ui/UIListener.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/UIListener.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/UIListener.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java b/main/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java
similarity index 88%
rename from src/main/java/su/nightexpress/nightcore/ui/UIUtils.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java
index 95a52cf..2428cbf 100644
--- a/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java
+++ b/main/src/main/java/su/nightexpress/nightcore/ui/UIUtils.java
@@ -2,10 +2,10 @@ package su.nightexpress.nightcore.ui;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
+import su.nightexpress.nightcore.Engine;
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 {
@@ -27,7 +27,7 @@ public class UIUtils {
public static void openConfirmation(@NotNull Player player, @NotNull Confirmation confirmation) {
if (confirmMenu == null) {
- Plugins.getCore().error("[UIUtils] Unsupported server version.");
+ Engine.core().error("[UIUtils] Unsupported server version.");
return;
}
confirmMenu.open(player, confirmation);
diff --git a/src/main/java/su/nightexpress/nightcore/ui/dialog/Dialog.java b/main/src/main/java/su/nightexpress/nightcore/ui/dialog/Dialog.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/dialog/Dialog.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/dialog/Dialog.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogHandler.java b/main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogHandler.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/dialog/DialogHandler.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogHandler.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogInput.java b/main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogInput.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/dialog/DialogInput.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogInput.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogManager.java b/main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogManager.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/dialog/DialogManager.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/dialog/DialogManager.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/Menu.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/Menu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/Menu.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/Menu.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/MenuRegistry.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/MenuRegistry.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/MenuRegistry.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/MenuRegistry.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/MenuViewer.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/MenuViewer.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/MenuViewer.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/MenuViewer.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickKey.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickKey.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickKey.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickKey.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickResult.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickResult.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickResult.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/click/ClickResult.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/ConfirmMenu.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/ConfirmMenu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/ConfirmMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/ConfirmMenu.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/Confirmation.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/Confirmation.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/Confirmation.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/confirmation/Confirmation.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/ConfigBased.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/ConfigBased.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/ConfigBased.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/ConfigBased.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/Filled.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/Filled.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/Filled.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/Filled.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkCache.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkCache.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkCache.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkCache.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkHandler.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkHandler.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkHandler.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/LinkHandler.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/Linked.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/Linked.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/Linked.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/Linked.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuFiller.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuFiller.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuFiller.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuFiller.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java
index 50f0c5d..b5e0023 100644
--- a/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java
+++ b/main/src/main/java/su/nightexpress/nightcore/ui/menu/data/MenuLoader.java
@@ -157,7 +157,7 @@ public class MenuLoader {
" [*] Available types: [" + String.join(", ", handlerMap.keySet().stream().map(str -> "'" + str + "'").toList()) + "]",
"> [Click_Commands] : Section | Executes commands on click with " + Plugins.PLACEHOLDER_API + " support.",
" [*] Works only if [Type] is not set (null).",
- " [*] Available click types: [" + String.join(", ", Lists.getEnums(ClickKey.class)) + "]",
+ " [*] Available click types: [" + Enums.inline(ClickKey.class) + "]",
" [*] Use prefix '" + Players.PLAYER_COMMAND_PREFIX + "' to run command by a player.",
" Click_Commands:",
" " + ClickKey.LEFT.name() + ":",
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemClick.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemClick.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemClick.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemClick.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemHandler.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemHandler.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemHandler.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemHandler.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemOptions.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemOptions.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemOptions.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/item/ItemOptions.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/item/MenuItem.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/item/MenuItem.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/item/MenuItem.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/item/MenuItem.java
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java
similarity index 96%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java
index da7d392..d613c3f 100644
--- a/src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java
+++ b/main/src/main/java/su/nightexpress/nightcore/ui/menu/type/AbstractMenu.java
@@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MenuType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
import su.nightexpress.nightcore.NightPlugin;
import su.nightexpress.nightcore.api.event.MenuOpenEvent;
import su.nightexpress.nightcore.ui.dialog.Dialog;
@@ -22,8 +23,9 @@ import su.nightexpress.nightcore.ui.menu.data.Linked;
import su.nightexpress.nightcore.ui.menu.item.ItemHandler;
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
import su.nightexpress.nightcore.util.Lists;
-import su.nightexpress.nightcore.util.Version;
+import su.nightexpress.nightcore.util.Placeholders;
import su.nightexpress.nightcore.util.bukkit.NightItem;
+import su.nightexpress.nightcore.util.text.NightMessage;
import java.util.Comparator;
import java.util.HashSet;
@@ -31,7 +33,6 @@ import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
-@SuppressWarnings("UnstableApiUsage")
public abstract class AbstractMenu
implements Menu {
protected final P plugin;
@@ -147,7 +148,10 @@ public abstract class AbstractMenu
implements Menu {
}
String title = this.getTitle(viewer);
- view = Version.software().createView(this.menuType, title, player);
+ if (this.isApplyPlaceholderAPI()) {
+ title = Placeholders.forPlayerWithPAPI(player).apply(title);
+ }
+ view = Engine.software().createView(this.menuType, NightMessage.parse(title), player);
viewer.assignInventory(view);
player.openInventory(view);
}
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java
similarity index 99%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java
index 7e192b8..4be6d00 100644
--- a/src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java
+++ b/main/src/main/java/su/nightexpress/nightcore/ui/menu/type/LinkedMenu.java
@@ -182,7 +182,8 @@ public abstract class LinkedMenu
extends AbstractMenu<
@Override
public void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler handler, @Nullable ItemOptions options) {
- MenuItem menuItem = item.setHideComponents(true)
+ MenuItem menuItem = item
+ .hideAllComponents()
.toMenuItem()
.setPriority(MenuItem.HIGH_PRIORITY)
.setSlots(slot)
diff --git a/src/main/java/su/nightexpress/nightcore/ui/menu/type/NormalMenu.java b/main/src/main/java/su/nightexpress/nightcore/ui/menu/type/NormalMenu.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/ui/menu/type/NormalMenu.java
rename to main/src/main/java/su/nightexpress/nightcore/ui/menu/type/NormalMenu.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/Colorizer.java b/main/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
similarity index 74%
rename from src/main/java/su/nightexpress/nightcore/util/Colorizer.java
rename to main/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
index 01cd61f..957bf5c 100644
--- a/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
@@ -16,27 +16,32 @@ public class Colorizer {
@Deprecated public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})");
@NotNull
+ @Deprecated
public static String apply(@NotNull String str) {
return hex(legacy(str));
}
@NotNull
+ @Deprecated
public static List apply(@NotNull List list) {
list.replaceAll(Colorizer::apply);
return list;
}
@NotNull
+ @Deprecated
public static Set apply(@NotNull Set set) {
return set.stream().map(Colorizer::apply).collect(Collectors.toSet());
}
@NotNull
+ @Deprecated
public static String legacyHex(@NotNull String str) {
return hex(legacy(str));
}
@NotNull
+ @Deprecated
public static String legacy(@NotNull String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
@@ -60,41 +65,48 @@ public class Colorizer {
}
@NotNull
+ @Deprecated
public static String plain(@NotNull String str) {
- return plainLegacy(plainHex(str));
+ return LegacyColors.plainColors(str);
+ //return plainLegacy(plainHex(str));
}
@NotNull
+ @Deprecated
public static String plainLegacy(@NotNull String str) {
- return str.replace(ChatColor.COLOR_CHAR, '&');
+ return LegacyColors.plainDefaultColors(str);
+ //return str.replace(ChatColor.COLOR_CHAR, '&');
}
@NotNull
@Deprecated
public static String plainHex(@NotNull String str) {
- StringBuilder builder = new StringBuilder(str);
-
- int index;
- while ((index = builder.toString().indexOf(ChatColor.COLOR_CHAR + "x")) >= 0) {
- int count = 0;
- builder.replace(index, index + 2, "#");
-
- for (int point = index + 1; count < 6; point += 1) {
- builder.deleteCharAt(point);
- count++;
- }
- }
-
- return builder.toString();//tagPlainHex(builder.toString());
+ return LegacyColors.plainHEXColors(str);
+// StringBuilder builder = new StringBuilder(str);
+//
+// int index;
+// while ((index = builder.toString().indexOf(ChatColor.COLOR_CHAR + "x")) >= 0) {
+// int count = 0;
+// builder.replace(index, index + 2, "#");
+//
+// for (int point = index + 1; count < 6; point += 1) {
+// builder.deleteCharAt(point);
+// count++;
+// }
+// }
+//
+// return builder.toString();
}
@NotNull
+ @Deprecated
public static String strip(@NotNull String str) {
String stripped = ChatColor.stripColor(str);
return stripped == null ? "" : stripped;
}
@NotNull
+ @Deprecated
public static String restrip(@NotNull String str) {
return strip(apply(str));
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/CommandUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/CommandUtil.java
similarity index 90%
rename from src/main/java/su/nightexpress/nightcore/util/CommandUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/CommandUtil.java
index eea2512..98bb480 100644
--- a/src/main/java/su/nightexpress/nightcore/util/CommandUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/CommandUtil.java
@@ -6,11 +6,11 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
import su.nightexpress.nightcore.command.api.NightPluginCommand;
import su.nightexpress.nightcore.command.experimental.CommandContext;
import su.nightexpress.nightcore.command.experimental.argument.ParsedArguments;
import su.nightexpress.nightcore.command.impl.WrappedCommand;
-import su.nightexpress.nightcore.util.text.NightMessage;
import java.util.*;
@@ -18,7 +18,7 @@ public class CommandUtil {
@NotNull
private static SimpleCommandMap getCommandMap() {
- return Version.software().getCommandMap();
+ return Engine.software().getCommandMap();
}
@Deprecated
@@ -48,7 +48,7 @@ public class CommandUtil {
SimpleCommandMap commandMap = getCommandMap();
- Map knownCommands = Version.software().getKnownCommands(commandMap);
+ Map knownCommands = Engine.software().getKnownCommands(commandMap);
if (!command.unregister(commandMap)) return false;
return knownCommands.keySet().removeIf(key -> key.equalsIgnoreCase(command.getName()) || command.getAliases().contains(key));
@@ -77,8 +77,8 @@ public class CommandUtil {
}
@NotNull
- public static String getCommandName(@NotNull String str) {
- String name = NightMessage.stripAll(str).split(" ")[0].substring(1);
+ public static String getCommandName(@NotNull String string) {
+ String name = string.split(" ")[0].substring(1);
String[] pluginPrefix = name.split(":");
if (pluginPrefix.length == 2) {
diff --git a/src/main/java/su/nightexpress/nightcore/util/EntityUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/EntityUtil.java
similarity index 86%
rename from src/main/java/su/nightexpress/nightcore/util/EntityUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/EntityUtil.java
index 44cd6c0..7f7df2a 100644
--- a/src/main/java/su/nightexpress/nightcore/util/EntityUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/EntityUtil.java
@@ -5,11 +5,13 @@ import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
import java.util.Collections;
import java.util.HashMap;
@@ -22,7 +24,7 @@ public class EntityUtil {
};
public static int nextEntityId() {
- return Version.software().nextEntityId();
+ return Engine.software().nextEntityId();
}
public static double getAttribute(@NotNull LivingEntity entity, @NotNull Attribute attribute) {
@@ -35,6 +37,16 @@ public class EntityUtil {
return instance == null ? 0D : instance.getBaseValue();
}
+ @Nullable
+ public static ItemStack getItemInSlot(@NotNull LivingEntity entity, @NotNull EquipmentSlot slot) {
+ if (entity instanceof Player player) {
+ return player.getInventory().getItem(slot);
+ }
+
+ EntityEquipment equipment = entity.getEquipment();
+ return equipment == null ? null : equipment.getItem(slot);
+ }
+
@NotNull
public static Map getEquippedItems(@NotNull LivingEntity entity) {
return getEquippedItems(entity, EQUIPMENT_SLOTS);
diff --git a/src/main/java/su/nightexpress/nightcore/util/FileUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/FileUtil.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/FileUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/FileUtil.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemNbt.java b/main/src/main/java/su/nightexpress/nightcore/util/ItemNbt.java
similarity index 90%
rename from src/main/java/su/nightexpress/nightcore/util/ItemNbt.java
rename to main/src/main/java/su/nightexpress/nightcore/util/ItemNbt.java
index 33b1e34..94bc875 100644
--- a/src/main/java/su/nightexpress/nightcore/util/ItemNbt.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/ItemNbt.java
@@ -21,9 +21,11 @@ import java.util.*;
public class ItemNbt {
+ private static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
+
private static final Class> CLS_MINECRAFT_ITEM_STACK = Reflex.getNMSClass("net.minecraft.world.item", "ItemStack");
- private static final Class> CLS_CRAFT_ITEM_STACK = Reflex.getNMSClass(Version.CRAFTBUKKIT_PACKAGE + ".inventory", "CraftItemStack");
+ private static final Class> CLS_CRAFT_ITEM_STACK = Reflex.getNMSClass(CRAFTBUKKIT_PACKAGE + ".inventory", "CraftItemStack");
private static final Class> CLS_TAG = Reflex.getNMSClass("net.minecraft.nbt", "Tag", "NBTBase");
private static final Class> CLS_COMPOUND_TAG = Reflex.getNMSClass("net.minecraft.nbt", "CompoundTag", "NBTTagCompound");
@@ -41,8 +43,6 @@ public class ItemNbt {
private static Method mNbtIoRead;
private static Method mTagParserParseTag;
- //private static int DATA_FIXER_SOURCE_VERSION;
- //private static int DATA_FIXER_TARGET_VERSION;
private static DataFixer dataFixer;
private static Object nbtOps;
private static Object itemStackReference;
@@ -92,9 +92,6 @@ public class ItemNbt {
}
// Load DataFixer components.
- //DATA_FIXER_SOURCE_VERSION = 4189;//3700; // 1.20.4
- //DATA_FIXER_TARGET_VERSION = 4325; // 1.21.5 or 1.21.4
-
Method mGetDataFixer = Reflex.getMethod(CLS_DATA_FIXERS, "a");
if (mGetDataFixer == null) {
core.error("[Item NBT] Could not load DataFixer components.");
@@ -109,7 +106,7 @@ public class ItemNbt {
if (Version.isAtLeast(Version.MC_1_20_6)) {
useRegistry = true;
- Class> clsCraftRegistry = Reflex.getNMSClass(Version.CRAFTBUKKIT_PACKAGE, "CraftRegistry");
+ Class> clsCraftRegistry = Reflex.getNMSClass(CRAFTBUKKIT_PACKAGE, "CraftRegistry");
if (clsCraftRegistry == null) {
core.error("[Item NBT] Could not find CraftRegistry.");
return;
@@ -163,10 +160,10 @@ public class ItemNbt {
public static boolean test() {
ItemStack testItem = new ItemStack(Material.DIAMOND_SWORD);
ItemUtil.editMeta(testItem, meta -> {
- meta.setDisplayName("Test Item");
- meta.setLore(Lists.newList("Test Lore 1", "Test Lore 2", "Test Lore 3"));
+ ItemUtil.setCustomName(meta, "Test Item");
+ ItemUtil.setLore(meta, Lists.newList("Test Lore 1", "Test Lore 2", "Test Lore 3"));
+ ItemUtil.setCustomModelData(meta, 100500);
meta.addEnchant(Enchantment.FIRE_ASPECT, 10, true);
- meta.setCustomModelData(100500);
});
ItemTag tag = getTag(testItem);
@@ -174,12 +171,6 @@ public class ItemNbt {
ItemStack parsed = fromTag(tag);
return parsed != null && parsed.isSimilar(testItem);
-
-// String nbt = ItemNbt.compress(testItem);
-// if (nbt == null) return false;
-//
-// ItemStack decompressed = ItemNbt.decompress(nbt);
-// return decompressed != null && decompressed.isSimilar(testItem);
}
@NotNull
@@ -267,7 +258,7 @@ public class ItemNbt {
- @NotNull
+ @Nullable
public static ItemStack getHoverEventItem(@NotNull String value) {
ItemStack itemStack = null;
@@ -282,7 +273,7 @@ public class ItemNbt {
}
}
- if (itemStack == null) itemStack = new ItemStack(Material.AIR);
+ if (itemStack != null && itemStack.getType().isAir()) return null;
return itemStack;
}
@@ -320,12 +311,6 @@ public class ItemNbt {
return itemStack == null ? null : (ItemStack) Reflex.invokeMethod(mCraftItemStackAsBukkitCopy, null, itemStack);
}
-// @SuppressWarnings({"rawtypes", "unchecked"})
-// private static Object applyDataFixer(@NotNull Object compoundTag) {
-// Dynamic> dynamic = new Dynamic<>((DynamicOps) nbtOps, compoundTag);
-// return dataFixer.update((DSL.TypeReference) itemStackReference, dynamic, DATA_FIXER_SOURCE_VERSION, DATA_FIXER_TARGET_VERSION).getValue();
-// }
-
@SuppressWarnings({"rawtypes", "unchecked"})
private static Object applyDataFixer(@NotNull Object compoundTag, int sourceVersion) {
int targetVersion = Version.getCurrent() == Version.UNKNOWN ? CoreConfig.DATA_FIXER_UNKNOWN_VERSION.get() : Version.getCurrent().getDataVersion();
diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java b/main/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java
rename to main/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemTag.java b/main/src/main/java/su/nightexpress/nightcore/util/ItemTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/ItemTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/ItemTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java
similarity index 60%
rename from src/main/java/su/nightexpress/nightcore/util/ItemUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java
index 9df0836..fb6ba36 100644
--- a/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java
@@ -2,8 +2,6 @@ package su.nightexpress.nightcore.util;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
-import net.kyori.adventure.text.Component;
-import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Tag;
@@ -12,11 +10,14 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.inventory.meta.components.CustomModelDataComponent;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import su.nightexpress.nightcore.language.LangAssets;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
+import su.nightexpress.nightcore.util.text.NightMessage;
import java.net.URI;
import java.net.URL;
@@ -28,136 +29,173 @@ public class ItemUtil {
public static final String TEXTURES_HOST = "http://textures.minecraft.net/texture/";
+ public static void editMeta(@NotNull ItemStack item, @NotNull Consumer consumer) {
+ Engine.software().editMeta(item, consumer);
+ }
+
+ public static void editMeta(@NotNull ItemStack item, @NotNull Class clazz, @NotNull Consumer consumer) {
+ Engine.software().editMeta(item, clazz, consumer);
+ }
+
@NotNull
+ public static String getNameSerialized(@NotNull ItemStack itemStack) {
+ ItemMeta meta = itemStack.getItemMeta();
+ String metaName = meta == null ? null : getNameSerialized(meta);
+ if (metaName != null) return metaName;
+
+// if (Version.isSpigot()) {
+// return LangAssets.get(itemStack.getType());
+// }
+
+ return LangUtil.getSerializedName(itemStack.getType());
+ }
+
+ @Nullable
+ public static String getNameSerialized(@NotNull ItemMeta meta) {
+ String customName = getCustomNameSerialized(meta);
+ if (customName != null) return customName;
+
+ return getItemNameSerialized(meta);
+ }
+
+ @NotNull
+ @Deprecated
public static String getItemName(@NotNull ItemStack item) {
- ItemMeta meta = item.getItemMeta();
- if (meta != null) {
- String name = getItemName(meta);
- if (name != null) return name;
- }
-
- return LangAssets.get(item.getType());
+ return getNameSerialized(item);
}
@Nullable
+ @Deprecated
public static String getItemName(@NotNull ItemMeta meta) {
- if (Version.isAtLeast(Version.MC_1_21) && meta.hasItemName()) {
- return meta.getItemName();
- }
- if (meta.hasDisplayName()) {
- return meta.getDisplayName();
- }
-
- return null;
+ return getNameSerialized(meta);
}
@NotNull
+ @Deprecated
public static String getSerializedName(@NotNull ItemStack item) {
- if (Version.isSpigot()) return getItemName(item);
- if (!item.hasItemMeta()) return LangAssets.get(item.getType());
-
- ItemMeta meta = item.getItemMeta();
- if (meta != null) {
- String name = getSerializedName(meta);
- if (name != null) return name;
- }
-
- return LangAssets.get(item.getType());
+ return getNameSerialized(item);
}
@Nullable
+ @Deprecated
public static String getSerializedName(@NotNull ItemMeta meta) {
- if (Version.isAtLeast(Version.MC_1_21) && meta.hasItemName()) {
- return getSerializedItemName(meta);
- }
-
- if (meta.hasDisplayName()) {
- return getSerializedDisplayName(meta);
- }
-
- return null;
+ return getNameSerialized(meta);
}
@Nullable
+ @Deprecated
public static String getSerializedDisplayName(@NotNull ItemMeta meta) {
- if (Version.isSpigot()) return getItemName(meta);
-
- var displayName = meta.hasDisplayName() ? meta.displayName() : null;
- return displayName == null ? null : MiniMessage.miniMessage().serialize(displayName);
+ return getCustomNameSerialized(meta);
}
@Nullable
+ @Deprecated
public static String getSerializedItemName(@NotNull ItemMeta meta) {
- if (Version.isSpigot()) return getItemName(meta);
+ return getItemNameSerialized(meta);
+ }
+
+ @NotNull
+ @Deprecated
+ public static List getSerializedLore(@NotNull ItemStack item) {
+ return getLoreSerialized(item);
+ }
+
+ @NotNull
+ @Deprecated
+ public static List getSerializedLore(@NotNull ItemMeta meta) {
+ return getLoreSerialized(meta);
+ }
+
+
+
+ @Deprecated
+ public static void setDisplayName(@NotNull ItemMeta meta, @NotNull String name) {
+ setCustomName(meta, name);
+ }
+
+ @Nullable
+ public static String getCustomNameSerialized(@NotNull ItemStack itemStack) {
+ ItemMeta meta = itemStack.getItemMeta();
+ return meta == null ? null : getCustomNameSerialized(meta);
+ }
+
+ @Nullable
+ public static String getCustomNameSerialized(@NotNull ItemMeta meta) {
+ return Engine.software().getCustomName(meta);
+ }
+
+ public static void setCustomName(@NotNull ItemMeta meta, @NotNull String name) {
+ Engine.software().setCustomName(meta, NightMessage.parse(name));
+ }
+
+
+
+ @Nullable
+ public static String getItemNameSerialized(@NotNull ItemStack itemStack) {
if (Version.isBehind(Version.MC_1_21)) return null;
- return meta.hasItemName() ? MiniMessage.miniMessage().serialize(meta.itemName()) : null;
+ ItemMeta meta = itemStack.getItemMeta();
+ return meta == null ? null : getItemNameSerialized(meta);
}
- @NotNull
- public static List getSerializedLore(@NotNull ItemStack item) {
- if (!item.hasItemMeta()) return new ArrayList<>();
+ @Nullable
+ public static String getItemNameSerialized(@NotNull ItemMeta meta) {
+ if (Version.isBehind(Version.MC_1_21)) return null;
- ItemMeta meta = item.getItemMeta();
-
- return meta == null ? new ArrayList<>() : getSerializedLore(meta);
- }
-
- @NotNull
- public static List getSerializedLore(@NotNull ItemMeta meta) {
- if (Version.isSpigot()) {
- List lore = meta.getLore();
- return lore == null ? new ArrayList<>() : lore;
- }
-
- List lore = meta.lore();
-
- return lore == null ? new ArrayList<>() : lore.stream().map(MiniMessage.miniMessage()::serialize).toList();
- }
-
- public static void setDisplayName(@NotNull ItemMeta meta, @NotNull String name) {
- Version.software().setDisplayName(meta, name);
+ return Engine.software().getItemName(meta);
}
public static void setItemName(@NotNull ItemMeta meta, @NotNull String name) {
- Version.software().setItemName(meta, name);
+ if (Version.isBehind(Version.MC_1_21)) return;
+
+ Engine.software().setItemName(meta, NightMessage.parse(name));
+ }
+
+
+
+ @NotNull
+ @Deprecated
+ public static List getLore(@NotNull ItemStack item) {
+ ItemMeta meta = item.getItemMeta();
+ return (meta == null || meta.getLore() == null) ? new ArrayList<>() : meta.getLore();
+ }
+
+ @NotNull
+ public static List getLoreSerialized(@NotNull ItemStack itemStack) {
+ ItemMeta meta = itemStack.getItemMeta();
+ return meta == null ? new ArrayList<>() : getLoreSerialized(meta);
+ }
+
+ @NotNull
+ public static List getLoreSerialized(@NotNull ItemMeta meta) {
+ List lore = Engine.software().getLore(meta);
+ return lore == null ? new ArrayList<>() : lore;
}
public static void setLore(@NotNull ItemMeta meta, @NotNull List lore) {
- Version.software().setLore(meta, lore);
+ Engine.software().setLore(meta, Lists.modify(lore, NightMessage::parse));
}
- public static void editMeta(@NotNull ItemStack item, @NotNull Consumer function) {
- editMeta(item, ItemMeta.class, function);
- }
- public static void editMeta(@NotNull ItemStack item, @NotNull Class clazz, @NotNull Consumer function) {
- ItemMeta meta = item.getItemMeta();
- if (meta == null) return;
- if (!clazz.isAssignableFrom(meta.getClass())) return;
-
- T specific = clazz.cast(meta);
-
- function.accept(specific);
- item.setItemMeta(specific);
- }
+ @Deprecated
public static void hideAttributes(@NotNull ItemStack itemStack) {
if (Version.isAtLeast(Version.MC_1_21_5)) {
- Version.software().hideComponents(itemStack);
+ Engine.software().hideComponents(itemStack);
return;
}
editMeta(itemStack, meta -> hideAttributes(meta, itemStack.getType()));
}
+ @Deprecated
private static void hideAttributes(@NotNull ItemMeta meta, @NotNull Material material) {
if (Version.isBehind(Version.MC_1_21_5) && Version.isAtLeast(Version.MC_1_20_6)) {
if (material.isItem()) {
EquipmentSlot slot = material.getEquipmentSlot();
material.getDefaultAttributeModifiers(slot).forEach((attribute, modifier) -> {
var modifiers = meta.getAttributeModifiers() == null ? null : meta.getAttributeModifiers(attribute);
- if (modifiers == null || modifiers.isEmpty()) {
+ if (modifiers == null || modifiers.isEmpty() || !meta.getAttributeModifiers().containsKey(attribute)) {
meta.addAttributeModifier(attribute, modifier);
}
});
@@ -167,10 +205,34 @@ public class ItemUtil {
meta.addItemFlags(ItemFlag.values());
}
- @NotNull
- public static List getLore(@NotNull ItemStack item) {
- ItemMeta meta = item.getItemMeta();
- return (meta == null || meta.getLore() == null) ? new ArrayList<>() : meta.getLore();
+ public static void setCustomModelData(@NotNull ItemStack itemStack, float data) {
+ ItemUtil.editMeta(itemStack, meta -> setCustomModelData(meta, data));
+ }
+
+ public static void setCustomModelData(@NotNull ItemMeta meta, float data) {
+ if (Version.isAtLeast(Version.MC_1_21_5)) {
+ CustomModelDataComponent component = meta.getCustomModelDataComponent();
+ component.setFloats(Lists.newList(data));
+ meta.setCustomModelDataComponent(component);
+ }
+ else {
+ meta.setCustomModelData((int) data);
+ }
+ }
+
+ @Nullable
+ public static Float getCustomModelData(@NotNull ItemStack itemStack) {
+ ItemMeta meta = itemStack.getItemMeta();
+ return meta == null ? null : getCustomModelData(meta);
+ }
+
+ @Nullable
+ public static Float getCustomModelData(@NotNull ItemMeta meta) {
+ if (Version.isAtLeast(Version.MC_1_21_5)) {
+ List floats = meta.getCustomModelDataComponent().getFloats();
+ return floats.isEmpty() ? null : floats.getFirst();
+ }
+ return meta.hasCustomModelData() ? (float) meta.getCustomModelData() : null;
}
@NotNull
@@ -182,13 +244,20 @@ public class ItemUtil {
}
@NotNull
+ @Deprecated
public static ItemStack getSkinHead(@NotNull String texture) {
+ return getCustomHead(texture);
+ }
+
+ @NotNull
+ public static ItemStack getCustomHead(@NotNull String texture) {
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
- setHeadSkin(item, texture);
+ setProfileBySkinURL(item, texture);
return item;
}
@Nullable
+ @Deprecated
public static PlayerProfile createSkinProfile(@NotNull String urlData) {
if (urlData.isBlank()) return null;
@@ -200,9 +269,7 @@ public class ItemUtil {
try {
UUID uuid = UUID.nameUUIDFromBytes(urlData.getBytes());
- // If no name, then meta#getOwnerProfile will return 'null' (wtf?)
- // sometimes swtiching to "new" spigot api is a pain.
- // why the hell i have to dig into nms to learn that...
+ // If no name, then meta#getOwnerProfile will return 'null'.
PlayerProfile profile = Bukkit.createPlayerProfile(uuid, name);
URL url = URI.create(urlData).toURL();//new URL(urlData);
PlayerTextures textures = profile.getTextures();
@@ -217,25 +284,35 @@ public class ItemUtil {
}
}
+ @Deprecated
public static void setHeadSkin(@NotNull ItemStack item, @NotNull String urlData) {
- editMeta(item, SkullMeta.class, meta -> {
- meta.setOwnerProfile(createSkinProfile(urlData));
- });
+ setProfileBySkinURL(item, urlData);
}
@Nullable
+ @Deprecated
public static String getHeadSkin(@NotNull ItemStack item) {
- if (item.getType() != Material.PLAYER_HEAD) return null;
- if (!(item.getItemMeta() instanceof SkullMeta meta)) return null;
+ return getProfileSkinURL(item);
+ }
- PlayerProfile profile = meta.getOwnerProfile();
+ @Nullable
+ public static NightProfile getOwnerProfile(@NotNull ItemStack itemStack) {
+ return Engine.software().getOwnerProfile(itemStack);
+ }
+
+ @Nullable
+ public static String getProfileSkinURL(@NotNull ItemStack itemStack) {
+ NightProfile profile = getOwnerProfile(itemStack);
if (profile == null) return null;
- URL skin = profile.getTextures().getSkin();
- if (skin == null) return null;
+ return Players.getProfileSkinURL(profile);
+ }
- String raw = skin.toString();
- return raw.substring(TEXTURES_HOST.length());
+ public static void setProfileBySkinURL(@NotNull ItemStack itemStack, @NotNull String urlData) {
+ NightProfile profile = Players.createProfileBySkinURL(urlData);
+ if (profile == null) return;
+
+ editMeta(itemStack, SkullMeta.class, profile::apply);
}
@Deprecated
@@ -250,7 +327,7 @@ public class ItemUtil {
String url = element.getAsJsonObject().getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString();
url = url.substring(ItemUtil.TEXTURES_HOST.length());
- setHeadSkin(item, url);
+ setProfileBySkinURL(item, url);
}
catch (Exception exception) {
exception.printStackTrace();
@@ -277,6 +354,7 @@ public class ItemUtil {
return Tag.ITEMS_AXES.isTagged(item.getType());
}
+ @Deprecated
public static boolean isTrident(@NotNull ItemStack item) {
return item.getType() == Material.TRIDENT;
}
@@ -293,10 +371,12 @@ public class ItemUtil {
return Tag.ITEMS_HOES.isTagged(item.getType());
}
+ @Deprecated
public static boolean isElytra(@NotNull ItemStack item) {
return item.getType() == Material.ELYTRA;
}
+ @Deprecated
public static boolean isFishingRod(@NotNull ItemStack item) {
return item.getType() == Material.FISHING_ROD;
}
diff --git a/main/src/main/java/su/nightexpress/nightcore/util/LangUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/LangUtil.java
new file mode 100644
index 0000000..2418755
--- /dev/null
+++ b/main/src/main/java/su/nightexpress/nightcore/util/LangUtil.java
@@ -0,0 +1,66 @@
+package su.nightexpress.nightcore.util;
+
+import org.bukkit.Material;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.EntityType;
+import org.bukkit.potion.PotionEffectType;
+import org.jetbrains.annotations.NotNull;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.bridge.paper.PaperBridge;
+import su.nightexpress.nightcore.util.text.tag.Tags;
+
+public class LangUtil {
+
+ @NotNull
+ public static String getTranslationKey(@NotNull Material material) {
+ return Engine.software().getTranslationKey(material);
+ }
+
+ @NotNull
+ public static String getTranslationKey(@NotNull Attribute attribute) {
+ return Engine.software().getTranslationKey(attribute);
+ }
+
+ @NotNull
+ public static String getTranslationKey(@NotNull Enchantment enchantment) {
+ return Engine.software().getTranslationKey(enchantment);
+ }
+
+ @NotNull
+ public static String getTranslationKey(@NotNull EntityType entityType) {
+ return Engine.software().getTranslationKey(entityType);
+ }
+
+ @NotNull
+ public static String getTranslationKey(@NotNull PotionEffectType effectType) {
+ return Engine.software().getTranslationKey(effectType);
+ }
+
+
+
+ @NotNull
+ public static String getSerializedName(@NotNull Material material) {
+ return Tags.TRANSLATE.wrap(getTranslationKey(material));
+ }
+
+ @NotNull
+ public static String getSerializedName(@NotNull Attribute attribute) {
+ return Tags.TRANSLATE.wrap(getTranslationKey(attribute));
+ }
+
+ @NotNull
+ public static String getSerializedName(@NotNull Enchantment enchantment) {
+ return Version.isPaper() ? PaperBridge.serializeComponent(enchantment.description()) : Tags.TRANSLATE.wrap(getTranslationKey(enchantment), BukkitThing.getValue(enchantment));
+ }
+
+ @NotNull
+ public static String getSerializedName(@NotNull EntityType entityType) {
+ return Tags.TRANSLATE.wrap(getTranslationKey(entityType));
+ }
+
+ @NotNull
+ public static String getSerializedName(@NotNull PotionEffectType effectType) {
+ return Tags.TRANSLATE.wrap(getTranslationKey(effectType));
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/LocationUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/LocationUtil.java
similarity index 96%
rename from src/main/java/su/nightexpress/nightcore/util/LocationUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/LocationUtil.java
index 0eaa858..3cde0b8 100644
--- a/src/main/java/su/nightexpress/nightcore/util/LocationUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/LocationUtil.java
@@ -6,6 +6,7 @@ import org.bukkit.World;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
import java.util.ArrayList;
import java.util.Collection;
@@ -37,7 +38,7 @@ public class LocationUtil {
World world = Bukkit.getWorld(split[5]);
if (world == null) {
- Plugins.getCore().error("Invalid/Unloaded world for: '" + raw + "' location!");
+ Engine.core().error("Invalid/Unloaded world for: '" + raw + "' location!");
return null;
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java
similarity index 88%
rename from src/main/java/su/nightexpress/nightcore/util/NumberUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java
index aa69f04..73273c2 100644
--- a/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/NumberUtil.java
@@ -63,8 +63,6 @@ public class NumberUtil {
@NotNull
@Deprecated
public static String compact(double value) {
-// Pair pair = formatCompact(value);
-// return pair.getFirst() + pair.getSecond();
return formatCompact(value);
}
@@ -73,29 +71,6 @@ public class NumberUtil {
return asCompact(value).format();
}
-// @NotNull
-// public static Pair formatCompact(double value) {
-// var compact = getCompact(value);
-// return Pair.of(format(compact.getValue()), compact.getShortcut() == null ? "" : compact.getShortcut().getSymbol());
-// boolean negative = false;
-// if (value < 0) {
-// value = Math.abs(value);
-// negative = true;
-// }
-//
-// List shortcuts = getNumberShortcuts();
-// int step = CoreConfig.NUMBER_STEP.get();
-// int index = 0;
-// int maxIndex = shortcuts.size() - 1;
-//
-// while ((value / step) >= 1 && index < maxIndex) {
-// value = value / step;
-// index++;
-// }
-//
-// return Pair.of(CoreConfig.NUMBER_FORMAT.get().format(negative ? -value : value), NUMERIC_MAP.get(NUMERIC_MAP.floorKey(index)).get());
-// }
-
@NotNull
public static CompactNumber asCompact(double value) {
boolean negative = value < 0;
diff --git a/src/main/java/su/nightexpress/nightcore/util/PDCUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/PDCUtil.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/PDCUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/PDCUtil.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/Pair.java b/main/src/main/java/su/nightexpress/nightcore/util/Pair.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/Pair.java
rename to main/src/main/java/su/nightexpress/nightcore/util/Pair.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/Placeholders.java b/main/src/main/java/su/nightexpress/nightcore/util/Placeholders.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/Placeholders.java
rename to main/src/main/java/su/nightexpress/nightcore/util/Placeholders.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/Players.java b/main/src/main/java/su/nightexpress/nightcore/util/Players.java
similarity index 60%
rename from src/main/java/su/nightexpress/nightcore/util/Players.java
rename to main/src/main/java/su/nightexpress/nightcore/util/Players.java
index 3f1cb01..814e1bc 100644
--- a/src/main/java/su/nightexpress/nightcore/util/Players.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/Players.java
@@ -2,27 +2,32 @@ package su.nightexpress.nightcore.util;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.profile.PlayerTextures;
import org.geysermc.floodgate.api.FloodgateApi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import su.nightexpress.nightcore.integration.VaultHook;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
+import su.nightexpress.nightcore.integration.permission.PermissionProvider;
+import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import su.nightexpress.nightcore.util.text.NightMessage;
import su.nightexpress.nightcore.util.text.TextRoot;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
+import java.net.URI;
+import java.net.URL;
+import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class Players {
+ public static final String TEXTURES_HOST = "http://textures.minecraft.net/texture/";
public static final String PLAYER_COMMAND_PREFIX = "player:";
@NotNull
@@ -78,23 +83,152 @@ public class Players {
}
@NotNull
+ public static NightProfile getProfile(@NotNull OfflinePlayer player) {
+ return Engine.software().getProfile(player);
+ }
+
+ @NotNull
+ public static NightProfile createProfile(@NotNull UUID uuid) {
+ return Engine.software().createProfile(uuid);
+ }
+
+ @NotNull
+ public static NightProfile createProfile(@NotNull String name) {
+ return Engine.software().createProfile(name);
+ }
+
+ @NotNull
+ public static NightProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
+ return Engine.software().createProfile(uuid, name);
+ }
+
+ @Nullable
+ public static NightProfile createProfileBySkinURL(@NotNull String urlData) {
+ if (urlData.isBlank()) return null;
+
+ String name = urlData.substring(0, 16);
+
+ if (!urlData.startsWith(TEXTURES_HOST)) {
+ urlData = TEXTURES_HOST + urlData;
+ }
+
+ try {
+ UUID uuid = UUID.nameUUIDFromBytes(urlData.getBytes());
+ // If no name, then meta#getOwnerProfile will return 'null'.
+ NightProfile profile = createProfile(uuid, name);
+ URL url = URI.create(urlData).toURL();
+ PlayerTextures textures = profile.getTextures();
+
+ textures.setSkin(url);
+ profile.setTextures(textures);
+ return profile;
+ }
+ catch (Exception exception) {
+ exception.printStackTrace();
+ return null;
+ }
+ }
+
+ @Nullable
+ public static String getProfileSkinURL(@NotNull NightProfile profile) {
+ URL skin = profile.getTextures().getSkin();
+ if (skin == null) return null;
+
+ String raw = skin.toString();
+ return raw.substring(TEXTURES_HOST.length());
+ }
+
+ @NotNull
+ @Deprecated
public static String getPermissionGroup(@NotNull Player player) {
- return Plugins.hasVault() && VaultHook.hasPermissions() ? VaultHook.getPermissionGroup(player).toLowerCase() : Placeholders.DEFAULT;
+ return getPrimaryGroupOrDefault(player);
+ }
+
+ @Nullable
+ public static String getPrimaryGroup(@NotNull Player player) {
+ PermissionProvider provider = Engine.getPermissions();
+ return provider == null ? null : provider.getPrimaryGroup(player);
}
@NotNull
+ public static String getPrimaryGroup(@NotNull Player player, @NotNull String fallback) {
+ String group = getPrimaryGroup(player);
+ return group == null ? fallback : group;
+ }
+
+ @NotNull
+ public static String getPrimaryGroupOrDefault(@NotNull Player player) {
+ return getPrimaryGroup(player, Placeholders.DEFAULT);
+ }
+
+ @NotNull
+ @Deprecated
public static Set getPermissionGroups(@NotNull Player player) {
- return Plugins.hasVault() && VaultHook.hasPermissions() ? VaultHook.getPermissionGroups(player) : Lists.newSet(Placeholders.DEFAULT);
+ return getInheritanceGroupsOrDefault(player);
}
@NotNull
+ public static Set getInheritanceGroups(@NotNull Player player) {
+ PermissionProvider provider = Engine.getPermissions();
+ return provider == null ? Collections.emptySet() : provider.getPermissionGroups(player);
+ }
+
+ @NotNull
+ public static Set getInheritanceGroups(@NotNull Player player, @NotNull Set fallback) {
+ Set groups = getInheritanceGroups(player);
+ return groups.isEmpty() ? fallback : groups;
+ }
+
+ @NotNull
+ public static Set getInheritanceGroupsOrDefault(@NotNull Player player) {
+ return getInheritanceGroups(player, Lists.newSet(Placeholders.DEFAULT));
+ }
+
+ @NotNull
+ @Deprecated
public static String getPrefix(@NotNull Player player) {
- return Plugins.hasVault() ? VaultHook.getPrefix(player) : "";
+ return getPrefixOrEmpty(player);
}
@NotNull
+ public static String getPrefixOrEmpty(@NotNull Player player) {
+ return getPrefix(player, "");
+
+ }
+
+ @Nullable
+ public static String getRawPrefix(@NotNull Player player) {
+ PermissionProvider provider = Engine.getPermissions();
+ return provider == null ? null : provider.getPrefix(player);
+ }
+
+ @NotNull
+ public static String getPrefix(@NotNull Player player, @NotNull String fallback) {
+ String prefix = getRawPrefix(player);
+ return prefix == null ? fallback : prefix;
+ }
+
+ @NotNull
+ @Deprecated
public static String getSuffix(@NotNull Player player) {
- return Plugins.hasVault() ? VaultHook.getSuffix(player) : "";
+ return getSuffixOrEmpty(player);
+ }
+
+ @NotNull
+ public static String getSuffixOrEmpty(@NotNull Player player) {
+ return getSuffix(player, "");
+ }
+
+ @Nullable
+ public static String getRawSuffix(@NotNull Player player) {
+ PermissionProvider provider = Engine.getPermissions();
+ return provider == null ? null : provider.getSuffix(player);
+ }
+
+ @NotNull
+ public static String getSuffix(@NotNull Player player, @NotNull String fallback) {
+ String suffix = getRawSuffix(player);
+ return suffix == null ? fallback : suffix;
}
public static void sendModernMessage(@NotNull CommandSender sender, @NotNull String message) {
@@ -111,7 +245,10 @@ public class Players {
}
public static void sendTitle(@NotNull Player player, @NotNull String title, @NotNull String subtitle, int fadeIn, int stay, int fadeOut) {
- Version.software().sendTitles(player, title, subtitle, fadeIn, stay, fadeOut);
+ NightComponent titleC = NightMessage.parse(title);
+ NightComponent subtitleC = NightMessage.parse(subtitle);
+
+ Engine.software().sendTitles(player, titleC, subtitleC, fadeIn, stay, fadeOut);
}
public static void dispatchCommands(@NotNull Player player, @NotNull String... commands) {
@@ -148,7 +285,7 @@ public class Players {
public static int countItemSpace(@NotNull Player player, @NotNull ItemStack item) {
int stackSize = item.getType().getMaxStackSize();
- return Stream.of(player.getInventory().getContents()).mapToInt(itemHas -> {
+ return Stream.of(player.getInventory().getStorageContents()).mapToInt(itemHas -> {
if (itemHas == null || itemHas.getType().isAir()) {
return stackSize;
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/Plugins.java b/main/src/main/java/su/nightexpress/nightcore/util/Plugins.java
similarity index 60%
rename from src/main/java/su/nightexpress/nightcore/util/Plugins.java
rename to main/src/main/java/su/nightexpress/nightcore/util/Plugins.java
index 7a3a4dd..829d3c4 100644
--- a/src/main/java/su/nightexpress/nightcore/util/Plugins.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/Plugins.java
@@ -1,49 +1,62 @@
package su.nightexpress.nightcore.util;
+import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
import su.nightexpress.nightcore.NightCore;
+import su.nightexpress.nightcore.integration.permission.PermissionProvider;
public class Plugins {
public static final String VAULT = "Vault";
+ public static final String LUCK_PERMS = "LuckPerms";
public static final String PLACEHOLDER_API = "PlaceholderAPI";
public static final String FLOODGATE = "floodgate";
- public static final String ECONOMY_BRIDGE = "EconomyBridge";
+ public static final String ECONOMY_BRIDGE = "EconomyBridge";
private static boolean hasPlaceholderAPI;
- private static boolean hasVault;
+// private static boolean hasVault;
private static boolean hasFloodgate;
private static boolean hasEconomyBridge;
- private static NightCore core;
-
- public static void load(@NotNull NightCore nightCore) {
- core = nightCore;
- }
+ //private static PermissionProvider permissionProvider;
public static void detectPlugins() {
hasPlaceholderAPI = isInstalled(PLACEHOLDER_API);
- hasVault = isInstalled(VAULT);
+// hasVault = isInstalled(VAULT);
hasFloodgate = isInstalled(FLOODGATE);
hasEconomyBridge = isInstalled(ECONOMY_BRIDGE);
}
@NotNull
+ @Deprecated
public static NightCore getCore() {
- return core;
+ return Engine.core();
}
public static boolean isInstalled(@NotNull String pluginName) {
- Plugin plugin = core.getPluginManager().getPlugin(pluginName);
+ Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
return plugin != null;
}
public static boolean isLoaded(@NotNull String pluginName) {
- Plugin plugin = core.getPluginManager().getPlugin(pluginName);
+ Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
return plugin != null && plugin.isEnabled();
}
+ @Nullable
+ @Deprecated
+ public static PermissionProvider getPermissionProvider() {
+ return Engine.getPermissions();
+ }
+
+ @Deprecated
+ public static boolean hasPermissionsProvider() {
+ return Engine.hasPermissions();
+ }
+
@Deprecated
public static boolean isSpigot() {
return Version.isSpigot();
@@ -54,7 +67,7 @@ public class Plugins {
}
public static boolean hasVault() {
- return hasVault;
+ return isInstalled(VAULT);// hasVault;
}
public static boolean hasFloodgate() {
diff --git a/src/main/java/su/nightexpress/nightcore/util/RankMap.java b/main/src/main/java/su/nightexpress/nightcore/util/RankMap.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/util/RankMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/RankMap.java
index b4884a3..41d7b64 100644
--- a/src/main/java/su/nightexpress/nightcore/util/RankMap.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/RankMap.java
@@ -71,7 +71,7 @@ public class RankMap {
});
Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK,
- "Available values: " + StringUtil.inlineEnum(Mode.class, ", "),
+ "Available values: " + Enums.inline(Mode.class),
"=".repeat(20) + " " + Mode.RANK.name() + " MODE " + "=".repeat(20),
"Get value by player's permission group. All keys in 'Values' list will represent permission group names.",
"If player has none of specified groups, the 'Default_Value' setting will be used then",
diff --git a/main/src/main/java/su/nightexpress/nightcore/util/RankTable.java b/main/src/main/java/su/nightexpress/nightcore/util/RankTable.java
new file mode 100644
index 0000000..f612cfb
--- /dev/null
+++ b/main/src/main/java/su/nightexpress/nightcore/util/RankTable.java
@@ -0,0 +1,178 @@
+package su.nightexpress.nightcore.util;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.config.ConfigValue;
+import su.nightexpress.nightcore.config.FileConfig;
+import su.nightexpress.nightcore.config.Writeable;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+public class RankTable implements Writeable {
+
+ private final Mode mode;
+ private final String permissionPrefix;
+ private final double defaultValue;
+ private final Map values;
+
+ public enum Mode {
+ RANK, PERMISSION
+ }
+
+ RankTable(@NotNull Mode mode, @NotNull String permissionPrefix, double defaultValue, @NotNull Map values) {
+ this.mode = mode;
+ this.permissionPrefix = permissionPrefix;
+ this.defaultValue = defaultValue;
+ this.values = new HashMap<>(values);
+ }
+
+ @NotNull
+ public static Builder ranked(double defaultValue) {
+ return builder(Mode.RANK, defaultValue);
+ }
+
+ @NotNull
+ public static Builder permissioned(double defaultValue) {
+ return builder(Mode.PERMISSION, defaultValue);
+ }
+
+ @NotNull
+ public static Builder builder(@NotNull Mode mode, double defaultValue) {
+ return new Builder(mode, defaultValue);
+ }
+
+ @NotNull
+ public static RankTable read(@NotNull FileConfig config, @NotNull String path) {
+ Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK,
+ "Available values: " + Enums.inline(Mode.class),
+ "=".repeat(20) + " " + Mode.RANK.name() + " MODE " + "=".repeat(20),
+ "Get value by player's permission group. All keys in 'Values' list will represent permission group names.",
+ "If player has none of specified groups, the 'Default_Value' setting will be used then",
+ " Values:",
+ " vip: 1 # -> Player must be in 'vip' permission group.",
+ " gold: 2 # -> Player must be in 'gold' permission group.",
+ " emerald: 3 # -> Player must be in 'emerald' permission group.",
+ "",
+ "=".repeat(20) + " " + Mode.PERMISSION.name() + " MODE " + "=".repeat(20),
+ "Get value by player's permissions. All keys in 'Values' list will represent postfixes for the 'Permission_Prefix' setting (see below).",
+ "If player has none of specified permissions, the 'Default_Value' setting will be used then",
+ " Permission_Prefix: 'example.prefix.'",
+ " Values:",
+ " vip: 1 # -> Player must have 'example.prefix.vip' permission.",
+ " gold: 2 # -> Player must have 'example.prefix.gold' permission.",
+ " emerald: 3 # -> Player must have 'example.prefix.emerald' permission."
+ ).read(config);
+
+ String permissionPrefix = ConfigValue.create(path + ".Permission_Prefix",
+ "example.prefix.",
+ "Sets permission prefix for the '" + Mode.PERMISSION.name() + "' mode."
+ ).read(config);
+
+ double defaultValue = ConfigValue.create(path + ".Default_Value", 0D).read(config);
+
+ Map values = new HashMap<>();
+ for (String rank : config.getSection(path + ".Values")) {
+ double number = config.getDouble(path + ".Values." + rank);
+ values.put(rank.toLowerCase(), number);
+ }
+
+ return new RankTable(mode, permissionPrefix, defaultValue, values);
+ }
+
+ @Override
+ public void write(@NotNull FileConfig config, @NotNull String path) {
+ config.set(path + ".Mode", this.mode.name());
+ config.set(path + ".Permission_Prefix", this.permissionPrefix);
+ config.set(path + ".Default_Value", this.defaultValue);
+ config.remove(path + ".Values");
+ this.values.forEach((rank, number) -> {
+ config.set(path + ".Values." + rank, number);
+ });
+ }
+
+ @NotNull
+ public Double getRankValue(@NotNull Player player) {
+ String group = Players.getPrimaryGroupOrDefault(player);
+ return this.values.getOrDefault(group, this.defaultValue);
+ }
+
+ @NotNull
+ public Double getGreatestOrNegative(@NotNull Player player) {
+ Double best = this.getGreatest(player);
+ Double lowest = this.getSmallest(player);
+
+ return lowest < 0D ? lowest : best;
+ }
+
+ @NotNull
+ public Double getGreatest(@NotNull Player player) {
+ if (this.mode == RankTable.Mode.RANK) {
+ return this.getRankValue(player);
+ }
+ return this.values.entrySet().stream()
+ .filter(entry -> player.hasPermission(this.permissionPrefix + entry.getKey()))
+ .map(Map.Entry::getValue)
+ .max(Comparator.comparingDouble(Number::doubleValue)).orElse(this.defaultValue);
+ }
+
+ @NotNull
+ public Double getSmallest(@NotNull Player player) {
+ if (this.mode == RankTable.Mode.RANK) {
+ return this.getRankValue(player);
+ }
+ return this.values.entrySet().stream()
+ .filter(entry -> player.hasPermission(this.permissionPrefix + entry.getKey()))
+ .map(Map.Entry::getValue)
+ .min(Comparator.comparingDouble(Number::doubleValue)).orElse(this.defaultValue);
+ }
+
+ @NotNull
+ public RankTable.Mode getMode() {
+ return this.mode;
+ }
+
+ @Nullable
+ public String getPermissionPrefix() {
+ return this.permissionPrefix;
+ }
+
+ @NotNull
+ public Double getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ public static class Builder {
+
+ private final Mode mode;
+ private final double defaultValue;
+ private final Map values;
+
+ private String permissionPrefix;
+
+ public Builder(@NotNull Mode mode, double defaultValue) {
+ this.mode = mode;
+ this.defaultValue = defaultValue;
+ this.values = new HashMap<>();
+ }
+
+ @NotNull
+ public RankTable build() {
+ return new RankTable(this.mode, this.permissionPrefix, this.defaultValue, this.values);
+ }
+
+ @NotNull
+ public Builder permissionPrefix(@NotNull String prefix) {
+ this.permissionPrefix = prefix;
+ return this;
+ }
+
+ @NotNull
+ public Builder addRankValue(@NotNull String rank, double value) {
+ this.values.put(rank.toLowerCase(), value);
+ return this;
+ }
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/StringUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/StringUtil.java
similarity index 88%
rename from src/main/java/su/nightexpress/nightcore/util/StringUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/StringUtil.java
index 0e13154..261d272 100644
--- a/src/main/java/su/nightexpress/nightcore/util/StringUtil.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/StringUtil.java
@@ -6,9 +6,10 @@ import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.util.placeholder.PlaceholderEntry;
import su.nightexpress.nightcore.util.random.Rnd;
import su.nightexpress.nightcore.util.regex.TimedMatcher;
+import su.nightexpress.nightcore.util.text.NightMessage;
+import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.regex.Pattern;
@@ -179,19 +180,33 @@ public class StringUtil {
return buf.toString();
}
- public static String replacePlaceholders(@NotNull String string, @NotNull Map> placeholders) {
+ @NotNull
+ public static String replacePlaceholders(@NotNull String string, @NotNull List> replacements, @NotNull T source) {
+ LinkedHashMap> placeholders = new LinkedHashMap<>();
+ replacements.forEach(entry -> {
+ placeholders.put(entry.getKey(), () -> entry.get(source));
+ });
+ return replacePlaceholders(string, placeholders);
+ }
+
+ @NotNull
+ public static String replacePlaceholders(@NotNull String string, @NotNull LinkedHashMap> placeholders) {
if (string.isBlank()) return string;
StringBuilder builder = new StringBuilder();
- //char[] chars = string.toCharArray();
int length = string.length();
- //int index = 0;
for (int index = 0; index < length; index++) {
- if (index == length - 1) continue;
-
char letter = string.charAt(index);
+
if (letter == '%') {
+ // Escaping when using double %%
+ if (index + 1 < length && string.charAt(index + 1) == '%') {
+ builder.append('%');
+ index++; // skip next
+ continue;
+ }
+
int indexNext = string.indexOf(letter, index + 1);
if (indexNext != -1) {
String key = string.substring(index + 1, indexNext);
@@ -233,18 +248,22 @@ public class StringUtil {
}
@NotNull
+ @Deprecated
public static > Optional getEnum(String str, @NotNull Class clazz) {
- try {
- return str == null ? Optional.empty() : Optional.of(Enum.valueOf(clazz, str.toUpperCase()));
- }
- catch (Exception exception) {
- return Optional.empty();
- }
+ return Enums.parse(str, clazz);
+// try {
+// return str == null ? Optional.empty() : Optional.of(Enum.valueOf(clazz, str.toUpperCase()));
+// }
+// catch (Exception exception) {
+// return Optional.empty();
+// }
}
@NotNull
+ @Deprecated
public static String inlineEnum(@NotNull Class extends Enum>> clazz, @NotNull String delimiter) {
- return String.join(delimiter, Lists.getEnums(clazz));
+ return Enums.inline(clazz, delimiter);
+ //return String.join(delimiter, Lists.getEnums(clazz));
}
@NotNull
@@ -294,27 +313,32 @@ public class StringUtil {
@NotNull
public static String lowerCaseUnderscore(@NotNull String str) {
- return lowerCaseUnderscore(str, -1);
+ return str.toLowerCase().replace(' ', '_');
+ //return lowerCaseUnderscore(str, -1);
}
@NotNull
+ @Deprecated
public static String lowerCaseUnderscore(@NotNull String str, int length) {
return lowerCaseAndClean(str, ID_PATTERN, length);
}
@NotNull
+ @Deprecated
public static String lowerCaseUnderscoreStrict(@NotNull String str) {
return lowerCaseUnderscoreStrict(str, -1);
}
@NotNull
+ @Deprecated
public static String lowerCaseUnderscoreStrict(@NotNull String str, int length) {
return lowerCaseAndClean(str, ID_STRICT_PATTERN, length);
}
@NotNull
+ @Deprecated
private static String lowerCaseAndClean(@NotNull String str, @NotNull Pattern pattern, int length) {
- String clean = Colorizer.restrip(str).toLowerCase().replace(" ", "_");
+ String clean = NightMessage.stripAll(str).toLowerCase().replace(" ", "_");
if (length > 0 && clean.length() > length) {
clean = clean.substring(0, length);
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/TimeUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/TimeUtil.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/TimeUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/TimeUtil.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/TriFunction.java b/main/src/main/java/su/nightexpress/nightcore/util/TriFunction.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/TriFunction.java
rename to main/src/main/java/su/nightexpress/nightcore/util/TriFunction.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java
similarity index 97%
rename from src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java
rename to main/src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java
index 7677373..c8063cc 100644
--- a/src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/PlayerBlockTracker.java
@@ -9,7 +9,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import su.nightexpress.nightcore.util.Plugins;
+import su.nightexpress.nightcore.Engine;
import java.util.*;
import java.util.function.Predicate;
@@ -25,7 +25,7 @@ public final class PlayerBlockTracker {
public static void initialize() {
if (listener == null) {
initCurrentlyLoadedWorlds();
- (listener = new TrackListener<>(Plugins.getCore())).registerListeners();
+ (listener = new TrackListener<>(Engine.core())).registerListeners();
}
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackListener.java b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackListener.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackListener.java
rename to main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackListener.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackUtil.java b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackUtil.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackUtil.java
rename to main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackUtil.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedChunk.java b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedChunk.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedChunk.java
rename to main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedChunk.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedWorld.java b/main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedWorld.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedWorld.java
rename to main/src/main/java/su/nightexpress/nightcore/util/blocktracker/TrackedWorld.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java
similarity index 70%
rename from src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java
rename to main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java
index 1b2fb7d..17a99b8 100644
--- a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightItem.java
@@ -6,16 +6,17 @@ import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.profile.PlayerProfile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.config.Writeable;
-import su.nightexpress.nightcore.core.CoreLogger;
-import su.nightexpress.nightcore.language.entry.LangUIButton;
import su.nightexpress.nightcore.language.entry.LangItem;
+import su.nightexpress.nightcore.language.entry.LangUIButton;
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
import su.nightexpress.nightcore.util.BukkitThing;
+import su.nightexpress.nightcore.util.NumberUtil;
import su.nightexpress.nightcore.util.placeholder.Replacer;
import java.util.List;
@@ -28,9 +29,12 @@ import java.util.function.Consumer;
*/
public class NightItem implements Writeable {
- private final ItemStack itemStack;
+ private final ItemStack backend;
private final NightMeta meta;
+ private Material material;
+ private int amount;
+
public NightItem(@NotNull Material material) {
this(material, 1);
}
@@ -44,8 +48,11 @@ public class NightItem implements Writeable {
}
private NightItem(@NotNull ItemStack itemStack, @NotNull NightMeta meta) {
- this.itemStack = new ItemStack(itemStack);
+ this.backend = new ItemStack(itemStack);
this.meta = meta;
+
+ this.material = itemStack.getType();
+ this.amount = itemStack.getAmount();
}
@NotNull
@@ -70,7 +77,7 @@ public class NightItem implements Writeable {
*/
@NotNull
public static NightItem asCustomHead(@NotNull String skinURL) {
- return new NightItem(Material.PLAYER_HEAD).setSkinURL(skinURL);
+ return new NightItem(Material.PLAYER_HEAD).setProfileBySkinURL(skinURL);
}
@NotNull
@@ -80,8 +87,8 @@ public class NightItem implements Writeable {
Material material = BukkitThing.getMaterial(String.valueOf(materialName));
if (material == null) {
- CoreLogger.error("Invalid material '" + materialName + "'. Caused by '" + config.getFile().getAbsolutePath() + "'.");
- material = Material.AIR;
+ Engine.core().error("Invalid material '" + materialName + "'. Found in '" + config.getFile().getAbsolutePath() + "' -> '" + path + "'.");
+ material = Material.BARRIER;
}
ItemStack itemStack = new ItemStack(material, amount);
@@ -92,20 +99,24 @@ public class NightItem implements Writeable {
@Override
public void write(@NotNull FileConfig config, @NotNull String path) {
- config.set(path + ".Material", BukkitThing.toString(this.itemStack.getType()));
- config.set(path + ".Amount", this.itemStack.getAmount() == 1 ? null : this.itemStack.getAmount());
+ config.set(path + ".Material", BukkitThing.getAsString(this.material));
+ config.set(path + ".Amount", this.amount == 1 ? null : this.amount);
this.meta.write(config, path);
}
@NotNull
public NightItem copy() {
- return new NightItem(this.itemStack, this.meta.copy());
+ NightItem copy = new NightItem(this.backend, this.meta.copy());
+ copy.setMaterial(this.material);
+ copy.setAmount(this.amount);
+ return copy;
}
@NotNull
+ @Deprecated
public NightItem inherit(@NotNull NightItem other) {
- this.itemStack.setType(other.getMaterial());
- this.itemStack.setAmount(other.getAmount());
+ this.backend.setType(other.getMaterial());
+ this.backend.setAmount(other.getAmount());
this.meta.inherit(other.meta);
return this;
@@ -126,8 +137,11 @@ public class NightItem implements Writeable {
*/
@NotNull
public ItemStack getItemStack() {
- ItemStack stack = new ItemStack(this.itemStack);
- this.meta.apply(stack/*, true*/);
+ ItemStack stack = Engine.software().setType(this.backend, this.material);
+
+ stack.setAmount(this.amount);
+
+ this.meta.apply(stack);
return stack;
}
@@ -138,22 +152,24 @@ public class NightItem implements Writeable {
@NotNull
public Material getMaterial() {
- return this.itemStack.getType();
+ return this.material;
}
@NotNull
public NightItem setMaterial(@NotNull Material material) {
- this.itemStack.setType(material);
+ if (!material.isItem()) throw new IllegalStateException("Material " + material.name() + " is not item!");
+
+ this.material = material;
return this;
}
public int getAmount() {
- return this.itemStack.getAmount();
+ return this.amount;
}
@NotNull
public NightItem setAmount(int amount) {
- this.itemStack.setAmount(amount);
+ this.amount = NumberUtil.clamp(amount, 1, this.material.getMaxStackSize());
return this;
}
@@ -244,33 +260,73 @@ public class NightItem implements Writeable {
}
@NotNull
+ @Deprecated
public NightItem setSkinURL(@Nullable String skinURL) {
this.meta.setSkinURL(skinURL);
return this;
}
- @Nullable
- public PlayerProfile getSkullOwner() {
- return this.meta.getSkullOwner();
- }
+// @Nullable
+// @Deprecated
+// public PlayerProfile getSkullOwner() {
+// return this.meta.getSkullOwner();
+// }
@NotNull
+ @Deprecated
public NightItem setSkullOwner(@Nullable OfflinePlayer owner) {
- return this.setSkullOwner(owner == null ? null : owner.getPlayerProfile());
+ this.meta.setSkullOwner(owner);
+ return this;
+ }
+
+// @NotNull
+// @Deprecated
+// public NightItem setSkullOwner(@Nullable PlayerProfile skullOwner) {
+// this.meta.setSkullOwner(skullOwner);
+// return this;
+// }
+
+ @Nullable
+ public NightProfile getPlayerProfile() {
+ return this.meta.getPlayerProfile();
}
@NotNull
- public NightItem setSkullOwner(@Nullable PlayerProfile skullOwner) {
- this.meta.setSkullOwner(skullOwner);
+ public NightItem setProfileBySkinURL(@NotNull String skinURL) {
+ this.meta.setProfileBySkinURL(skinURL);
return this;
}
@NotNull
+ public NightItem setPlayerProfile(@NotNull OfflinePlayer player) {
+ this.meta.setPlayerProfile(player);
+ return this;
+ }
+
+ @NotNull
+ public NightItem setPlayerProfile(@Nullable NightProfile profile) {
+ this.meta.setPlayerProfile(profile);
+ return this;
+ }
+
+ @NotNull
+ @Deprecated
public NightItem setModelData(@Nullable Integer modelData) {
this.meta.setModelData(modelData);
return this;
}
+ @Nullable
+ public Float getCustomModelData() {
+ return this.meta.getCustomModelData();
+ }
+
+ @NotNull
+ public NightItem setCustomModelData(@Nullable Float modelData) {
+ this.meta.setCustomModelData(modelData);
+ return this;
+ }
+
@NotNull
public NightItem setModelPath(@Nullable NamespacedKey modelPath) {
this.meta.setModelPath(modelPath);
@@ -302,8 +358,21 @@ public class NightItem implements Writeable {
}
@NotNull
+ @Deprecated
public NightItem setHideComponents(boolean hideComponents) {
- this.meta.setHideComponents(hideComponents);
+ //this.meta.setHideComponents(hideComponents);
+ return hideComponents ? this.hideAllComponents() : this.showAllComponents();
+ }
+
+ @NotNull
+ public NightItem hideAllComponents() {
+ this.meta.hideAllComponents();
+ return this;
+ }
+
+ @NotNull
+ public NightItem showAllComponents() {
+ this.meta.showAllComponents();
return this;
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java
similarity index 74%
rename from src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java
rename to main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java
index a99ff39..9589c4a 100644
--- a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightMeta.java
@@ -8,9 +8,11 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
-import org.bukkit.profile.PlayerProfile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.bridge.spigot.SpigotBridge;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.config.Writeable;
import su.nightexpress.nightcore.core.CoreLang;
@@ -22,6 +24,7 @@ import su.nightexpress.nightcore.util.placeholder.Replacer;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
public class NightMeta implements Writeable {
@@ -29,19 +32,18 @@ public class NightMeta implements Writeable {
private String displayName;
private List lore;
private Map enchants;
+ private Set hiddenComponents;
- private Integer damage;
- private String skinURL;
- private PlayerProfile skullOwner;
- private Color color;
+ private Integer damage;
+ private NightProfile playerProfile;
+ private Color color;
- private Integer modelData;
+ private Float modelData;
private NamespacedKey modelPath;
private NamespacedKey tooltipStyle;
private boolean unbreakable;
private boolean enchantGlint;
- private boolean hideComponents;
private boolean hideTooltip;
private Replacer replacer;
@@ -59,19 +61,20 @@ public class NightMeta implements Writeable {
.setDisplayName(this.displayName)
.setLore(this.lore == null ? null : new ArrayList<>(this.lore))
.setEnchants(this.enchants)
- .setSkinURL(this.skinURL)
- .setSkullOwner(this.skullOwner)
+ //.setSkinURL(this.skinURL)
+ .setPlayerProfile(this.playerProfile)
.setColor(this.color)
- .setModelData(this.modelData)
+ .setCustomModelData(this.modelData)
.setModelPath(this.modelPath)
.setTooltipStyle(this.tooltipStyle)
.setEnchantGlint(this.enchantGlint)
- .setHideComponents(this.hideComponents)
+ .setHiddenComponents(this.hiddenComponents)
.setHideTooltip(this.hideTooltip)
.setReplacer(this.replacer == null ? null : new Replacer(this.replacer));
}
@NotNull
+ @Deprecated
public NightMeta inherit(@NotNull NightMeta other) {
return this
.setDamage(other.damage)
@@ -80,14 +83,14 @@ public class NightMeta implements Writeable {
.setDisplayName(other.displayName)
.setLore(other.lore == null ? null : new ArrayList<>(other.lore))
.setEnchants(other.enchants)
- .setSkinURL(other.skinURL)
- .setSkullOwner(other.skullOwner)
+ //.setSkinURL(other.skinURL)
+ .setPlayerProfile(other.playerProfile)
.setColor(other.color)
- .setModelData(other.modelData)
+ .setCustomModelData(other.modelData)
.setModelPath(other.modelPath)
.setTooltipStyle(other.tooltipStyle)
.setEnchantGlint(other.enchantGlint)
- .setHideComponents(other.hideComponents)
+ .setHiddenComponents(other.hiddenComponents)
.setHideTooltip(other.hideTooltip)
.setReplacer(other.replacer == null ? null : new Replacer(other.replacer));
}
@@ -102,18 +105,19 @@ public class NightMeta implements Writeable {
if (meta instanceof Damageable damageable && damageable.getDamage() != 0) {
displayMeta.setDamage(damageable.getDamage());
}
- if (meta instanceof SkullMeta skullMeta) {
- displayMeta.setSkullOwner(skullMeta.getOwnerProfile());
- }
+// if (meta instanceof SkullMeta skullMeta) {
+//
+// }
- displayMeta.setDisplayName(meta.hasDisplayName() ? ItemUtil.getSerializedDisplayName(meta)/*meta.getDisplayName()*/ : null);
- displayMeta.setLore(ItemUtil.getSerializedLore(meta));
+ displayMeta.setDisplayName(ItemUtil.getCustomNameSerialized(meta));
+ displayMeta.setItemName(ItemUtil.getItemNameSerialized(meta));
+ displayMeta.setLore(ItemUtil.getLoreSerialized(meta));
displayMeta.setEnchants(meta.getEnchants());
displayMeta.setUnbreakable(meta.isUnbreakable());
- displayMeta.setSkinURL(ItemUtil.getHeadSkin(itemStack));
- displayMeta.setModelData(meta.hasCustomModelData() ? meta.getCustomModelData() : null);
+ displayMeta.setPlayerProfile(ItemUtil.getOwnerProfile(itemStack));
+ //displayMeta.setSkinURL(ItemUtil.getHeadSkin(itemStack));
+ displayMeta.setCustomModelData(ItemUtil.getCustomModelData(meta));
if (Version.isAtLeast(Version.MC_1_21)) {
- displayMeta.setItemName(meta.hasItemName() ? ItemUtil.getSerializedItemName(meta)/*meta.getItemName()*/ : null);
displayMeta.setEnchantGlint((meta.hasEnchantmentGlintOverride() && meta.getEnchantmentGlintOverride())/* || meta.hasEnchants()*/);
displayMeta.setHideTooltip(meta.isHideTooltip());
}
@@ -121,7 +125,14 @@ public class NightMeta implements Writeable {
displayMeta.setModelPath(meta.getItemModel());
displayMeta.setTooltipStyle(meta.getTooltipStyle());
}
- displayMeta.setHideComponents(!meta.getItemFlags().isEmpty());
+ if (Version.isAtLeast(Version.MC_1_21_5)) {
+ displayMeta.setHiddenComponents(Engine.software().getHiddenComponents(itemStack));
+ }
+ else {
+ displayMeta.setHiddenComponents(meta.getItemFlags().stream().map(Enum::name).collect(Collectors.toSet()));
+ //if (!meta.getItemFlags().isEmpty()) displayMeta.hideAllComponents();
+ }
+ //displayMeta.setHideComponents(!meta.getItemFlags().isEmpty());
if (meta instanceof LeatherArmorMeta armorMeta) {
displayMeta.setColor(armorMeta.getColor());
@@ -188,7 +199,11 @@ public class NightMeta implements Writeable {
displayMeta.setItemName(config.getString(path + ".Item_Name"));
displayMeta.setDisplayName(config.getString(path + ".Display_Name"));
displayMeta.setLore(config.getStringList(path + ".Lore"));
- displayMeta.setSkinURL(config.getString(path + ".SkinURL"));
+
+ String skinURL = config.getString(path + ".SkinURL");
+ if (skinURL != null) {
+ displayMeta.setProfileBySkinURL(skinURL);
+ }
Map enchants = new HashMap<>();
config.getSection(path + ".Enchants").forEach(sId -> {
@@ -201,7 +216,7 @@ public class NightMeta implements Writeable {
displayMeta.setEnchants(enchants);
if (config.contains(path + ".Model.Data")) {
- displayMeta.setModelData(config.getInt(path + ".Model.Data"));
+ displayMeta.setCustomModelData((float) config.getDouble(path + ".Model.Data"));
}
if (config.contains(path + ".Model.Path")) {
String packPath = config.getString(path + ".Model.Path");
@@ -220,9 +235,12 @@ public class NightMeta implements Writeable {
displayMeta.setUnbreakable(config.getBoolean(path + ".Durabilities.Unbreakable", false));
displayMeta.setEnchantGlint(config.getBoolean(path + ".Enchant_Glint", false));
- displayMeta.setHideComponents(config.getBoolean(path + ".Hide_Components", false));
displayMeta.setHideTooltip(config.getBoolean(path + ".Hide_Tooltip", false));
+ if (config.getBoolean(path + ".Hide_Components", false)) {
+ displayMeta.setHiddenComponents(Engine.software().getCommonComponentsToHide());
+ }
+
String rawColor = config.getString(path + ".Color");
Color color = rawColor == null ? null : StringUtil.getColor(rawColor);
displayMeta.setColor(color);
@@ -234,43 +252,44 @@ public class NightMeta implements Writeable {
public void write(@NotNull FileConfig config, @NotNull String path) {
config.remove(path + ".Enchants");
- config.set(path + ".Item_Name", /*this.itemName == null || this.itemName.isBlank() ? null :*/ this.itemName);
- config.set(path + ".Display_Name", /*this.displayName == null || this.displayName.isBlank() ? null :*/ this.displayName);
+ config.set(path + ".Item_Name", this.itemName);
+ config.set(path + ".Display_Name", this.displayName);
config.set(path + ".Lore", this.lore);
if (this.enchants != null) {
- this.enchants.forEach((enchantment, level) -> config.set(path + ".Enchants." + BukkitThing.toString(enchantment), level));
+ this.enchants.forEach((enchantment, level) -> config.set(path + ".Enchants." + BukkitThing.getAsString(enchantment), level));
}
- config.set(path + ".SkinURL", this.skinURL);
+ config.set(path + ".SkinURL", this.playerProfile == null ? null : Players.getProfileSkinURL(this.playerProfile));
config.set(path + ".Model.Data", this.modelData);
config.set(path + ".Model.Path", this.modelPath == null ? null : this.modelPath.getKey());
config.set(path + ".Tooltip.Style", this.tooltipStyle == null ? null : this.tooltipStyle.getKey());
config.set(path + ".Durabilities.Damage", this.damage);
config.set(path + ".Durabilities.Unbreakable", this.unbreakable ? true : null);
config.set(path + ".Enchant_Glint", this.enchantGlint ? true : null);
- config.set(path + ".Hide_Components", this.hideComponents ? true : null);
+ config.set(path + ".Hide_Components", this.hiddenComponents != null && !this.hiddenComponents.isEmpty() ? true : null);
config.set(path + ".Hide_Tooltip", this.hideTooltip ? true : null);
config.set(path + ".Color", this.color == null ? null : color.getRed() + "," + color.getBlue() + "," + color.getGreen());
}
- public void apply(@NotNull ItemStack itemStack/*, boolean legacy*/) {
+ public void apply(@NotNull ItemStack itemStack) {
ItemUtil.editMeta(itemStack, meta -> {
+ if (meta instanceof SkullMeta skullMeta) {
+ if (this.playerProfile != null) this.playerProfile.apply(skullMeta);
+ }
+
if (this.displayName != null) {
String name = this.replacer == null ? this.displayName : this.replacer.apply(this.displayName);
- ItemUtil.setDisplayName(meta, name);
- //meta.setDisplayName(legacy ? NightMessage.asLegacy(name) : name);
+ ItemUtil.setCustomName(meta, name);
}
if (this.itemName != null && Version.isAtLeast(Version.MC_1_21)) {
String name = this.replacer == null ? this.itemName : this.replacer.apply(this.itemName);
ItemUtil.setItemName(meta, name);
- //meta.setItemName(name == null ? null : (legacy ? NightMessage.asLegacy(name) : name));
}
if (this.lore != null) {
List lore = this.replacer == null ? this.lore : this.replacer.apply(this.lore);
ItemUtil.setLore(meta, this.addEmptyLines(lore));
- //meta.setLore(legacy ? NightMessage.asLegacy(this.addEmptyLines(lore)) : this.addEmptyLines(lore));
}
if (this.modelData != null) {
- meta.setCustomModelData(this.modelData);
+ ItemUtil.setCustomModelData(meta, this.modelData);
}
if (this.enchants != null) {
meta.getEnchants().keySet().forEach(meta::removeEnchant);
@@ -279,10 +298,6 @@ public class NightMeta implements Writeable {
meta.setUnbreakable(this.unbreakable);
-// if (this.hideComponents) {
-// ItemUtil.hideAttributes(meta, itemStack.getType());
-// }
-
if (Version.isAtLeast(Version.MC_1_21)) {
if (this.enchantGlint) meta.setEnchantmentGlintOverride(true);
if (this.hideTooltip) meta.setHideTooltip(true);
@@ -295,10 +310,6 @@ public class NightMeta implements Writeable {
if (this.damage != null && meta instanceof Damageable damageable) {
damageable.setDamage(this.damage);
}
- if (meta instanceof SkullMeta skullMeta) {
- PlayerProfile profile = this.skinURL != null ? ItemUtil.createSkinProfile(this.skinURL) : this.skullOwner;
- skullMeta.setOwnerProfile(profile);
- }
if (this.color != null) {
switch (meta) {
@@ -309,8 +320,14 @@ public class NightMeta implements Writeable {
}
});
- if (this.hideComponents && !this.hideTooltip) {
- ItemUtil.hideAttributes(itemStack);
+ if (this.hiddenComponents != null && !this.hiddenComponents.isEmpty() && !this.hideTooltip) {
+ if (Version.isAtLeast(Version.MC_1_21_5)) {
+ Engine.software().hideComponents(itemStack, this.hiddenComponents);
+ }
+ else {
+ SpigotBridge.hideComponentsByName(itemStack, this.hiddenComponents);
+ //ItemUtil.hideAttributes(itemStack);
+ }
}
}
@@ -440,37 +457,103 @@ public class NightMeta implements Writeable {
return this;
}
+ @NotNull
+ public Set getHiddenComponents() {
+ return this.hiddenComponents;
+ }
+
+ public NightMeta setHiddenComponents(@Nullable Set hiddenComponents) {
+ this.hiddenComponents = hiddenComponents;
+ return this;
+ }
+
+ public NightMeta addHiddenComponent(@NotNull String component) {
+ this.hiddenComponents.add(component);
+ return this;
+ }
+
+ public NightMeta hideAllComponents() {
+ this.setHiddenComponents(Engine.software().getCommonComponentsToHide());
+ return this;
+ }
+
+ public NightMeta showAllComponents() {
+ this.setHiddenComponents(null);
+ return this;
+ }
+
+
+
+ @Deprecated
+ @Nullable
public String getSkinURL() {
- return skinURL;
+ return this.playerProfile == null ? null : Players.getProfileSkinURL(this.playerProfile);
}
+ @Deprecated
public NightMeta setSkinURL(@Nullable String skinURL) {
- this.skinURL = skinURL;
- return this;
+ return skinURL == null ? this.setPlayerProfile((NightProfile) null) : this.setProfileBySkinURL(skinURL);
}
- @Nullable
- public PlayerProfile getSkullOwner() {
- return this.skullOwner;
- }
+// @Nullable
+// @Deprecated
+// public PlayerProfile getSkullOwner() {
+// return this.getPlayerProfile();
+// }
@NotNull
+ @Deprecated
public NightMeta setSkullOwner(@Nullable OfflinePlayer owner) {
- return this.setSkullOwner(owner == null ? null : owner.getPlayerProfile());
+ return this.setPlayerProfile(owner == null ? null : Players.getProfile(owner));
}
@NotNull
- public NightMeta setSkullOwner(@Nullable PlayerProfile skullOwner) {
- this.skullOwner = skullOwner;
- return this;
+ @Deprecated
+ public NightMeta setSkullOwner(@Nullable NightProfile skullOwner) {
+ return this.setPlayerProfile(skullOwner);
}
@Nullable
+ public NightProfile getPlayerProfile() {
+ return this.playerProfile;
+ }
+
+ @NotNull
+ public NightMeta setProfileBySkinURL(@NotNull String skinURL) {
+ return this.setPlayerProfile(Players.createProfileBySkinURL(skinURL));
+ }
+
+ @NotNull
+ public NightMeta setPlayerProfile(@NotNull OfflinePlayer player) {
+ return this.setPlayerProfile(Players.getProfile(player));
+ }
+
+ @NotNull
+ public NightMeta setPlayerProfile(@Nullable NightProfile profile) {
+ this.playerProfile = profile;
+ return this;
+ }
+
+
+
+ @Nullable
+ @Deprecated
public Integer getModelData() {
+ return this.modelData == null ? null : this.modelData.intValue();
+ }
+
+ @Deprecated
+ public NightMeta setModelData(@Nullable Integer modelData) {
+ return this.setCustomModelData(modelData == null ? null : modelData.floatValue());
+ }
+
+ @Nullable
+ public Float getCustomModelData() {
return this.modelData;
}
- public NightMeta setModelData(@Nullable Integer modelData) {
+ @NotNull
+ public NightMeta setCustomModelData(@Nullable Float modelData) {
this.modelData = modelData;
return this;
}
@@ -522,13 +605,16 @@ public class NightMeta implements Writeable {
return this;
}
+ @Deprecated
public boolean isHideComponents() {
- return hideComponents;
+ return !this.hiddenComponents.isEmpty();// hideComponents;
}
+ @Deprecated
public NightMeta setHideComponents(boolean hideComponents) {
- this.hideComponents = hideComponents;
- return this;
+ //this.hideComponents = hideComponents;
+// this.setHiddenComponents(Version.software().getCommonComponentsToHide());
+ return hideComponents ? this.hideAllComponents() : this.showAllComponents();
}
public boolean isHideTooltip() {
diff --git a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java
similarity index 86%
rename from src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java
rename to main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java
index 96db0b8..1d36719 100644
--- a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightSound.java
@@ -10,10 +10,11 @@ import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.config.Writeable;
import su.nightexpress.nightcore.util.BukkitThing;
import su.nightexpress.nightcore.util.NumberUtil;
+import su.nightexpress.nightcore.util.StringUtil;
public class NightSound implements Writeable {
- private static final String DELIMITER = ":";
+ private static final String DELIMITER = ";";
private static final float MIN_PITCH = 0.5f;
private static final float MAX_PITCH = 2.0f;
@@ -50,14 +51,14 @@ public class NightSound implements Writeable {
@NotNull
public static NightSound of(@NotNull String name, float volume, float pitch) {
- Sound bukkit = BukkitThing.getSound(name);
+ Sound bukkit = BukkitThing.getSound(StringUtil.transformForID(name));
return new NightSound(name, bukkit, volume, pitch);
}
@NotNull
public static NightSound deserialize(@NotNull String from) {
- String[] split = from.split(DELIMITER);
+ String[] split = fix(from).split(DELIMITER);
String name = split[0];
float volume = split.length >= 2 ? (float) NumberUtil.getDoubleAbs(split[1], MAX_VOLUME) : MAX_VOLUME;
@@ -72,9 +73,7 @@ public class NightSound implements Writeable {
}
@NotNull
- @Deprecated
public static NightSound read(@NotNull FileConfig config, @NotNull String path) {
-
if (config.contains(path + ".Name")) {
String oldName = config.getString(path + ".Name", "null");
float volume = (float) config.getDouble(path + ".Volume");
@@ -85,11 +84,22 @@ public class NightSound implements Writeable {
config.set(path, old.serialize());
}
- return deserialize(config.getString(path, "null"));
+ String raw = config.getString(path, "null");
+
+ return deserialize(raw);
+ }
+
+ private static String fix(String raw) {
+ String[] split = raw.split(":");
+ if (split.length == 4) {
+ raw = split[0] + ":" + split[1] + DELIMITER + split[2] + DELIMITER + split[3];
+ }
+ else raw = raw.replace(":", DELIMITER);
+
+ return raw;
}
@Override
- @Deprecated
public void write(@NotNull FileConfig config, @NotNull String path) {
config.set(path, this.serialize());
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/bukkit/NightTask.java b/main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightTask.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/bukkit/NightTask.java
rename to main/src/main/java/su/nightexpress/nightcore/util/bukkit/NightTask.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java
similarity index 94%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java
index 97fe866..2ced569 100644
--- a/src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/geodata/Cuboid.java
@@ -63,6 +63,14 @@ public class Cuboid {
this.intersectingChunks = new HashSet<>(this.getIntersectingChunks());
}
+ @NotNull
+ public Cuboid maxHeight(@NotNull World world) {
+ BlockPos min = new BlockPos(this.min.getX(), world.getMinHeight(), this.min.getZ());
+ BlockPos max = new BlockPos(this.max.getX(), world.getMaxHeight(), this.max.getZ());
+
+ return new Cuboid(min, max);
+ }
+
public boolean isSimilar(@NotNull Cuboid other) {
if (this.isEmpty() || other.isEmpty()) return false;
@@ -270,8 +278,12 @@ public class Cuboid {
}
public int getVolume() {
+ return this.getVolume(DimensionType._3D);
+ }
+
+ public int getVolume(@NotNull DimensionType dimensionType) {
int xLength = this.max.getX() - this.min.getX() + 1;
- int yLength = this.max.getY() - this.min.getY() + 1;
+ int yLength = dimensionType == DimensionType._2D ? 1 : this.max.getY() - this.min.getY() + 1;
int zLength = this.max.getZ() - this.min.getZ() + 1;
return xLength * zLength * yLength;
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/DimensionType.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/DimensionType.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/DimensionType.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/DimensionType.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/GeoUtils.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/GeoUtils.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/GeoUtils.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/GeoUtils.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/pos/BlockPos.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/BlockPos.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/pos/BlockPos.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/BlockPos.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ChunkPos.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ChunkPos.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/pos/ChunkPos.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ChunkPos.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ExactPos.java b/main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ExactPos.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/geodata/pos/ExactPos.java
rename to main/src/main/java/su/nightexpress/nightcore/util/geodata/pos/ExactPos.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/number/CompactNumber.java b/main/src/main/java/su/nightexpress/nightcore/util/number/CompactNumber.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/number/CompactNumber.java
rename to main/src/main/java/su/nightexpress/nightcore/util/number/CompactNumber.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/number/NumberShortcut.java b/main/src/main/java/su/nightexpress/nightcore/util/number/NumberShortcut.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/number/NumberShortcut.java
rename to main/src/main/java/su/nightexpress/nightcore/util/number/NumberShortcut.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/placeholder/Placeholder.java b/main/src/main/java/su/nightexpress/nightcore/util/placeholder/Placeholder.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/placeholder/Placeholder.java
rename to main/src/main/java/su/nightexpress/nightcore/util/placeholder/Placeholder.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderEntry.java b/main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderEntry.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderEntry.java
rename to main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderEntry.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderList.java b/main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderList.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderList.java
rename to main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderList.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderMap.java b/main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderMap.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/placeholder/PlaceholderMap.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/placeholder/Replacer.java b/main/src/main/java/su/nightexpress/nightcore/util/placeholder/Replacer.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/placeholder/Replacer.java
rename to main/src/main/java/su/nightexpress/nightcore/util/placeholder/Replacer.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java b/main/src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java
rename to main/src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java
index fc28dc6..cfe1f76 100644
--- a/src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/random/MTRandom.java
@@ -16,7 +16,7 @@ public class MTRandom extends Random {
private final static int MAGIC_MASK1 = 0x9d2c5680;
private final static int MAGIC_MASK2 = 0xefc60000;
private final static int MAGIC_SEED = 19650218;
- private final static long DEFAULT_SEED = 5489L;
+ //private final static long DEFAULT_SEED = 5489L;
// Internal state
private transient int[] mt;
diff --git a/src/main/java/su/nightexpress/nightcore/util/random/Rnd.java b/main/src/main/java/su/nightexpress/nightcore/util/random/Rnd.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/random/Rnd.java
rename to main/src/main/java/su/nightexpress/nightcore/util/random/Rnd.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/random/WeightedItem.java b/main/src/main/java/su/nightexpress/nightcore/util/random/WeightedItem.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/random/WeightedItem.java
rename to main/src/main/java/su/nightexpress/nightcore/util/random/WeightedItem.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java
similarity index 99%
rename from src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java
index f631b50..20bb5bc 100644
--- a/src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/DoubleRankMap.java
@@ -7,6 +7,7 @@ import su.nightexpress.nightcore.config.FileConfig;
import java.util.Map;
import java.util.function.Function;
+@Deprecated
public class DoubleRankMap extends RankMap {
public static final Creator CREATOR = DoubleRankMap::new;
diff --git a/src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java
similarity index 99%
rename from src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java
index 5f45032..65b3773 100644
--- a/src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/IntRankMap.java
@@ -7,6 +7,7 @@ import su.nightexpress.nightcore.config.FileConfig;
import java.util.Map;
import java.util.function.Function;
+@Deprecated
public class IntRankMap extends RankMap {
public static final Creator CREATOR = IntRankMap::new;
diff --git a/src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java
similarity index 99%
rename from src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java
index 187b058..d7d4c3c 100644
--- a/src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/LongRankMap.java
@@ -7,6 +7,7 @@ import su.nightexpress.nightcore.config.FileConfig;
import java.util.Map;
import java.util.function.Function;
+@Deprecated
public class LongRankMap extends RankMap {
public static final Creator CREATOR = LongRankMap::new;
diff --git a/src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java
rename to main/src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java
index c9d6869..7362448 100644
--- a/src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/rankmap/RankMap.java
@@ -5,14 +5,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.config.ConfigValue;
import su.nightexpress.nightcore.config.FileConfig;
+import su.nightexpress.nightcore.util.Enums;
import su.nightexpress.nightcore.util.Players;
-import su.nightexpress.nightcore.util.StringUtil;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
+@Deprecated
public abstract class RankMap {
private final Mode mode;
@@ -63,7 +64,7 @@ public abstract class RankMap {
@NotNull Creator creator,
@NotNull Function converter) {
Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK,
- "Available values: " + StringUtil.inlineEnum(Mode.class, ", "),
+ "Available values: " + Enums.inline(Mode.class),
"=".repeat(20) + " " + Mode.RANK.name() + " MODE " + "=".repeat(20),
"Get value by player's permission group. All keys in 'Values' list will represent permission group names.",
"If player has none of specified groups, the 'Default_Value' setting will be used then",
diff --git a/src/main/java/su/nightexpress/nightcore/util/regex/MatcherTimeoutException.java b/main/src/main/java/su/nightexpress/nightcore/util/regex/MatcherTimeoutException.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/regex/MatcherTimeoutException.java
rename to main/src/main/java/su/nightexpress/nightcore/util/regex/MatcherTimeoutException.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java b/main/src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java
similarity index 82%
rename from src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java
rename to main/src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java
index 83014cf..a64430a 100644
--- a/src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/regex/TimedMatcher.java
@@ -1,7 +1,7 @@
package su.nightexpress.nightcore.util.regex;
import org.jetbrains.annotations.NotNull;
-import su.nightexpress.nightcore.util.Plugins;
+import su.nightexpress.nightcore.Engine;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -63,7 +63,7 @@ public class TimedMatcher {
}
catch (MatcherTimeoutException exception) {
if (this.isDebug()) {
- Plugins.getCore().warn("Matcher " + exception.getTimeout() + "ms timeout error for replaceAll: '" + matcher.pattern().pattern() + "'.");
+ Engine.core().warn("Matcher " + exception.getTimeout() + "ms timeout error for replaceAll: '" + matcher.pattern().pattern() + "'.");
}
return "";
}
@@ -75,7 +75,7 @@ public class TimedMatcher {
}
catch (MatcherTimeoutException exception) {
if (this.isDebug()) {
- Plugins.getCore().warn("Matcher " + exception.getTimeout() + "ms timeout error for: '" + matcher.pattern().pattern() + "'.");
+ Engine.core().warn("Matcher " + exception.getTimeout() + "ms timeout error for: '" + matcher.pattern().pattern() + "'.");
}
return false;
}
@@ -87,7 +87,7 @@ public class TimedMatcher {
}
catch (MatcherTimeoutException exception) {
if (this.isDebug()) {
- Plugins.getCore().warn("Matcher " + exception.getTimeout() + "ms timeout error for: '" + matcher.pattern().pattern() + "'.");
+ Engine.core().warn("Matcher " + exception.getTimeout() + "ms timeout error for: '" + matcher.pattern().pattern() + "'.");
}
return false;
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/regex/TimeoutCharSequence.java b/main/src/main/java/su/nightexpress/nightcore/util/regex/TimeoutCharSequence.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/regex/TimeoutCharSequence.java
rename to main/src/main/java/su/nightexpress/nightcore/util/regex/TimeoutCharSequence.java
diff --git a/main/src/main/java/su/nightexpress/nightcore/util/text/LangNode.java b/main/src/main/java/su/nightexpress/nightcore/util/text/LangNode.java
new file mode 100644
index 0000000..e51f95c
--- /dev/null
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/LangNode.java
@@ -0,0 +1,41 @@
+package su.nightexpress.nightcore.util.text;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
+import su.nightexpress.nightcore.util.text.tag.decorator.ColorDecorator;
+
+public class LangNode extends TextChildren {
+
+ private final String key;
+ private final String fallback;
+
+ public LangNode(@NotNull TextGroup parent, @NotNull String key, @Nullable String fallback) {
+ super(parent);
+ this.key = key;
+ this.fallback = fallback;
+ }
+
+ @Override
+ public int textLength() {
+ return 1;
+ }
+
+ @Override
+ @NotNull
+ public NightComponent toComponent() {
+ ColorDecorator colorDecorator = this.parent.getColor();
+ NightComponent textComponent = Engine.software().translateComponent(this.key, this.fallback);
+
+ if (colorDecorator != null) {
+ colorDecorator.decorate(textComponent);
+ }
+
+ this.parent.getDecorators().forEach(decorator -> {
+ decorator.decorate(textComponent);
+ });
+
+ return textComponent;
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java b/main/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
similarity index 96%
rename from src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
index c1c6c19..613f9f6 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
@@ -1,7 +1,6 @@
package su.nightexpress.nightcore.util.text;
import org.jetbrains.annotations.NotNull;
-import su.nightexpress.nightcore.util.Colorizer;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import su.nightexpress.nightcore.util.text.tag.TagPool;
import su.nightexpress.nightcore.util.text.tag.Tags;
@@ -59,7 +58,8 @@ public class NightMessage {
@NotNull
@Deprecated
public static String stripAll(@NotNull String string) {
- return Colorizer.strip(clean(string));
+ return stripTags(string);
+ //return clean(TagUtils.tagPlainHex(LegacyColors.plainColors(string)));
}
/**
diff --git a/main/src/main/java/su/nightexpress/nightcore/util/text/TextChildren.java b/main/src/main/java/su/nightexpress/nightcore/util/text/TextChildren.java
new file mode 100644
index 0000000..dbaed7b
--- /dev/null
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/TextChildren.java
@@ -0,0 +1,20 @@
+package su.nightexpress.nightcore.util.text;
+
+import org.jetbrains.annotations.NotNull;
+import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
+
+public abstract class TextChildren implements ComponentBuildable {
+
+ protected final TextGroup parent;
+
+ public TextChildren(@NotNull TextGroup parent) {
+ this.parent = parent;
+ }
+
+ @NotNull
+ public TextGroup getParent() {
+ return this.parent;
+ }
+
+ public abstract int textLength();
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java b/main/src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java
similarity index 77%
rename from src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java
index bbb8ca8..3aa563d 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/TextGroup.java
@@ -2,7 +2,8 @@ package su.nightexpress.nightcore.util.text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import su.nightexpress.nightcore.util.Version;
+import su.nightexpress.nightcore.Engine;
+import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import su.nightexpress.nightcore.util.text.tag.decorator.ColorDecorator;
import su.nightexpress.nightcore.util.text.tag.decorator.Decorator;
@@ -46,6 +47,13 @@ public class TextGroup implements ComponentBuildable {
return node;
}
+ @NotNull
+ public LangNode createLangNode(@NotNull String key, @Nullable String fallback) {
+ LangNode node = new LangNode(this, key, fallback);
+ this.childrens.add(node);
+ return node;
+ }
+
public void addDecorator(@NotNull Decorator decorator) {
if (decorator instanceof ColorDecorator color) {
this.colorDecorator = color;
@@ -63,8 +71,6 @@ public class TextGroup implements ComponentBuildable {
@Override
@NotNull
public NightComponent toComponent() {
- //ComponentBuilder builder = new ComponentBuilder();
-
// Gradient colors must be predefined based on text length.
// Text length is calculated from group's childrens that are TextNodes.
if (this.colorDecorator instanceof GradientColorDecorator gradientDecorator && !gradientDecorator.isCreated()) {
@@ -74,32 +80,9 @@ public class TextGroup implements ComponentBuildable {
gradientDecorator.createGradient(length.get()); // This will create and store Color[] array.
}
- return Version.software().buildComponent(this.childrens);
-
-// this.childrens.forEach(child -> {
-// BaseComponent childComponent = child.toComponent();
-// //if (!TextRoot.isEmpty(childComponent)) {
-// builder.append(childComponent);
-// //}
-// });
-//
-// return this.build(builder);
+ return Engine.software().buildComponent(this.childrens);
}
-// private BaseComponent build(@NotNull ComponentBuilder builder) {
-// if (Version.isAtLeast(Version.MC_1_20_6)) {
-// return builder.build();
-// }
-//
-// TextComponent base = new TextComponent();
-// if (!builder.getParts().isEmpty()) {
-// List cloned = new ArrayList<>(builder.getParts());
-// cloned.replaceAll(BaseComponent::duplicate);
-// base.setExtra(cloned);
-// }
-// return base;
-// }
-
private void countLength(@NotNull TextGroup parent, @NotNull AtomicInteger length) {
for (ComponentBuildable buildable : parent.getChildrens()) {
if (buildable instanceof TextNode textNode) {
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/TextNode.java b/main/src/main/java/su/nightexpress/nightcore/util/text/TextNode.java
similarity index 62%
rename from src/main/java/su/nightexpress/nightcore/util/text/TextNode.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/TextNode.java
index 7b5aaa5..f3cbab2 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/TextNode.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/TextNode.java
@@ -1,21 +1,17 @@
package su.nightexpress.nightcore.util.text;
import org.jetbrains.annotations.NotNull;
-import su.nightexpress.nightcore.util.Version;
-import su.nightexpress.nightcore.util.bridge.Software;
+import su.nightexpress.nightcore.Engine;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import su.nightexpress.nightcore.util.text.tag.decorator.ColorDecorator;
-public class TextNode implements ComponentBuildable {
+public class TextNode extends TextChildren {
private final StringBuilder textBuilder;
- private final TextGroup parent;
-
- private boolean translation;
public TextNode(@NotNull TextGroup parent) {
+ super(parent);
this.textBuilder = new StringBuilder();
- this.parent = parent;
}
public void append(char letter) {
@@ -26,23 +22,13 @@ public class TextNode implements ComponentBuildable {
this.textBuilder.append(str);
}
- public void setTranslation(boolean translation) {
- this.translation = translation;
- }
-
@NotNull
public StringBuilder getTextBuilder() {
- return textBuilder;
- }
-
- @NotNull
- public TextGroup getParent() {
- return parent;
+ return this.textBuilder;
}
+ @Override
public int textLength() {
- if (this.translation) return 1;
-
int legnth = 0;
for (int index = 0; index < this.textBuilder.length(); index++) {
char letter = this.textBuilder.charAt(index);
@@ -58,12 +44,8 @@ public class TextNode implements ComponentBuildable {
@NotNull
public NightComponent toComponent() {
String text = this.textBuilder.toString();
-
ColorDecorator colorDecorator = this.parent.getColor();
- Software software = Version.software();
-
- //BaseComponent textComponent = this.translation == null ? new TextComponent(text) : new TranslatableComponent(this.translation);
- NightComponent textComponent = this.translation ? software.translateComponent(text) : software.textComponent(text);
+ NightComponent textComponent = Engine.software().textComponent(text);
if (colorDecorator != null) {
colorDecorator.decorate(textComponent);
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java b/main/src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java
similarity index 92%
rename from src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java
index 9bae5e5..a5a7a6f 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/TextRoot.java
@@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.core.CoreConfig;
-import su.nightexpress.nightcore.util.Colorizer;
+import su.nightexpress.nightcore.util.LegacyColors;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import su.nightexpress.nightcore.util.text.tag.TagPool;
import su.nightexpress.nightcore.util.text.tag.TagUtils;
@@ -40,8 +40,9 @@ public class TextRoot {
public void setString(@NotNull String string) {
if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
- string = TagUtils.tagPlainHex(Colorizer.plain(string));
- string = TagUtils.replaceLegacyColors(string);
+ string = LegacyColors.plainColors(string); // Translate legacy colors to plain values: 'ยงa' -> '&a', 'ยงxยงfยงfยงfยงfยงfยงf' -> '#ffffff'.
+ string = TagUtils.tagPlainHex(string); // Wrap HEX colors in tags: '#ffffff' -> '<#ffffff>'.
+ string = TagUtils.replaceLegacyColors(string); // Replace legacy colors with named tags: '&c' -> ''.
}
this.string = string;
@@ -73,24 +74,20 @@ public class TextRoot {
public String toLegacy() {
this.parseIfAbsent();
- //if (this.string.isBlank() || isEmpty(this.component)) return "";
if (this.string.isBlank() || this.component.isEmpty()) return "";
return this.component.toLegacy();
- //return TextComponent.toLegacyText(this.parseIfAbsent());
}
@NotNull
public String toJson() {
return this.parseIfAbsent().toJson();
- //return ComponentSerializer.toString(this.parseIfAbsent());
}
@NotNull
@Deprecated
public NightComponent toComponent() {
return this.parseIfAbsent();
- //return TextComponent.fromArray(this.parseIfAbsent());
}
@NotNull
@@ -109,7 +106,6 @@ public class TextRoot {
this.parseIfAbsent();
for (CommandSender sender : senders) {
this.component.send(sender);
- //sender.spigot().sendMessage(this.component);
}
}
@@ -252,18 +248,17 @@ public class TextRoot {
if (closeTag && !tag.isCloseable()) return;
if (tag instanceof PlaceholderTag placeholderTag) {
- //if (!closeTag) {
- this.currentNode().append(placeholderTag.getValue()); // Insert it to the current node as if it was a regular text.
- //}
+ this.currentNode().append(placeholderTag.getValue()); // Insert it to the current node as if it was a regular text.
return;
}
if (tag instanceof TranslationTag) {
if (tagContent != null) {
+ int index = indexOfIgnoreEscaped(tagContent, TagUtils.SEMICOLON, 0);
+ String key = index < 0 ? tagContent : tagContent.substring(0, index);
+ String fallback = index < 0 || index >= tagContent.length() ? null : TagUtils.unquoted(tagContent.substring(index + 1));
+
// Create a new node exclusively for translation text.
- TextNode node = this.currentGroup.createNode();
- node.append(TagUtils.unquoted(tagContent));
- node.setTranslation(true);
- //this.currentGroup.createNode().setTranslation(TagUtils.unquoted(tagContent));
+ this.currentGroup.createLangNode(TagUtils.unquoted(key), fallback);
this.currentNode = null; // Reset current node so parser will create a new one after this one with translation.
}
return;
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/TagPool.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/TagPool.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/TagPool.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/TagPool.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java
similarity index 98%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java
index 34321ac..2ec4c82 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/TagUtils.java
@@ -38,7 +38,8 @@ public class TagUtils {
.replace("&m", Tags.STRIKETHROUGH::getBracketsName)
.replace("&n", Tags.UNDERLINED::getBracketsName)
.replace("&o", Tags.ITALIC::getBracketsName)
- .replace("&r", Tags.RESET::getBracketsName);
+ .replace("&r", Tags.RESET::getBracketsName)
+ ;
@NotNull
public static String replaceLegacyColors(@NotNull String string) {
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ComplexTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ComplexTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/api/ComplexTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ComplexTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ContentTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ContentTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/api/ContentTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/ContentTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/PlaceholderTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/PlaceholderTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/api/PlaceholderTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/PlaceholderTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/SimpleTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/SimpleTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/api/SimpleTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/SimpleTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/Tag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/Tag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/api/Tag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/api/Tag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/color/MinecraftColors.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/color/MinecraftColors.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/color/MinecraftColors.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/color/MinecraftColors.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/BaseColorDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/BaseColorDecorator.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/BaseColorDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/BaseColorDecorator.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ClickDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ClickDecorator.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ClickDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ClickDecorator.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ColorDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ColorDecorator.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ColorDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ColorDecorator.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/Decorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/Decorator.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/Decorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/Decorator.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/FontDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/FontDecorator.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/FontDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/FontDecorator.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java
similarity index 95%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java
index 49bcf02..834c96d 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/GradientColorDecorator.java
@@ -1,7 +1,7 @@
package su.nightexpress.nightcore.util.text.tag.decorator;
import org.jetbrains.annotations.NotNull;
-import su.nightexpress.nightcore.util.Version;
+import su.nightexpress.nightcore.Engine;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import java.awt.*;
@@ -76,7 +76,7 @@ public class GradientColorDecorator implements ColorDecorator {
for (char letter : component.getText().toCharArray()) {
if (!Character.isWhitespace(letter)) length++;
- childrens.add(Version.software().textComponent(String.valueOf(letter)));
+ childrens.add(Engine.software().textComponent(String.valueOf(letter)));
}
if (!this.isCreated()) {
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java
similarity index 88%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java
index 021e8c9..dd0cbb3 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowItemDecorator.java
@@ -48,7 +48,11 @@ public class ShowItemDecorator implements Decorator {
@Override
public void decorate(@NotNull NightComponent component) {
- component.setHoverEvent(HoverEventType.SHOW_ITEM, this.itemData);
+ ItemStack itemStack = ItemNbt.getHoverEventItem(this.itemData);
+ if (itemStack == null) return;
+
+ component.setHoverEvent(itemStack);
+ //component.setHoverEvent(HoverEventType.SHOW_ITEM, this.itemData);
//component.setHoverEvent(this.createEvent());
}
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java
similarity index 81%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java
index 3206105..4e0a4ce 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/decorator/ShowTextDecorator.java
@@ -3,8 +3,8 @@ package su.nightexpress.nightcore.util.text.tag.decorator;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.util.Lists;
import su.nightexpress.nightcore.util.Placeholders;
-import su.nightexpress.nightcore.util.bridge.wrapper.HoverEventType;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
+import su.nightexpress.nightcore.util.text.NightMessage;
import java.util.List;
@@ -38,7 +38,8 @@ public class ShowTextDecorator implements Decorator {
@Override
public void decorate(@NotNull NightComponent component) {
- component.setHoverEvent(HoverEventType.SHOW_TEXT, String.join(Placeholders.TAG_LINE_BREAK, this.text));
+ component.setHoverEvent(NightMessage.parse(String.join(Placeholders.TAG_LINE_BREAK, this.text)));
+ //component.setHoverEvent(HoverEventType.SHOW_TEXT, String.join(Placeholders.TAG_LINE_BREAK, this.text));
//component.setHoverEvent(this.createEvent());
}
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ClickTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ClickTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ClickTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ClickTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ColorTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ColorTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ColorTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ColorTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontStyleTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontStyleTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontStyleTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontStyleTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/FontTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/GradientTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java
similarity index 96%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java
index 0ae6549..f2b624e 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HexColorTag.java
@@ -14,7 +14,7 @@ public class HexColorTag extends Tag implements ContentTag {
public static final String NAME = "color";
public HexColorTag() {
- super(NAME, new String[]{"colour", "c"});
+ super("c", new String[]{"color", "colour"});
}
@NotNull
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/HoverTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ResetTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ResetTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ResetTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ResetTag.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java
rename to main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/ShortHexColorTag.java
diff --git a/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslationTag.java b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslationTag.java
new file mode 100644
index 0000000..611faa9
--- /dev/null
+++ b/main/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslationTag.java
@@ -0,0 +1,30 @@
+package su.nightexpress.nightcore.util.text.tag.impl;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.util.text.tag.TagUtils;
+import su.nightexpress.nightcore.util.text.tag.api.Tag;
+
+public class TranslationTag extends Tag {
+
+ public static final String NAME = "lang";
+
+ public TranslationTag() {
+ super(NAME, new String[]{"lang_or", "tr", "tr_or", "translation", "translation_or", "translate", "translate_or"});
+ }
+
+ @NotNull
+ public String wrap(@NotNull String translationKey) {
+ return this.wrap(translationKey, null);
+ }
+
+ @NotNull
+ public String wrap(@NotNull String translationKey, @Nullable String fallback) {
+ String full = this.getName() + TagUtils.SEMICOLON + TagUtils.quoted(translationKey);
+ if (fallback != null) {
+ full += TagUtils.SEMICOLON + TagUtils.quoted(fallback);
+ }
+
+ return TagUtils.brackets(full);
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/time/TimeFormatType.java b/main/src/main/java/su/nightexpress/nightcore/util/time/TimeFormatType.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/time/TimeFormatType.java
rename to main/src/main/java/su/nightexpress/nightcore/util/time/TimeFormatType.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/time/TimeFormats.java b/main/src/main/java/su/nightexpress/nightcore/util/time/TimeFormats.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/time/TimeFormats.java
rename to main/src/main/java/su/nightexpress/nightcore/util/time/TimeFormats.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniDouble.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniDouble.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniDouble.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniDouble.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniFormatter.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniFormatter.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniFormatter.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniFormatter.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniInt.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniInt.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniInt.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniInt.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniPermission.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniPermission.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniPermission.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniPermission.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java
diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniTask.java b/main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniTask.java
similarity index 100%
rename from src/main/java/su/nightexpress/nightcore/util/wrapper/UniTask.java
rename to main/src/main/java/su/nightexpress/nightcore/util/wrapper/UniTask.java
diff --git a/src/main/resources/lang/messages_cn.yml b/main/src/main/resources/lang/messages_cn.yml
similarity index 100%
rename from src/main/resources/lang/messages_cn.yml
rename to main/src/main/resources/lang/messages_cn.yml
diff --git a/src/main/resources/lang/messages_tw.yml b/main/src/main/resources/lang/messages_tw.yml
similarity index 100%
rename from src/main/resources/lang/messages_tw.yml
rename to main/src/main/resources/lang/messages_tw.yml
diff --git a/src/main/resources/paper-plugin.yml b/main/src/main/resources/paper-plugin.yml
similarity index 88%
rename from src/main/resources/paper-plugin.yml
rename to main/src/main/resources/paper-plugin.yml
index 06bd511..c5be43a 100644
--- a/src/main/resources/paper-plugin.yml
+++ b/main/src/main/resources/paper-plugin.yml
@@ -13,6 +13,9 @@ dependencies:
Vault:
required: false
join-classpath: true
+ LuckPerms:
+ required: false
+ join-classpath: true
PlaceholderAPI:
required: false
join-classpath: true
diff --git a/src/main/resources/plugin.yml b/main/src/main/resources/plugin.yml
similarity index 100%
rename from src/main/resources/plugin.yml
rename to main/src/main/resources/plugin.yml
diff --git a/paper/pom.xml b/paper/pom.xml
new file mode 100644
index 0000000..390bbf4
--- /dev/null
+++ b/paper/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ su.nightexpress.nightcore
+ nightcore
+ 2.7.6
+
+
+ paper
+
+
+ 21
+ 21
+ UTF-8
+
+
+
+
+ papermc
+ https://repo.papermc.io/repository/maven-public/
+
+
+
+
+
+ io.papermc.paper
+ paper-api
+ 1.21.5-R0.1-SNAPSHOT
+ provided
+
+
+
+ su.nightexpress.nightcore
+ bridge
+ 2.7.6
+
+
+
+
\ No newline at end of file
diff --git a/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperBridge.java b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperBridge.java
new file mode 100644
index 0000000..1e7e50d
--- /dev/null
+++ b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperBridge.java
@@ -0,0 +1,324 @@
+package su.nightexpress.nightcore.bridge.paper;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
+import io.papermc.paper.datacomponent.DataComponentType;
+import io.papermc.paper.datacomponent.DataComponentTypes;
+import io.papermc.paper.datacomponent.item.TooltipDisplay;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.title.Title;
+import net.kyori.adventure.translation.Translatable;
+import net.kyori.adventure.util.Ticks;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.command.Command;
+import org.bukkit.command.SimpleCommandMap;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.MenuType;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.potion.PotionEffectType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
+import su.nightexpress.nightcore.util.BukkitThing;
+import su.nightexpress.nightcore.util.Lists;
+import su.nightexpress.nightcore.util.Version;
+import su.nightexpress.nightcore.util.bridge.RegistryType;
+import su.nightexpress.nightcore.util.bridge.Software;
+import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
+import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
+
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+public class PaperBridge implements Software {
+
+ private Set commonComponentsToHide;
+
+ @Override
+ @NotNull
+ public String getName() {
+ return "paper-bridge";
+ }
+
+ @Override
+ public boolean isPaper() {
+ return true;
+ }
+
+ @Override
+ public boolean initialize() {
+ if (Version.isAtLeast(Version.MC_1_21_5)) {
+ this.commonComponentsToHide = BukkitThing.getAll(RegistryType.Paper.DATA_COMPONENT_TYPE);
+ this.commonComponentsToHide.remove(DataComponentTypes.LORE);
+ this.commonComponentsToHide.remove(DataComponentTypes.ITEM_NAME);
+ this.commonComponentsToHide.remove(DataComponentTypes.ITEM_MODEL);
+ this.commonComponentsToHide.remove(DataComponentTypes.CUSTOM_NAME);
+ this.commonComponentsToHide.remove(DataComponentTypes.CUSTOM_MODEL_DATA);
+ this.commonComponentsToHide.remove(DataComponentTypes.TOOLTIP_DISPLAY);
+ this.commonComponentsToHide.remove(DataComponentTypes.TOOLTIP_STYLE);
+ }
+
+ return true;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public int nextEntityId() {
+ return Bukkit.getUnsafe().nextEntityId();
+ }
+
+ @Override
+ @NotNull
+ public SimpleCommandMap getCommandMap() {
+ return (SimpleCommandMap) Bukkit.getCommandMap();
+ }
+
+ @Override
+ @NotNull
+ public Map getKnownCommands(@NotNull SimpleCommandMap commandMap) {
+ return commandMap.getKnownCommands();
+ }
+
+ @Override
+ @NotNull
+ public PaperComponent textComponent(@NotNull String text) {
+ return PaperComponent.text(text);
+ }
+
+ @Override
+ @NotNull
+ public PaperComponent translateComponent(@NotNull String key) {
+ return PaperComponent.translate(key);
+ }
+
+ @Override
+ @NotNull
+ public PaperComponent translateComponent(@NotNull String key, @Nullable String fallback) {
+ return PaperComponent.translate(key, fallback);
+ }
+
+ @Override
+ @NotNull
+ public PaperComponent buildComponent(@NotNull List childrens) {
+ return PaperComponent.builder(childrens);
+ }
+
+// @NotNull
+// private static Component fromNightComponent(@NotNull String component) {
+// return fromNightComponent(NightMessage.parse(component));
+// }
+
+ @NotNull
+ static Component fromNightComponent(@NotNull NightComponent component) {
+ return ((PaperComponent)component).getParent();
+ }
+
+ @NotNull
+ public static String serializeComponent(@NotNull Component component) {
+ return MiniMessage.miniMessage().serialize(component);
+ }
+
+ @Override
+ @NotNull
+ public NightProfile createProfile(@NotNull UUID uuid) {
+ return new PaperProfile(Bukkit.createProfile(uuid));
+ }
+
+ @Override
+ @NotNull
+ public NightProfile createProfile(@NotNull String name) {
+ return new PaperProfile(Bukkit.createProfile(name));
+ }
+
+ @Override
+ @NotNull
+ public NightProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
+ return new PaperProfile(Bukkit.createProfile(uuid, name));
+ }
+
+ @Override
+ @NotNull
+ public NightProfile getProfile(@NotNull OfflinePlayer player) {
+ return new PaperProfile(player.getPlayerProfile());
+ }
+
+ @Override
+ public void sendTitles(@NotNull Player player, @NotNull NightComponent title, @NotNull NightComponent subtitle, int fadeIn, int stay, int fadeOut) {
+ Component titleComp = fromNightComponent(title);
+ Component subComp = fromNightComponent(subtitle);
+
+ Title.Times times = Title.Times.times(Ticks.duration(fadeIn), Ticks.duration(stay), Ticks.duration(fadeIn));
+ Title titles = Title.title(titleComp, subComp, times);
+
+ player.showTitle(titles);
+ }
+
+ @Override
+ @NotNull
+ public InventoryView createView(@NotNull MenuType menuType, @NotNull NightComponent title, @NotNull Player player) {
+ if (Version.isAtLeast(Version.MC_1_21_4)) {
+ return menuType.typed().builder().title(fromNightComponent(title)).build(player);
+ }
+ else {
+ return menuType.typed().create(player, fromNightComponent(title));
+ }
+ }
+
+ @Override
+ @NotNull
+ public String getTranslationKey(@NotNull Material material) {
+ return getTranslation(material);
+ }
+
+ @Override
+ @NotNull
+ public String getTranslationKey(@NotNull Attribute attribute) {
+ return getTranslation(attribute);
+ }
+
+ @Override
+ @NotNull
+ public String getTranslationKey(@NotNull EntityType entityType) {
+ return getTranslation(entityType);
+ }
+
+ @Override
+ @NotNull
+ public String getTranslationKey(@NotNull Enchantment enchantment) {
+ return getTranslation(enchantment);
+ }
+
+ @Override
+ @NotNull
+ public String getTranslationKey(@NotNull PotionEffectType effectType) {
+ return getTranslation(effectType);
+ }
+
+ @NotNull
+ public static String getTranslation(@NotNull Translatable translatable) {
+ return translatable.translationKey();
+ }
+
+
+
+
+ @Override
+ @NotNull
+ public ItemStack setType(@NotNull ItemStack itemStack, @NotNull Material material) {
+ return itemStack.withType(material);
+ }
+
+ @Override
+ public void editMeta(@NotNull ItemStack itemStack, @NotNull Consumer consumer) {
+ itemStack.editMeta(consumer);
+ }
+
+ @Override
+ public void editMeta(@NotNull ItemStack itemStack, @NotNull Class clazz, @NotNull Consumer consumer) {
+ itemStack.editMeta(clazz, consumer);
+ }
+
+ @Override
+ @Nullable
+ public String getCustomName(@NotNull ItemMeta meta) {
+ Component component;
+ if (Version.isBehind(Version.MC_1_21_4)) {
+ component = meta.displayName();
+ }
+ else {
+ component = meta.customName();
+ }
+ return component == null ? null : serializeComponent(component);
+ }
+
+ @Override
+ public void setCustomName(@NotNull ItemMeta meta, @NotNull NightComponent name) {
+ if (Version.isBehind(Version.MC_1_21_4)) {
+ meta.displayName(fromNightComponent(name));
+ }
+ else {
+ meta.customName(fromNightComponent(name));
+ }
+ }
+
+ @Override
+ @Nullable
+ public String getItemName(@NotNull ItemMeta meta) {
+ return meta.hasItemName() ? serializeComponent(meta.itemName()) : null;
+ }
+
+ @Override
+ public void setItemName(@NotNull ItemMeta meta, @NotNull NightComponent name) {
+ meta.itemName(fromNightComponent(name));
+ }
+
+ @Override
+ @Nullable
+ public List getLore(@NotNull ItemMeta meta) {
+ List lore = meta.lore();
+ return lore == null ? null : Lists.modify(lore, PaperBridge::serializeComponent);
+ }
+
+ @Override
+ public void setLore(@NotNull ItemMeta meta, @NotNull List lore) {
+ meta.lore(Lists.modify(lore, PaperBridge::fromNightComponent));
+ }
+
+ @Override
+ @Nullable
+ public NightProfile getOwnerProfile(@NotNull ItemStack itemStack) {
+ if (!(itemStack.getItemMeta() instanceof SkullMeta skullMeta)) return null;
+
+ PlayerProfile profile = skullMeta.getPlayerProfile();
+ return profile == null ? null : new PaperProfile(profile);
+ }
+
+ @NotNull
+ public Set getCommonComponentsToHide() {
+ if (this.commonComponentsToHide == null) return new HashSet<>(); // Fix for <= 1.21.4
+
+ return /*BukkitThing.allFromRegistry(Registry.DATA_COMPONENT_TYPE)*/this.commonComponentsToHide.stream().map(BukkitThing::getAsString).collect(Collectors.toSet());
+ }
+
+ @Override
+ @NotNull
+ public Set getHiddenComponents(@NotNull ItemStack itemStack) {
+ TooltipDisplay tooltipDisplay = itemStack.getData(DataComponentTypes.TOOLTIP_DISPLAY);
+ if (tooltipDisplay == null) return Collections.emptySet();
+
+ return tooltipDisplay.hiddenComponents().stream().map(BukkitThing::getAsString).collect(Collectors.toSet());
+ }
+
+ @Override
+ public void hideComponents(@NotNull ItemStack itemStack) {
+// TooltipDisplay tooltipDisplay = TooltipDisplay.tooltipDisplay().hiddenComponents(this.commonComponentsToHide).build();
+// itemStack.setData(DataComponentTypes.TOOLTIP_DISPLAY, tooltipDisplay);
+//
+ if (commonComponentsToHide == null) return;
+
+ hidePaperComponents(itemStack, this.commonComponentsToHide);
+ }
+
+ @Override
+ public void hideComponents(@NotNull ItemStack itemStack, @NotNull Set componentNames) {
+ Set componentTypes = componentNames.stream().map(name -> BukkitThing.getByString(RegistryType.Paper.DATA_COMPONENT_TYPE, name))
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ hidePaperComponents(itemStack, componentTypes);
+ }
+
+ public static void hidePaperComponents(@NotNull ItemStack itemStack, @NotNull Set componentTypes) {
+ TooltipDisplay tooltipDisplay = TooltipDisplay.tooltipDisplay().hiddenComponents(componentTypes).build();
+ itemStack.setData(DataComponentTypes.TOOLTIP_DISPLAY, tooltipDisplay);
+ }
+}
diff --git a/src/main/java/su/nightexpress/nightcore/util/bridge/paper/PaperComponent.java b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperComponent.java
similarity index 78%
rename from src/main/java/su/nightexpress/nightcore/util/bridge/paper/PaperComponent.java
rename to paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperComponent.java
index f5a98f6..2199498 100644
--- a/src/main/java/su/nightexpress/nightcore/util/bridge/paper/PaperComponent.java
+++ b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperComponent.java
@@ -1,4 +1,4 @@
-package su.nightexpress.nightcore.util.bridge.paper;
+package su.nightexpress.nightcore.bridge.paper;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
@@ -13,13 +13,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
-import su.nightexpress.nightcore.util.ItemNbt;
+import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.util.Lists;
import su.nightexpress.nightcore.util.bridge.wrapper.ClickEventType;
-import su.nightexpress.nightcore.util.bridge.wrapper.HoverEventType;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
-import su.nightexpress.nightcore.util.text.ComponentBuildable;
-import su.nightexpress.nightcore.util.text.NightMessage;
+import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
import java.awt.*;
import java.util.List;
@@ -42,6 +40,11 @@ public class PaperComponent implements NightComponent {
return new PaperComponent(Component.translatable(key));
}
+ @NotNull
+ public static PaperComponent translate(@NotNull String key, @Nullable String fallback) {
+ return new PaperComponent(Component.translatable(key, fallback));
+ }
+
@NotNull
public static PaperComponent builder(@NotNull List childrens) {
// Force remove all decortaions, otherwise it'll be decorated by default (italic on items, etc).
@@ -112,14 +115,12 @@ public class PaperComponent implements NightComponent {
@Override
public void setChildrens(@NotNull List childrens) {
- this.parent = this.parent.children(childrens.stream().map(child -> ((PaperComponent)child).parent).toList());
+ this.parent = this.parent.children(childrens.stream().map(PaperBridge::fromNightComponent).toList());
}
@Override
public void addChildren(@NotNull NightComponent other) {
- if (other instanceof PaperComponent paperComponent) {
- this.parent = this.parent.append(paperComponent.parent);
- }
+ this.parent = this.parent.append(PaperBridge.fromNightComponent(other));
}
@Override
@@ -148,23 +149,34 @@ public class PaperComponent implements NightComponent {
this.parent = this.parent.clickEvent(ClickEvent.clickEvent(action, value));
}
+// @Override
+// public void setHoverEvent(@NotNull HoverEventType type, @NotNull String value) {
+// HoverEvent> event = null;
+//
+// switch (type) {
+// case SHOW_TEXT -> {
+// PaperComponent component = (PaperComponent) NightMessage.parse(value);
+// event = HoverEvent.showText(component.parent);
+// }
+// case SHOW_ITEM -> {
+// ItemStack itemStack = ItemNbt.getHoverEventItem(value);
+// event = itemStack == null ? null : itemStack.asHoverEvent();
+// }
+// }
+// if (event == null) return;
+//
+// this.parent = this.parent.hoverEvent(event);
+// }
+
@Override
- public void setHoverEvent(@NotNull HoverEventType type, @NotNull String value) {
- HoverEvent> event = null;
+ public void setHoverEvent(@NotNull NightComponent text) {
+ Component component = PaperBridge.fromNightComponent(text);
+ this.parent = this.parent.hoverEvent(HoverEvent.showText(component));
+ }
- switch (type) {
- case SHOW_TEXT -> {
- PaperComponent component = (PaperComponent) NightMessage.parse(value);
- event = HoverEvent.showText(component.parent);
- }
- case SHOW_ITEM -> {
- ItemStack itemStack = ItemNbt.getHoverEventItem(value);
- event = itemStack.asHoverEvent();
- }
- }
- if (event == null) return;
-
- this.parent = this.parent.hoverEvent(event);
+ @Override
+ public void setHoverEvent(@NotNull ItemStack itemStack) {
+ this.parent = this.parent.hoverEvent(itemStack.asHoverEvent());
}
@Override
diff --git a/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperProfile.java b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperProfile.java
new file mode 100644
index 0000000..3764363
--- /dev/null
+++ b/paper/src/main/java/su/nightexpress/nightcore/bridge/paper/PaperProfile.java
@@ -0,0 +1,66 @@
+package su.nightexpress.nightcore.bridge.paper;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.profile.PlayerTextures;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.bridge.wrap.NightProfile;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+public class PaperProfile implements NightProfile {
+
+ private final PlayerProfile backend;
+
+ public PaperProfile(@NotNull PlayerProfile backend) {
+ this.backend = backend;
+ }
+
+ @Override
+ public void apply(@NotNull SkullMeta meta) {
+ meta.setPlayerProfile(this.backend);
+ }
+
+ @Override
+ @Nullable
+ public UUID getId() {
+ return this.backend.getId();
+ }
+
+ @Override
+ @Nullable
+ public String getName() {
+ return this.backend.getName();
+ }
+
+ @Override
+ @NotNull
+ public PlayerTextures getTextures() {
+ return this.backend.getTextures();
+ }
+
+ @Override
+ public void setTextures(@Nullable PlayerTextures textures) {
+ this.backend.setTextures(textures);
+ }
+
+ @Override
+ public boolean isComplete() {
+ return this.backend.isComplete();
+ }
+
+ @Override
+ @NotNull
+ public CompletableFuture update() {
+ return this.backend.update().thenApplyAsync(PaperProfile::new);
+ }
+
+ @Override
+ public String toString() {
+ return "PaperProfile{" +
+ "backend=" + backend +
+ '}';
+ }
+}
diff --git a/pom.xml b/pom.xml
index 944d9fe..70fd1aa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,15 @@
su.nightexpress.nightcore
nightcore
- 2.7.5.2
+ 2.7.6
+ pom
+
+ main
+ bridge
+ utils
+ spigot
+ paper
+
21
@@ -21,122 +29,16 @@
-
-
- spigot-repo
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
-
-
- papermc
- https://repo.papermc.io/repository/maven-public/
-
-
-
- placeholderapi
- https://repo.extendedclip.com/content/repositories/placeholderapi/
-
-
-
- opencollab-snapshot
- https://repo.opencollab.dev/maven-snapshots/
-
-
-
- minecraft-repo
- https://libraries.minecraft.net/
-
-
-
- jitpack.io
- https://jitpack.io
-
-
-
-
-
-
-
-
-
-
- io.papermc.paper
- paper-api
- 1.21.5-R0.1-SNAPSHOT
- provided
-
-
-
-
-
- com.zaxxer
- HikariCP
- 6.0.0
- provided
-
-
-
- com.mojang
- datafixerupper
- 8.0.16
- provided
-
-
-
- org.xerial
- sqlite-jdbc
- 3.47.0.0
- provided
-
-
-
- it.unimi.dsi
- fastutil-core
- 8.5.13
- provided
-
-
-
- com.github.MilkBowl
- VaultAPI
- 1.7
- provided
-
-
-
- me.clip
- placeholderapi
- 2.11.6
- provided
-
-
-
- org.geysermc.floodgate
- api
- 2.2.0-SNAPSHOT
- provided
+ org.jetbrains
+ annotations
+ 24.0.0
+ compile
-
-
-