diff --git a/pom.xml b/pom.xml index 4d05ceb..6b5fbff 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ 17 17 + UTF-8 diff --git a/src/main/java/su/nightexpress/nightcore/NightCore.java b/src/main/java/su/nightexpress/nightcore/NightCore.java index 3122f69..8d2feb8 100644 --- a/src/main/java/su/nightexpress/nightcore/NightCore.java +++ b/src/main/java/su/nightexpress/nightcore/NightCore.java @@ -16,6 +16,7 @@ import su.nightexpress.nightcore.language.LangAssets; import su.nightexpress.nightcore.util.EntityUtil; import su.nightexpress.nightcore.util.ItemUtil; import su.nightexpress.nightcore.util.Plugins; +import su.nightexpress.nightcore.util.Version; import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker; import java.util.HashSet; @@ -76,6 +77,11 @@ public class NightCore extends NightPlugin { } private void testMethods() { + if (Version.getCurrent() == Version.UNKNOWN) { + this.warn("Server Version: UNSUPPORTED (!)"); + } + else this.info("Server Version: " + Version.getCurrent().getLocalized() + " (OK)"); + if (EntityUtil.ENTITY_COUNTER == null) { this.warn("Entity Id Counter: NULL!"); } diff --git a/src/main/java/su/nightexpress/nightcore/NightPlugin.java b/src/main/java/su/nightexpress/nightcore/NightPlugin.java index e5d4d0d..18bafee 100644 --- a/src/main/java/su/nightexpress/nightcore/NightPlugin.java +++ b/src/main/java/su/nightexpress/nightcore/NightPlugin.java @@ -159,8 +159,8 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin this.disable(); + AbstractMenu.closeAll(this); // Close all GUIs. HandlerList.unregisterAll(this); // Unregister all plugin listeners. - AbstractMenu.closeAll(); // Close all GUIs. this.getCommandManager().shutdown(); this.getLangManager().shutdown(); diff --git a/src/main/java/su/nightexpress/nightcore/config/PluginDetails.java b/src/main/java/su/nightexpress/nightcore/config/PluginDetails.java index 2a429a0..65502ac 100644 --- a/src/main/java/su/nightexpress/nightcore/config/PluginDetails.java +++ b/src/main/java/su/nightexpress/nightcore/config/PluginDetails.java @@ -33,7 +33,7 @@ public class PluginDetails { @NotNull public static PluginDetails create(@NotNull String name, @NotNull String[] commandAliases) { - String prefix = Tags.YELLOW.enclose(name) + Tags.DARK_GRAY.enclose(" » ") + Tags.GRAY.getFullName(); + String prefix = Tags.LIGHT_YELLOW.enclose(Tags.BOLD.enclose(name)) + Tags.DARK_GRAY.enclose(" » ") + Tags.GRAY.getFullName(); String language = Locale.getDefault().getLanguage(); return new PluginDetails(name, prefix, commandAliases, language); diff --git a/src/main/java/su/nightexpress/nightcore/database/sql/SQLColumn.java b/src/main/java/su/nightexpress/nightcore/database/sql/SQLColumn.java index 8e955c2..b3a5b65 100644 --- a/src/main/java/su/nightexpress/nightcore/database/sql/SQLColumn.java +++ b/src/main/java/su/nightexpress/nightcore/database/sql/SQLColumn.java @@ -34,7 +34,9 @@ public class SQLColumn { @NotNull public SQLColumn asLowerCase() { - return new SQLColumn("LOWER(" + this.getName() + ")", this.getName(), this.getType(), this.getLength()); + String name = "LOWER(" + this.getName() + ")"; + + return new SQLColumn(name, name, this.getType(), this.getLength()); } @NotNull diff --git a/src/main/java/su/nightexpress/nightcore/language/entry/LangItem.java b/src/main/java/su/nightexpress/nightcore/language/entry/LangItem.java index 6b64e53..03815a6 100644 --- a/src/main/java/su/nightexpress/nightcore/language/entry/LangItem.java +++ b/src/main/java/su/nightexpress/nightcore/language/entry/LangItem.java @@ -8,13 +8,14 @@ import su.nightexpress.nightcore.util.ItemUtil; import su.nightexpress.nightcore.util.Pair; import su.nightexpress.nightcore.util.text.NightMessage; import su.nightexpress.nightcore.util.text.WrappedMessage; -import su.nightexpress.nightcore.util.text.tag.Tags; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import static su.nightexpress.nightcore.util.text.tag.Tags.*; + public class LangItem extends LangEntry>> { private final List defaultLore; @@ -106,10 +107,11 @@ public class LangItem extends LangEntry>> { return wrappedLore; } + public static final String CLICK = "Click"; public static final String LMB = "Left-Click"; public static final String RMB = "Right-Click"; - public static final String DROP_KEY = "[Q] Drop Key"; - public static final String SWAP_KEY = "[F] Swap Key"; + public static final String DROP_KEY = "[Q / Drop] Key"; + public static final String SWAP_KEY = "[F / Swap] Key"; public static final String SHIFT_LMB = "Shift-Left"; public static final String SHIFT_RMB = "Shift-Right"; public static final String DRAG_DROP = "Drag & Drop"; @@ -138,14 +140,14 @@ public class LangItem extends LangEntry>> { @NotNull public Builder name(@NotNull String name) { - this.name = Tags.YELLOW.enclose(Tags.BOLD.enclose(name)); + this.name = LIGHT_YELLOW.enclose(BOLD.enclose(name)); return this; } @NotNull public Builder text(@NotNull String... text) { for (String str : text) { - this.addLore(Tags.GRAY.enclose(str)); + this.addLore(LIGHT_GRAY.enclose(str)); } return this; } @@ -157,12 +159,22 @@ public class LangItem extends LangEntry>> { @NotNull public Builder currentHeader() { - return this.addLore(Tags.YELLOW.enclose(Tags.BOLD.enclose("Current:"))); + return this.addLore(LIGHT_YELLOW.enclose(BOLD.enclose("Current:"))); } @NotNull public Builder current(@NotNull String type, @NotNull String value) { - return this.addLore(Tags.YELLOW.enclose("▪ " + Tags.GRAY.enclose(type + ": ") + value)); + return this.addLore(LIGHT_YELLOW.enclose("● " + LIGHT_GRAY.enclose(type + ": ") + value)); + } + + @NotNull + public Builder current(@NotNull String value) { + return this.addLore(LIGHT_YELLOW.enclose("● " + LIGHT_GRAY.enclose(value))); + } + + @NotNull + public Builder click(@NotNull String action) { + return this.click(CLICK, action); } @NotNull @@ -202,7 +214,7 @@ public class LangItem extends LangEntry>> { @NotNull public Builder click(@NotNull String click, @NotNull String action) { - return this.addLore(Tags.GRAY.enclose("(" + Tags.WHITE.enclose(click) + " to " + action + ")")); + return this.addLore(LIGHT_YELLOW.enclose("[▶]") + " " + LIGHT_GRAY.enclose(click + " to " + LIGHT_YELLOW.enclose(action) + ".")); } @NotNull diff --git a/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java b/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java index 832aa2d..3777e3b 100644 --- a/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java +++ b/src/main/java/su/nightexpress/nightcore/menu/api/Menu.java @@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import su.nightexpress.nightcore.NightCorePlugin; import su.nightexpress.nightcore.menu.MenuOptions; import su.nightexpress.nightcore.menu.MenuViewer; import su.nightexpress.nightcore.menu.click.ClickResult; @@ -30,6 +31,8 @@ public interface Menu { void close(); + boolean close(@NotNull NightCorePlugin plugin); + void runNextTick(@NotNull Runnable runnable); void onClick(@NotNull MenuViewer viewer, @NotNull ClickResult result, @NotNull InventoryClickEvent event); diff --git a/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java b/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java index 70cf64a..72b7584 100644 --- a/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java +++ b/src/main/java/su/nightexpress/nightcore/menu/impl/AbstractMenu.java @@ -27,7 +27,23 @@ public abstract class AbstractMenu

implements Menu { public static final Map PLAYER_MENUS = new HashMap<>(); public static void closeAll() { - new HashSet<>(PLAYER_MENUS.values()).forEach(Menu::close); + getActiveMenus().forEach(Menu::close); + } + + public static void closeAll(@NotNull NightCorePlugin plugin) { + getActiveMenus().forEach(menu -> menu.close(plugin)); + } + + public static Collection

getActiveMenus() { + return new HashSet<>(PLAYER_MENUS.values()); + } + + public static void purge(@NotNull Player player) { + Menu menu = getMenu(player); + if (menu == null) return; + + menu.close(); + PLAYER_MENUS.remove(player.getUniqueId()); } protected final P plugin; @@ -71,6 +87,16 @@ public abstract class AbstractMenu

implements Menu { @Override public void close() { new HashSet<>(this.getViewers()).forEach(viewer -> viewer.getPlayer().closeInventory()); + this.viewers.clear(); + } + + @Override + public boolean close(@NotNull NightCorePlugin plugin) { + if (this.plugin == plugin) { + this.close(); + return true; + } + return false; } /*@NotNull @@ -117,7 +143,11 @@ public abstract class AbstractMenu

implements Menu { Inventory inventory = viewer.getInventory(); if (inventory == null) { - this.plugin.debug("Could not create " + this.getClass().getSimpleName() + " inventory for '" + player.getName() + "'."); + this.plugin.debug("Could not create " + this.getClass().getSimpleName() + " menu for '" + player.getName() + "'."); + return false; + } + if (inventory.getType() == InventoryType.CRAFTING) { + this.plugin.warn("Got CRAFTING inventory when trying to open " + this.getClass().getSimpleName() + " menu for '" + player.getName() + "'."); return false; } diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java b/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java index 7279875..98edfb8 100644 --- a/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java +++ b/src/main/java/su/nightexpress/nightcore/util/ItemReplacer.java @@ -194,6 +194,14 @@ public class ItemReplacer { return this; } + @NotNull + public ItemReplacer injectLore(@NotNull String placeholder, @NotNull List replacer) { + if (this.getLore() == null) return this; + + this.setLore(Lists.replace(this.packLore(), placeholder, replacer)); + return this; + } + @NotNull public ItemReplacer replaceLoreTrail(@NotNull String placeholder, @NotNull List replacer) { if (this.getLore() == null) return this; diff --git a/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java b/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java index 405785c..f5f0320 100644 --- a/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java +++ b/src/main/java/su/nightexpress/nightcore/util/ItemUtil.java @@ -25,12 +25,12 @@ import java.util.function.Consumer; public class ItemUtil { - private static final String VERSION = Version.getProtocol(); + //private static final String VERSION = Version.getProtocol(); private static final String TEXTURES_HOST = "http://textures.minecraft.net/texture/"; private static final Class NBT_TAG_COMPOUND = Reflex.getClass("net.minecraft.nbt", "NBTTagCompound"); private static final Class NMS_ITEM = Reflex.getClass("net.minecraft.world.item", "ItemStack"); - private static final Class CRAFT_ITEM_STACK = Reflex.getClass("org.bukkit.craftbukkit." + VERSION + ".inventory", "CraftItemStack"); + private static final Class CRAFT_ITEM_STACK = Reflex.getClass(Version.CRAFTBUKKIT_PACKAGE + ".inventory", "CraftItemStack"); private static final Class NBT_IO = Reflex.getClass("net.minecraft.nbt", "NBTCompressedStreamTools"); private static final Constructor NBT_TAG_COMPOUND_NEW = Reflex.getConstructor(NBT_TAG_COMPOUND); diff --git a/src/main/java/su/nightexpress/nightcore/util/Placeholders.java b/src/main/java/su/nightexpress/nightcore/util/Placeholders.java index 76849d2..70eb798 100644 --- a/src/main/java/su/nightexpress/nightcore/util/Placeholders.java +++ b/src/main/java/su/nightexpress/nightcore/util/Placeholders.java @@ -39,6 +39,14 @@ public class Placeholders { public static final String LOCATION_Z = "%location_z%"; public static final String LOCATION_WORLD = "%location_world%"; + public static final String SKIN_WRONG_MARK = "27548362a24c0fa8453e4d93e68c5969ddbde57bf6666c0319c1ed1e84d89065"; + public static final String SKIN_QUESTION_MARK = "2705fd94a0c431927fb4e639b0fcfb49717e412285a02b439e0112da22b2e2ec"; + public static final String SKIN_CHECK_MARK = "a79a5c95ee17abfef45c8dc224189964944d560f19a44f19f8a46aef3fee4756"; + public static final String SKIN_EXCLAMATION_MARK = "7b41996fd20ca21d79adfc0e12057b2f2ceadf7b3cf5bb5f8a92fe3460161acd"; + public static final String SKIN_ARROW_LEFT = "86971dd881dbaf4fd6bcaa93614493c612f869641ed59d1c9363a3666a5fa6"; + public static final String SKIN_ARROW_RIGHT = "f32ca66056b72863e98f7f32bd7d94c7a0d796af691c9ac3a9136331352288f9"; + public static final String SKIN_ARROW_DOWN = "be9ae7a4be65fcbaee65181389a2f7d47e2e326db59ea3eb789a92c85ea46"; + public static final String COMMAND_USAGE = "%command_usage%"; public static final String COMMAND_DESCRIPTION = "%command_description%"; public static final String COMMAND_LABEL = "%command_label%"; diff --git a/src/main/java/su/nightexpress/nightcore/util/RankMap.java b/src/main/java/su/nightexpress/nightcore/util/RankMap.java index 91f0d14..eb5a30b 100644 --- a/src/main/java/su/nightexpress/nightcore/util/RankMap.java +++ b/src/main/java/su/nightexpress/nightcore/util/RankMap.java @@ -45,6 +45,8 @@ public class RankMap { @NotNull public static RankMap read(@NotNull FileConfig cfg, @NotNull String path, @NotNull Class clazz) { + Map oldMap = new HashMap<>(); + if (!cfg.contains(path + ".Mode")) { for (String rank : cfg.getSection(path)) { T number; @@ -53,16 +55,20 @@ public class RankMap { } else number = clazz.cast(cfg.getInt(path + "." + rank)); - if (rank.equalsIgnoreCase(Placeholders.DEFAULT)) { - cfg.set(path + ".Default_Value", number); - } - else { - cfg.set(path + ".Values." + rank, number); - } + oldMap.put(rank.toLowerCase(), number); } cfg.remove(path); } + oldMap.forEach((rank, number) -> { + if (rank.equalsIgnoreCase(Placeholders.DEFAULT)) { + cfg.set(path + ".Default_Value", number); + } + else { + cfg.set(path + ".Values." + rank, number); + } + }); + Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK, "Available values: " + StringUtil.inlineEnum(Mode.class, ", "), "RANK = Get value by player's permission group. All 'Values' keys will represent permission group names.", diff --git a/src/main/java/su/nightexpress/nightcore/util/Version.java b/src/main/java/su/nightexpress/nightcore/util/Version.java index 243779d..93c2108 100644 --- a/src/main/java/su/nightexpress/nightcore/util/Version.java +++ b/src/main/java/su/nightexpress/nightcore/util/Version.java @@ -3,6 +3,8 @@ package su.nightexpress.nightcore.util; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; +import java.util.stream.Stream; + public enum Version { V1_18_R2("1.18.2"), @@ -13,6 +15,8 @@ public enum Version { UNKNOWN("Unknown"), ; + public static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName(); + private static Version current; private final boolean deprecated; @@ -28,15 +32,20 @@ public enum Version { } @NotNull + @Deprecated public static String getProtocol() { - String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\."); - return split[split.length - 1]; + return Bukkit.getServer().getBukkitVersion();//.split("-")[0]; + + //String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\."); + //return split[split.length - 1]; } @NotNull public static Version getCurrent() { if (current == null) { - current = StringUtil.getEnum(getProtocol(), Version.class).orElse(UNKNOWN); + String protocol = Bukkit.getServer().getBukkitVersion(); + current = Stream.of(values()).filter(version -> protocol.startsWith(version.getLocalized())).findFirst().orElse(UNKNOWN); + //current = StringUtil.getEnum(getProtocol(), Version.class).orElse(UNKNOWN); } return current; } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java index cb26637..651da81 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java @@ -13,6 +13,7 @@ import su.nightexpress.nightcore.util.regex.TimedMatcher; import su.nightexpress.nightcore.util.text.decoration.*; import su.nightexpress.nightcore.util.text.tag.*; import su.nightexpress.nightcore.util.text.tag.api.DynamicTag; +import su.nightexpress.nightcore.util.text.tag.api.OrphanTag; import su.nightexpress.nightcore.util.text.tag.api.Tag; import su.nightexpress.nightcore.util.text.tag.impl.*; @@ -40,7 +41,8 @@ public class NightMessage { registerTags( Tags.FONT, Tags.HEX_COLOR, Tags.HEX_COLOR_SHORT, Tags.GRADIENT, Tags.HOVER, Tags.CLICK, - Tags.LINE_BREAK, Tags.RESET + Tags.LINE_BREAK, Tags.RESET, + Tags.TRANSLATE ); } @@ -67,6 +69,11 @@ public class NightMessage { return TAG_MAP.get(name.toLowerCase()); } + @NotNull + public static String clean(@NotNull String string) { + return create(string, TagPool.NONE).toLegacy(); + } + @NotNull public static String asLegacy(@NotNull String string) { return create(string).toLegacy(); @@ -201,21 +208,20 @@ public class NightMessage { if (tag != null) { if (tagPool.isGoodTag(tag)) { - if (tag == Tags.LINE_BREAK) { + if (tag instanceof OrphanTag orphanTag) { if (currentText.getTextBuilder().isEmpty()) { - currentText.getTextBuilder().append("\n"); + currentText.getTextBuilder().append(orphanTag.getContent()); } else { currentText = currentText.nested(); - currentText.setText("\n"); + currentText.setText(orphanTag.getContent()); parts.add(currentText); } currentText = currentText.nested(); parts.add(currentText); } - // Если был текст ДО текущего тега и не было ДРУГИХ тегов прямо перед ним, - // то вставляем новую часть текста + // Создаем новую "часть текста" только если обнаружен новый тег после текста (но не других тегов). if (lastTag == null && !currentText.getTextBuilder().isEmpty()) { currentText = currentText.nested(); parts.add(currentText); @@ -224,7 +230,7 @@ public class NightMessage { if (closeTag) { currentText.removeLatestTag(tag); } - else if (tag != Tags.LINE_BREAK) { + else if (!(tag instanceof OrphanTag)) { currentText.addTag(tag, decorator); } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java index 4c44229..5cdd8a7 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/Tags.java @@ -12,6 +12,7 @@ public class Tags { public static final HoverTag HOVER = new HoverTag(); public static final LineBreakTag LINE_BREAK = new LineBreakTag(); public static final ResetTag RESET = new ResetTag(); + public static final TranslateTag TRANSLATE = new TranslateTag(); public static final FontStyleTag BOLD = new FontStyleTag("b", FontStyleTag.Style.BOLD); public static final FontStyleTag ITALIC = new FontStyleTag("i", FontStyleTag.Style.ITALIC); diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/api/OrphanTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/api/OrphanTag.java new file mode 100644 index 0000000..6eaef13 --- /dev/null +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/api/OrphanTag.java @@ -0,0 +1,8 @@ +package su.nightexpress.nightcore.util.text.tag.api; + +import org.jetbrains.annotations.NotNull; + +public interface OrphanTag { + + @NotNull String getContent(); +} diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java index 49c674c..964e227 100644 --- a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/LineBreakTag.java @@ -1,8 +1,10 @@ package su.nightexpress.nightcore.util.text.tag.impl; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.nightcore.util.text.tag.api.OrphanTag; import su.nightexpress.nightcore.util.text.tag.api.Tag; -public class LineBreakTag extends Tag { +public class LineBreakTag extends Tag implements OrphanTag { public LineBreakTag() { super("br"); @@ -12,4 +14,10 @@ public class LineBreakTag extends Tag { public int getWeight() { return 0; } + + @Override + @NotNull + public String getContent() { + return "\n"; + } } diff --git a/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslateTag.java b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslateTag.java new file mode 100644 index 0000000..e14c9cc --- /dev/null +++ b/src/main/java/su/nightexpress/nightcore/util/text/tag/impl/TranslateTag.java @@ -0,0 +1,33 @@ +package su.nightexpress.nightcore.util.text.tag.impl; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.TranslatableComponent; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.nightcore.util.text.decoration.Decorator; +import su.nightexpress.nightcore.util.text.tag.api.Tag; + +public class TranslateTag extends Tag implements Decorator { + + public static final String NAME = "translate"; + + public TranslateTag() { + super(NAME); + } + + @Override + public int getWeight() { + return Integer.MAX_VALUE - 10; + } + + @Override + public void decorate(@NotNull BaseComponent component) { + if (!(component instanceof TextComponent textComponent)) return; + + String content = textComponent.getText(); + textComponent.setText(""); + + TranslatableComponent translatableComponent = new TranslatableComponent(content); + component.addExtra(translatableComponent); + } +} diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java b/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java index bbeede6..3076f3c 100644 --- a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java +++ b/src/main/java/su/nightexpress/nightcore/util/wrapper/UniParticle.java @@ -7,7 +7,6 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nightexpress.nightcore.config.FileConfig; -import su.nightexpress.nightcore.util.NumberUtil; import su.nightexpress.nightcore.util.StringUtil; public class UniParticle { @@ -86,12 +85,18 @@ public class UniParticle { Color colorStart = StringUtil.getColor(cfg.getString(path + ".Color_From", "")); Color colorEnd = StringUtil.getColor(cfg.getString(path + ".Color_To", "")); double size = cfg.getDouble(path + ".Size", 1D); - data = new Particle.DustTransition(colorStart, colorEnd, 1.0f); + data = new Particle.DustTransition(colorStart, colorEnd, (float) size); } else if (dataType == ItemStack.class) { ItemStack item = cfg.getItem(path + ".Item"); data = item.getType().isAir() ? new ItemStack(Material.STONE) : item; } + else if (dataType == Float.class) { + data = (float) cfg.getDouble(path + ".floatValue", 1F); + } + else if (dataType == Integer.class) { + data = cfg.getInt(path + ".intValue", 1); + } else if (dataType != Void.class) return UniParticle.of(Particle.REDSTONE); return UniParticle.of(particle, data); @@ -119,6 +124,12 @@ public class UniParticle { else if (data instanceof ItemStack item) { cfg.setItem(path + ".Item", item); } + else if (data instanceof Float f) { + cfg.set(path + ".floatValue", f); + } + else if (data instanceof Integer i) { + cfg.set(path + ".intValue", i); + } } public boolean isEmpty() { @@ -134,39 +145,6 @@ public class UniParticle { return data; } - @NotNull - @Deprecated - public UniParticle parseData(@NotNull String from) { - if (this.isEmpty()) return this; - - String[] split = from.split(" "); - Class dataType = this.getParticle().getDataType(); - Object data = null; - if (dataType == BlockData.class) { - Material material = Material.getMaterial(from.toUpperCase()); - data = material != null ? material.createBlockData() : Material.STONE.createBlockData(); - } - else if (dataType == Particle.DustOptions.class) { - Color color = StringUtil.getColor(split[0]); - double size = split.length >= 2 ? NumberUtil.getDouble(split[1], 1D) : 1D; - data = new Particle.DustOptions(color, (float) size); - } - else if (dataType == Particle.DustTransition.class) { - Color colorStart = StringUtil.getColor(split[0]); - Color colorEnd = split.length >= 2 ? StringUtil.getColor(split[1]) : colorStart; - double size = split.length >= 3 ? NumberUtil.getDouble(split[2], 1D) : 1D; - data = new Particle.DustTransition(colorStart, colorEnd, 1.0f); - } - else if (dataType == ItemStack.class) { - Material material = Material.getMaterial(from.toUpperCase()); - if (material != null && !material.isAir()) data = new ItemStack(material); - else data = new ItemStack(Material.STONE); - } - else if (dataType != Void.class) return UniParticle.of(Particle.REDSTONE); - - return UniParticle.of(this.getParticle(), data); - } - public void play(@NotNull Location location, double speed, int amount) { this.play(location, 0D, speed, amount); } @@ -189,6 +167,7 @@ public class UniParticle { public void play(@Nullable Player player, @NotNull Location location, double xOffset, double yOffset, double zOffset, double speed, int amount) { if (this.isEmpty()) return; + if (this.particle == null || (this.particle.getDataType() != Void.class && this.data == null)) return; if (player == null) { World world = location.getWorld();