mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-03 14:38:48 +00:00
Some fixes and additions; Prepare for Paper changes
This commit is contained in:
1 parent
b69c8ea719
commit
f70589cbe2
19 files changed
+187
-67
No files matched your search
@@ -11,6 +11,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import su.nightexpress.nightcore.language.LangAssets;
|
|||||||
import su.nightexpress.nightcore.util.EntityUtil;
|
import su.nightexpress.nightcore.util.EntityUtil;
|
||||||
import su.nightexpress.nightcore.util.ItemUtil;
|
import su.nightexpress.nightcore.util.ItemUtil;
|
||||||
import su.nightexpress.nightcore.util.Plugins;
|
import su.nightexpress.nightcore.util.Plugins;
|
||||||
|
import su.nightexpress.nightcore.util.Version;
|
||||||
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;
|
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -76,6 +77,11 @@ public class NightCore extends NightPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testMethods() {
|
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) {
|
if (EntityUtil.ENTITY_COUNTER == null) {
|
||||||
this.warn("Entity Id Counter: NULL!");
|
this.warn("Entity Id Counter: NULL!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
|||||||
|
|
||||||
this.disable();
|
this.disable();
|
||||||
|
|
||||||
|
AbstractMenu.closeAll(this); // Close all GUIs.
|
||||||
HandlerList.unregisterAll(this); // Unregister all plugin listeners.
|
HandlerList.unregisterAll(this); // Unregister all plugin listeners.
|
||||||
AbstractMenu.closeAll(); // Close all GUIs.
|
|
||||||
|
|
||||||
this.getCommandManager().shutdown();
|
this.getCommandManager().shutdown();
|
||||||
this.getLangManager().shutdown();
|
this.getLangManager().shutdown();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class PluginDetails {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static PluginDetails create(@NotNull String name, @NotNull String[] commandAliases) {
|
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();
|
String language = Locale.getDefault().getLanguage();
|
||||||
|
|
||||||
return new PluginDetails(name, prefix, commandAliases, language);
|
return new PluginDetails(name, prefix, commandAliases, language);
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ public class SQLColumn {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public SQLColumn asLowerCase() {
|
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
|
@NotNull
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import su.nightexpress.nightcore.util.ItemUtil;
|
|||||||
import su.nightexpress.nightcore.util.Pair;
|
import su.nightexpress.nightcore.util.Pair;
|
||||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||||
import su.nightexpress.nightcore.util.text.WrappedMessage;
|
import su.nightexpress.nightcore.util.text.WrappedMessage;
|
||||||
import su.nightexpress.nightcore.util.text.tag.Tags;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static su.nightexpress.nightcore.util.text.tag.Tags.*;
|
||||||
|
|
||||||
public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
||||||
|
|
||||||
private final List<String> defaultLore;
|
private final List<String> defaultLore;
|
||||||
@@ -106,10 +107,11 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
|||||||
return wrappedLore;
|
return wrappedLore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String CLICK = "Click";
|
||||||
public static final String LMB = "Left-Click";
|
public static final String LMB = "Left-Click";
|
||||||
public static final String RMB = "Right-Click";
|
public static final String RMB = "Right-Click";
|
||||||
public static final String DROP_KEY = "[Q] Drop Key";
|
public static final String DROP_KEY = "[Q / Drop] Key";
|
||||||
public static final String SWAP_KEY = "[F] Swap Key";
|
public static final String SWAP_KEY = "[F / Swap] Key";
|
||||||
public static final String SHIFT_LMB = "Shift-Left";
|
public static final String SHIFT_LMB = "Shift-Left";
|
||||||
public static final String SHIFT_RMB = "Shift-Right";
|
public static final String SHIFT_RMB = "Shift-Right";
|
||||||
public static final String DRAG_DROP = "Drag & Drop";
|
public static final String DRAG_DROP = "Drag & Drop";
|
||||||
@@ -138,14 +140,14 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Builder name(@NotNull String name) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Builder text(@NotNull String... text) {
|
public Builder text(@NotNull String... text) {
|
||||||
for (String str : text) {
|
for (String str : text) {
|
||||||
this.addLore(Tags.GRAY.enclose(str));
|
this.addLore(LIGHT_GRAY.enclose(str));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -157,12 +159,22 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Builder currentHeader() {
|
public Builder currentHeader() {
|
||||||
return this.addLore(Tags.YELLOW.enclose(Tags.BOLD.enclose("Current:")));
|
return this.addLore(LIGHT_YELLOW.enclose(BOLD.enclose("Current:")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Builder current(@NotNull String type, @NotNull String value) {
|
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
|
@NotNull
|
||||||
@@ -202,7 +214,7 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Builder click(@NotNull String click, @NotNull String action) {
|
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
|
@NotNull
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryDragEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import su.nightexpress.nightcore.NightCorePlugin;
|
||||||
import su.nightexpress.nightcore.menu.MenuOptions;
|
import su.nightexpress.nightcore.menu.MenuOptions;
|
||||||
import su.nightexpress.nightcore.menu.MenuViewer;
|
import su.nightexpress.nightcore.menu.MenuViewer;
|
||||||
import su.nightexpress.nightcore.menu.click.ClickResult;
|
import su.nightexpress.nightcore.menu.click.ClickResult;
|
||||||
@@ -30,6 +31,8 @@ public interface Menu {
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
boolean close(@NotNull NightCorePlugin plugin);
|
||||||
|
|
||||||
void runNextTick(@NotNull Runnable runnable);
|
void runNextTick(@NotNull Runnable runnable);
|
||||||
|
|
||||||
void onClick(@NotNull MenuViewer viewer, @NotNull ClickResult result, @NotNull InventoryClickEvent event);
|
void onClick(@NotNull MenuViewer viewer, @NotNull ClickResult result, @NotNull InventoryClickEvent event);
|
||||||
|
|||||||
@@ -27,7 +27,23 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
public static final Map<UUID, Menu> PLAYER_MENUS = new HashMap<>();
|
public static final Map<UUID, Menu> PLAYER_MENUS = new HashMap<>();
|
||||||
|
|
||||||
public static void closeAll() {
|
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<Menu> 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;
|
protected final P plugin;
|
||||||
@@ -71,6 +87,16 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
new HashSet<>(this.getViewers()).forEach(viewer -> viewer.getPlayer().closeInventory());
|
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
|
/*@NotNull
|
||||||
@@ -117,7 +143,11 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
|
|
||||||
Inventory inventory = viewer.getInventory();
|
Inventory inventory = viewer.getInventory();
|
||||||
if (inventory == null) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,14 @@ public class ItemReplacer {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ItemReplacer injectLore(@NotNull String placeholder, @NotNull List<String> replacer) {
|
||||||
|
if (this.getLore() == null) return this;
|
||||||
|
|
||||||
|
this.setLore(Lists.replace(this.packLore(), placeholder, replacer));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ItemReplacer replaceLoreTrail(@NotNull String placeholder, @NotNull List<String> replacer) {
|
public ItemReplacer replaceLoreTrail(@NotNull String placeholder, @NotNull List<String> replacer) {
|
||||||
if (this.getLore() == null) return this;
|
if (this.getLore() == null) return this;
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class ItemUtil {
|
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 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<?> 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<?> 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 Class<?> NBT_IO = Reflex.getClass("net.minecraft.nbt", "NBTCompressedStreamTools");
|
||||||
|
|
||||||
private static final Constructor<?> NBT_TAG_COMPOUND_NEW = Reflex.getConstructor(NBT_TAG_COMPOUND);
|
private static final Constructor<?> NBT_TAG_COMPOUND_NEW = Reflex.getConstructor(NBT_TAG_COMPOUND);
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ public class Placeholders {
|
|||||||
public static final String LOCATION_Z = "%location_z%";
|
public static final String LOCATION_Z = "%location_z%";
|
||||||
public static final String LOCATION_WORLD = "%location_world%";
|
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_USAGE = "%command_usage%";
|
||||||
public static final String COMMAND_DESCRIPTION = "%command_description%";
|
public static final String COMMAND_DESCRIPTION = "%command_description%";
|
||||||
public static final String COMMAND_LABEL = "%command_label%";
|
public static final String COMMAND_LABEL = "%command_label%";
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public class RankMap<T extends Number> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <T extends Number> RankMap<T> read(@NotNull FileConfig cfg, @NotNull String path, @NotNull Class<T> clazz) {
|
public static <T extends Number> RankMap<T> read(@NotNull FileConfig cfg, @NotNull String path, @NotNull Class<T> clazz) {
|
||||||
|
Map<String, T> oldMap = new HashMap<>();
|
||||||
|
|
||||||
if (!cfg.contains(path + ".Mode")) {
|
if (!cfg.contains(path + ".Mode")) {
|
||||||
for (String rank : cfg.getSection(path)) {
|
for (String rank : cfg.getSection(path)) {
|
||||||
T number;
|
T number;
|
||||||
@@ -53,16 +55,20 @@ public class RankMap<T extends Number> {
|
|||||||
}
|
}
|
||||||
else number = clazz.cast(cfg.getInt(path + "." + rank));
|
else number = clazz.cast(cfg.getInt(path + "." + rank));
|
||||||
|
|
||||||
if (rank.equalsIgnoreCase(Placeholders.DEFAULT)) {
|
oldMap.put(rank.toLowerCase(), number);
|
||||||
cfg.set(path + ".Default_Value", number);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cfg.set(path + ".Values." + rank, number);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cfg.remove(path);
|
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,
|
Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK,
|
||||||
"Available values: " + StringUtil.inlineEnum(Mode.class, ", "),
|
"Available values: " + StringUtil.inlineEnum(Mode.class, ", "),
|
||||||
"RANK = Get value by player's permission group. All 'Values' keys will represent permission group names.",
|
"RANK = Get value by player's permission group. All 'Values' keys will represent permission group names.",
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package su.nightexpress.nightcore.util;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public enum Version {
|
public enum Version {
|
||||||
|
|
||||||
V1_18_R2("1.18.2"),
|
V1_18_R2("1.18.2"),
|
||||||
@@ -13,6 +15,8 @@ public enum Version {
|
|||||||
UNKNOWN("Unknown"),
|
UNKNOWN("Unknown"),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
public static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
|
||||||
private static Version current;
|
private static Version current;
|
||||||
|
|
||||||
private final boolean deprecated;
|
private final boolean deprecated;
|
||||||
@@ -28,15 +32,20 @@ public enum Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Deprecated
|
||||||
public static String getProtocol() {
|
public static String getProtocol() {
|
||||||
String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
|
return Bukkit.getServer().getBukkitVersion();//.split("-")[0];
|
||||||
return split[split.length - 1];
|
|
||||||
|
//String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
|
||||||
|
//return split[split.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Version getCurrent() {
|
public static Version getCurrent() {
|
||||||
if (current == null) {
|
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;
|
return current;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import su.nightexpress.nightcore.util.regex.TimedMatcher;
|
|||||||
import su.nightexpress.nightcore.util.text.decoration.*;
|
import su.nightexpress.nightcore.util.text.decoration.*;
|
||||||
import su.nightexpress.nightcore.util.text.tag.*;
|
import su.nightexpress.nightcore.util.text.tag.*;
|
||||||
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
|
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.api.Tag;
|
||||||
import su.nightexpress.nightcore.util.text.tag.impl.*;
|
import su.nightexpress.nightcore.util.text.tag.impl.*;
|
||||||
|
|
||||||
@@ -40,7 +41,8 @@ public class NightMessage {
|
|||||||
registerTags(
|
registerTags(
|
||||||
Tags.FONT, Tags.HEX_COLOR, Tags.HEX_COLOR_SHORT, Tags.GRADIENT,
|
Tags.FONT, Tags.HEX_COLOR, Tags.HEX_COLOR_SHORT, Tags.GRADIENT,
|
||||||
Tags.HOVER, Tags.CLICK,
|
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());
|
return TAG_MAP.get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String clean(@NotNull String string) {
|
||||||
|
return create(string, TagPool.NONE).toLegacy();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String asLegacy(@NotNull String string) {
|
public static String asLegacy(@NotNull String string) {
|
||||||
return create(string).toLegacy();
|
return create(string).toLegacy();
|
||||||
@@ -201,21 +208,20 @@ public class NightMessage {
|
|||||||
|
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
if (tagPool.isGoodTag(tag)) {
|
if (tagPool.isGoodTag(tag)) {
|
||||||
if (tag == Tags.LINE_BREAK) {
|
if (tag instanceof OrphanTag orphanTag) {
|
||||||
if (currentText.getTextBuilder().isEmpty()) {
|
if (currentText.getTextBuilder().isEmpty()) {
|
||||||
currentText.getTextBuilder().append("\n");
|
currentText.getTextBuilder().append(orphanTag.getContent());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentText = currentText.nested();
|
currentText = currentText.nested();
|
||||||
currentText.setText("\n");
|
currentText.setText(orphanTag.getContent());
|
||||||
parts.add(currentText);
|
parts.add(currentText);
|
||||||
}
|
}
|
||||||
currentText = currentText.nested();
|
currentText = currentText.nested();
|
||||||
parts.add(currentText);
|
parts.add(currentText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если был текст ДО текущего тега и не было ДРУГИХ тегов прямо перед ним,
|
// Создаем новую "часть текста" только если обнаружен новый тег после текста (но не других тегов).
|
||||||
// то вставляем новую часть текста
|
|
||||||
if (lastTag == null && !currentText.getTextBuilder().isEmpty()) {
|
if (lastTag == null && !currentText.getTextBuilder().isEmpty()) {
|
||||||
currentText = currentText.nested();
|
currentText = currentText.nested();
|
||||||
parts.add(currentText);
|
parts.add(currentText);
|
||||||
@@ -224,7 +230,7 @@ public class NightMessage {
|
|||||||
if (closeTag) {
|
if (closeTag) {
|
||||||
currentText.removeLatestTag(tag);
|
currentText.removeLatestTag(tag);
|
||||||
}
|
}
|
||||||
else if (tag != Tags.LINE_BREAK) {
|
else if (!(tag instanceof OrphanTag)) {
|
||||||
currentText.addTag(tag, decorator);
|
currentText.addTag(tag, decorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class Tags {
|
|||||||
public static final HoverTag HOVER = new HoverTag();
|
public static final HoverTag HOVER = new HoverTag();
|
||||||
public static final LineBreakTag LINE_BREAK = new LineBreakTag();
|
public static final LineBreakTag LINE_BREAK = new LineBreakTag();
|
||||||
public static final ResetTag RESET = new ResetTag();
|
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 BOLD = new FontStyleTag("b", FontStyleTag.Style.BOLD);
|
||||||
public static final FontStyleTag ITALIC = new FontStyleTag("i", FontStyleTag.Style.ITALIC);
|
public static final FontStyleTag ITALIC = new FontStyleTag("i", FontStyleTag.Style.ITALIC);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package su.nightexpress.nightcore.util.text.tag.api;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface OrphanTag {
|
||||||
|
|
||||||
|
@NotNull String getContent();
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package su.nightexpress.nightcore.util.text.tag.impl;
|
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;
|
import su.nightexpress.nightcore.util.text.tag.api.Tag;
|
||||||
|
|
||||||
public class LineBreakTag extends Tag {
|
public class LineBreakTag extends Tag implements OrphanTag {
|
||||||
|
|
||||||
public LineBreakTag() {
|
public LineBreakTag() {
|
||||||
super("br");
|
super("br");
|
||||||
@@ -12,4 +14,10 @@ public class LineBreakTag extends Tag {
|
|||||||
public int getWeight() {
|
public int getWeight() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public String getContent() {
|
||||||
|
return "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import su.nightexpress.nightcore.config.FileConfig;
|
import su.nightexpress.nightcore.config.FileConfig;
|
||||||
import su.nightexpress.nightcore.util.NumberUtil;
|
|
||||||
import su.nightexpress.nightcore.util.StringUtil;
|
import su.nightexpress.nightcore.util.StringUtil;
|
||||||
|
|
||||||
public class UniParticle {
|
public class UniParticle {
|
||||||
@@ -86,12 +85,18 @@ public class UniParticle {
|
|||||||
Color colorStart = StringUtil.getColor(cfg.getString(path + ".Color_From", ""));
|
Color colorStart = StringUtil.getColor(cfg.getString(path + ".Color_From", ""));
|
||||||
Color colorEnd = StringUtil.getColor(cfg.getString(path + ".Color_To", ""));
|
Color colorEnd = StringUtil.getColor(cfg.getString(path + ".Color_To", ""));
|
||||||
double size = cfg.getDouble(path + ".Size", 1D);
|
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) {
|
else if (dataType == ItemStack.class) {
|
||||||
ItemStack item = cfg.getItem(path + ".Item");
|
ItemStack item = cfg.getItem(path + ".Item");
|
||||||
data = item.getType().isAir() ? new ItemStack(Material.STONE) : 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);
|
else if (dataType != Void.class) return UniParticle.of(Particle.REDSTONE);
|
||||||
|
|
||||||
return UniParticle.of(particle, data);
|
return UniParticle.of(particle, data);
|
||||||
@@ -119,6 +124,12 @@ public class UniParticle {
|
|||||||
else if (data instanceof ItemStack item) {
|
else if (data instanceof ItemStack item) {
|
||||||
cfg.setItem(path + ".Item", 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() {
|
public boolean isEmpty() {
|
||||||
@@ -134,39 +145,6 @@ public class UniParticle {
|
|||||||
return data;
|
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) {
|
public void play(@NotNull Location location, double speed, int amount) {
|
||||||
this.play(location, 0D, speed, 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) {
|
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.isEmpty()) return;
|
||||||
|
if (this.particle == null || (this.particle.getDataType() != Void.class && this.data == null)) return;
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
World world = location.getWorld();
|
World world = location.getWorld();
|
||||||
|
|||||||
Reference in new issue
Block a user