mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-02 14:38:48 +00:00
tag, lang, menu fixes
This commit is contained in:
1 parent
5e7b1a20ec
commit
b69c8ea719
17 files changed
+211
-65
No files matched your search
@@ -82,12 +82,22 @@ public abstract class PluginCommand<P extends NightCorePlugin> extends AbstractC
|
||||
return childCount;
|
||||
}*/
|
||||
|
||||
/*private String[] insertArg(@NotNull String arg, int index, String[] args) {
|
||||
List<String> list = new ArrayList<>(Arrays.asList(args));
|
||||
if (index >= list.size()) {
|
||||
list.add(arg);
|
||||
}
|
||||
else list.add(index, arg);
|
||||
return list.toArray(new String[0]);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
NightCommand command = this.findChildren(args);
|
||||
if (command instanceof NightPluginCommand pluginCommand) {
|
||||
if (pluginCommand.getDefaultCommand() != null) {
|
||||
command = pluginCommand.getDefaultCommand();
|
||||
//args = insertArg(command.getAliases()[0], 0, args);
|
||||
}
|
||||
}
|
||||
command.execute(sender, label, args);
|
||||
|
||||
@@ -17,9 +17,9 @@ public class CoreLang {
|
||||
public static final LangText COMMAND_HELP_LIST = LangText.of("Command.Help.List",
|
||||
TAG_NO_PREFIX,
|
||||
" " + YELLOW.enclose(BOLD.enclose(GENERIC_NAME)) + GRAY.enclose(" - ") + YELLOW.enclose(BOLD.enclose("Commands:")),
|
||||
"",
|
||||
" ",
|
||||
GRAY.enclose(" " + RED.enclose(BOLD.enclose("<>")) + " - Required, " + GREEN.enclose(BOLD.enclose("[]")) + " - Optional."),
|
||||
"",
|
||||
" ",
|
||||
GENERIC_ENTRY,
|
||||
" "
|
||||
);
|
||||
|
||||
@@ -30,11 +30,11 @@ public abstract class AbstractUserDataHandler<P extends NightDataPlugin<U>, U ex
|
||||
protected final Set<UUID> existIDs;
|
||||
protected final Set<String> existNames;
|
||||
|
||||
protected AbstractUserDataHandler(@NotNull P plugin) {
|
||||
public AbstractUserDataHandler(@NotNull P plugin) {
|
||||
this(plugin, DatabaseConfig.read(plugin));
|
||||
}
|
||||
|
||||
protected AbstractUserDataHandler(@NotNull P plugin, @NotNull DatabaseConfig config) {
|
||||
public AbstractUserDataHandler(@NotNull P plugin, @NotNull DatabaseConfig config) {
|
||||
super(plugin, config);
|
||||
this.tableUsers = this.getTablePrefix() + "_users";
|
||||
this.existIDs = new HashSet<>();
|
||||
|
||||
@@ -74,7 +74,7 @@ public class LangMessage {
|
||||
if (typeIndex == -1) continue;
|
||||
|
||||
String leading = legContent.substring(typeIndex + type.length() + 1);
|
||||
String typeContent = DynamicTag.parseQuotedContentFix(leading);
|
||||
String typeContent = StringUtil.parseQuotedContent(leading);
|
||||
if (typeContent == null) continue;
|
||||
|
||||
if (type.equalsIgnoreCase("type")) {
|
||||
@@ -146,7 +146,7 @@ public class LangMessage {
|
||||
if (tag instanceof DynamicTag) {
|
||||
int prefixSize = tag.getName().length() + 1; // 1 for semicolon
|
||||
|
||||
String content = DynamicTag.parseQuotedContent(leading.substring(prefixSize));
|
||||
String content = StringUtil.parseQuotedContent(leading.substring(prefixSize));
|
||||
if (content == null) break Tag;
|
||||
|
||||
decorator.apply(options, content);
|
||||
@@ -166,7 +166,18 @@ public class LangMessage {
|
||||
String text = builder.toString();
|
||||
String prefix = options.getOutputType() == OutputType.CHAT && options.hasPrefix() ? plugin.getPrefix() : null;
|
||||
|
||||
return new LangMessage(plugin, text, options, prefix);
|
||||
// Remove completely empty lines.
|
||||
// Especially useful for message tags lines without extra text.
|
||||
StringBuilder stripper = new StringBuilder();
|
||||
for (String part : text.split(Placeholders.TAG_LINE_BREAK)) {
|
||||
if (part.isEmpty()) continue;
|
||||
|
||||
if (!stripper.isEmpty()) stripper.append(Placeholders.TAG_LINE_BREAK);
|
||||
stripper.append(part);
|
||||
}
|
||||
String strippedText = stripper.toString();
|
||||
|
||||
return new LangMessage(plugin, strippedText, options, prefix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package su.nightexpress.nightcore.menu.api;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.menu.click.ClickAction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class AutoFill<T> {
|
||||
|
||||
private int[] slots;
|
||||
private List<T> items;
|
||||
private Function<T, ItemStack> itemCreator;
|
||||
private Function<T, ClickAction> clickAction;
|
||||
|
||||
public AutoFill() {
|
||||
this.setSlots();
|
||||
this.setItems(new ArrayList<>());
|
||||
this.setItemCreator(obj -> new ItemStack(Material.AIR));
|
||||
this.setClickAction(obj -> (viewer, event) -> {});
|
||||
}
|
||||
|
||||
public int[] getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public void setSlots(int... slots) {
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<T> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(@NotNull Collection<T> items) {
|
||||
this.setItems(new ArrayList<>(items));
|
||||
}
|
||||
|
||||
public void setItems(@NotNull List<T> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Function<T, ItemStack> getItemCreator() {
|
||||
return itemCreator;
|
||||
}
|
||||
|
||||
public void setItemCreator(@NotNull Function<T, ItemStack> itemCreator) {
|
||||
this.itemCreator = itemCreator;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Function<T, ClickAction> getClickAction() {
|
||||
return clickAction;
|
||||
}
|
||||
|
||||
public void setClickAction(@NotNull Function<T, ClickAction> clickAction) {
|
||||
this.clickAction = clickAction;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.menu.MenuViewer;
|
||||
import su.nightexpress.nightcore.menu.click.ClickAction;
|
||||
import su.nightexpress.nightcore.menu.item.ItemOptions;
|
||||
import su.nightexpress.nightcore.menu.item.MenuItem;
|
||||
|
||||
@@ -13,25 +12,38 @@ import java.util.List;
|
||||
|
||||
public interface AutoFilled<I> extends Menu {
|
||||
|
||||
int[] getAutoFillSlots();
|
||||
default boolean open(@NotNull Player player, int page) {
|
||||
return this.open(this.getViewerOrCreate(player), page);
|
||||
}
|
||||
|
||||
@NotNull List<I> getAutoFills(@NotNull Player player);
|
||||
default boolean open(@NotNull MenuViewer viewer, int page) {
|
||||
viewer.setPage(page);
|
||||
return this.open(viewer);
|
||||
}
|
||||
|
||||
@NotNull ItemStack getAutoFillStack(@NotNull Player player, @NotNull I object);
|
||||
void onAutoFill(@NotNull MenuViewer viewer, @NotNull AutoFill<I> autoFill);
|
||||
|
||||
@NotNull ClickAction getAutoFillClick(@NotNull I object);
|
||||
/*@Deprecated int[] getAutoFillSlots();
|
||||
|
||||
@Deprecated @NotNull List<I> getAutoFills(@NotNull Player player);
|
||||
|
||||
@Deprecated @NotNull ItemStack getAutoFillStack(@NotNull Player player, @NotNull I object);
|
||||
|
||||
@Deprecated@NotNull ClickAction getAutoFillClick(@NotNull I object);*/
|
||||
|
||||
default void autoFill(@NotNull MenuViewer viewer) {
|
||||
this.getAutoFillItems(viewer).forEach(this::addItem);
|
||||
AutoFill<I> autoFill = new AutoFill<>();
|
||||
this.onAutoFill(viewer, autoFill);
|
||||
this.getAutoFillItems(viewer, autoFill).forEach(this::addItem);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
default List<MenuItem> getAutoFillItems(@NotNull MenuViewer viewer) {
|
||||
default List<MenuItem> getAutoFillItems(@NotNull MenuViewer viewer, @NotNull AutoFill<I> autoFill) {
|
||||
Player player = viewer.getPlayer();
|
||||
List<MenuItem> items = new ArrayList<>();
|
||||
List<I> origin = this.getAutoFills(player);
|
||||
List<I> origin = autoFill.getItems();//this.getAutoFills(player);
|
||||
|
||||
int[] slots = this.getAutoFillSlots();
|
||||
int[] slots = autoFill.getSlots();//this.getAutoFillSlots();
|
||||
int limit = slots.length;
|
||||
int pages = (int) Math.ceil((double) origin.size() / (double) limit);
|
||||
viewer.setPages(pages);
|
||||
@@ -43,12 +55,10 @@ public interface AutoFilled<I> extends Menu {
|
||||
|
||||
int count = 0;
|
||||
for (I object : list) {
|
||||
ItemStack item = this.getAutoFillStack(player, object);
|
||||
ItemStack item = autoFill.getItemCreator().apply(object);//this.getAutoFillStack(player, object);
|
||||
ItemOptions options = ItemOptions.personalWeak(player);
|
||||
MenuItem menuItem = new MenuItem(item).setPriority(100).setOptions(options).setSlots(slots[count++])
|
||||
.addClick(this.getAutoFillClick(object));
|
||||
//MenuItem menuItem = new MenuItem(item, 100, options, slots[count++]);
|
||||
//menuItem.addClick(this.getAutoFillClick(object));
|
||||
.addClick(autoFill.getClickAction().apply(object)/*this.getAutoFillClick(object)*/);
|
||||
items.add(menuItem);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,15 @@ public interface Menu {
|
||||
|
||||
void clear();
|
||||
|
||||
void flush();
|
||||
default void flush() {
|
||||
this.getViewers().forEach(this::flush);
|
||||
}
|
||||
|
||||
default void flush(@NotNull MenuViewer viewer) {
|
||||
this.flush(viewer.getPlayer());
|
||||
}
|
||||
|
||||
void flush(@NotNull Player player);
|
||||
|
||||
void close();
|
||||
|
||||
@@ -42,6 +50,8 @@ public interface Menu {
|
||||
|
||||
@Nullable MenuViewer getViewer(@NotNull Player player);
|
||||
|
||||
@NotNull MenuViewer getViewerOrCreate(@NotNull Player player);
|
||||
|
||||
|
||||
|
||||
@NotNull List<MenuItem> getItems(@NotNull MenuViewer viewer);
|
||||
|
||||
@@ -84,8 +84,8 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
this.getViewers().forEach(viewer -> this.open(viewer.getPlayer()));
|
||||
public void flush(@NotNull Player player) {
|
||||
this.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,8 +193,9 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
||||
return this.getViewersMap().get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
private MenuViewer getViewerOrCreate(@NotNull Player player) {
|
||||
public MenuViewer getViewerOrCreate(@NotNull Player player) {
|
||||
return this.getViewersMap().computeIfAbsent(player.getUniqueId(), k -> new MenuViewer(player));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package su.nightexpress.nightcore.menu.impl;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
@@ -38,19 +39,18 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addNextPage(int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgyYWQxYjljYjRkZDIxMjU5YzBkNzVhYTMxNWZmMzg5YzNjZWY3NTJiZTM5NDkzMzgxNjRiYWM4NGE5NmUifX19");
|
||||
ItemStack item = ItemUtil.getSkinHead("f32ca66056b72863e98f7f32bd7d94c7a0d796af691c9ac3a9136331352288f9");
|
||||
return this.addItem(item, CoreLang.EDITOR_ITEM_NEXT_PAGE, slots).setHandler(ItemHandler.forNextPage(this));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addPreviousPage(int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzdhZWU5YTc1YmYwZGY3ODk3MTgzMDE1Y2NhMGIyYTdkNzU1YzYzMzg4ZmYwMTc1MmQ1ZjQ0MTlmYzY0NSJ9fX0=");
|
||||
ItemStack item = ItemUtil.getSkinHead("86971dd881dbaf4fd6bcaa93614493c612f869641ed59d1c9363a3666a5fa6");
|
||||
return this.addItem(item, CoreLang.EDITOR_ITEM_PREVIOUS_PAGE, slots).setHandler(ItemHandler.forPreviousPage(this));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
protected MenuItem addReturn(int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM4NTJiZjYxNmYzMWVkNjdjMzdkZTRiMGJhYTJjNWY4ZDhmY2E4MmU3MmRiY2FmY2JhNjY5NTZhODFjNCJ9fX0=");
|
||||
@@ -58,25 +58,39 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
protected MenuItem addCreation(@NotNull LangItem locale, int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWZmMzE0MzFkNjQ1ODdmZjZlZjk4YzA2NzU4MTA2ODFmOGMxM2JmOTZmNTFkOWNiMDdlZDc4NTJiMmZmZDEifX19");
|
||||
return this.addItem(item, locale, slots);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addReturn(int slot, @NotNull EditorHandler<T> handler) {
|
||||
ItemStack item = ItemUtil.getSkinHead("27548362a24c0fa8453e4d93e68c5969ddbde57bf6666c0319c1ed1e84d89065");
|
||||
return this.addItem(item, CoreLang.EDITOR_ITEM_RETURN, slot, handler);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addCreation(@NotNull LangItem locale, int slot, @NotNull EditorHandler<T> handler) {
|
||||
ItemStack item = ItemUtil.getSkinHead("5ff31431d64587ff6ef98c0675810681f8c13bf96f51d9cb07ed7852b2ffd1");
|
||||
return this.addItem(item, locale, slot, handler);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addExit(int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmViNTg4YjIxYTZmOThhZDFmZjRlMDg1YzU1MmRjYjA1MGVmYzljYWI0MjdmNDYwNDhmMThmYzgwMzQ3NWY3In19fQ==");
|
||||
ItemStack item = ItemUtil.getSkinHead("27548362a24c0fa8453e4d93e68c5969ddbde57bf6666c0319c1ed1e84d89065");
|
||||
return this.addItem(item, CoreLang.EDITOR_ITEM_CLOSE, slots).setHandler(ItemHandler.forClose(this));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public MenuItem addItem(@NotNull Material material, @NotNull LangItem locale, int... slots) {
|
||||
return this.addItem(new ItemStack(material), locale, slots);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public MenuItem addItem(@NotNull ItemStack item, @NotNull LangItem locale, int... slots) {
|
||||
ItemReplacer.create(item).trimmed().hideFlags().readLocale(locale).writeMeta();
|
||||
MenuItem menuItem = new MenuItem(item).setPriority(100).setSlots(slots);
|
||||
@@ -84,6 +98,20 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MenuItem addItem(@NotNull Material material, @NotNull LangItem locale, int slot, @NotNull EditorHandler<T> handler) {
|
||||
return this.addItem(new ItemStack(material), locale, slot, handler);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MenuItem addItem(@NotNull ItemStack item, @NotNull LangItem locale, int slot, @NotNull EditorHandler<T> handler) {
|
||||
ItemReplacer.create(item).trimmed().hideFlags().readLocale(locale).writeMeta();
|
||||
MenuItem menuItem = new MenuItem(item).setPriority(100).setSlots(slot)
|
||||
.setHandler((viewer, event) -> handler.handle(viewer, event, this.getObject(viewer)));
|
||||
this.addItem(menuItem);
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Dialog handleInput(@NotNull MenuViewer viewer, @NotNull LangString prompt, @NotNull DialogHandler handler) {
|
||||
return this.handleInput(viewer.getPlayer(), prompt, handler);
|
||||
@@ -129,4 +157,9 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
public T getObject(@NotNull Player player) {
|
||||
return this.getLink().get(player);
|
||||
}
|
||||
|
||||
public interface EditorHandler<T> {
|
||||
|
||||
void handle(@NotNull MenuViewer viewer, @NotNull InventoryClickEvent event, @NotNull T obj);
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,11 @@ public class MenuItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MenuItem setHandler(@NotNull ClickAction click) {
|
||||
return this.setHandler(ItemHandler.forClick(click));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MenuItem addClick(@NotNull ClickAction click) {
|
||||
this.getHandler().getClickActions().add(click);
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
public class Colorizer {
|
||||
|
||||
public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})");
|
||||
public static final Pattern PATTERN_HEX_LEGACY = Pattern.compile("(?:^|[^<])(#[A-Fa-f0-9]{6})(?:$|[^>])");
|
||||
public static final Pattern PATTERN_HEX_LEGACY = Pattern.compile("(?:^|[^<])(#[A-Fa-f0-9]{6})(?:$|[^:>])");
|
||||
public static final Pattern PATTERN_GRADIENT = Pattern.compile("<gradient:" + PATTERN_HEX.pattern() + ">(.*?)</gradient:" + PATTERN_HEX.pattern() + ">");
|
||||
|
||||
@NotNull
|
||||
@@ -83,6 +83,7 @@ public class Colorizer {
|
||||
String start = matcher.group(1);
|
||||
String end = matcher.group(3);
|
||||
String content = matcher.group(2);
|
||||
System.out.println("content legacy = " + content);
|
||||
|
||||
java.awt.Color colorStart = new java.awt.Color(Integer.parseInt(start, 16));
|
||||
java.awt.Color colorEnd = new java.awt.Color(Integer.parseInt(end, 16));
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Placeholders {
|
||||
|
||||
public static final String GITHUB_URL = "https://github.com/nulli0n/nightcore-spigot";
|
||||
public static final String WIKI_MAIN_URL = GITHUB_URL + "/wiki/";
|
||||
public static final String WIKI_ITEMS_URL = WIKI_MAIN_URL + "Configuration-Tips#item-sections";
|
||||
public static final String WIKI_ITEMS_URL = WIKI_MAIN_URL + "ItemStack-Options";
|
||||
public static final String WIKI_TEXT_URL = WIKI_MAIN_URL + "Text-Formation";
|
||||
public static final String WIKI_LANG_URL = WIKI_MAIN_URL + "Language-Formation";
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package su.nightexpress.nightcore.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.random.Rnd;
|
||||
import su.nightexpress.nightcore.util.regex.TimedMatcher;
|
||||
|
||||
@@ -101,6 +102,29 @@ public class StringUtil {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String parseQuotedContent(@NotNull String string) {
|
||||
char quote = string.charAt(0);
|
||||
if (quote != '\'' && quote != '"') return null;
|
||||
if (string.length() < 3) return null;
|
||||
|
||||
int indexEnd = -1;
|
||||
for (int index = 1; index < string.length(); index++) {
|
||||
char letter = string.charAt(index);
|
||||
if (letter == '\\') {
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
if (letter == quote) {
|
||||
indexEnd = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexEnd == -1) return null;
|
||||
|
||||
return string.substring(1, indexEnd);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends Enum<T>> Optional<T> getEnum(String str, @NotNull Class<T> clazz) {
|
||||
try {
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class DynamicTag extends Tag {
|
||||
return leading(prefix, content) + text + this.getClosingName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
/*@Nullable
|
||||
@Deprecated
|
||||
public static String parseQuotedContent(@NotNull String string) {
|
||||
char quote = string.charAt(0);
|
||||
@@ -39,7 +39,7 @@ public abstract class DynamicTag extends Tag {
|
||||
if (index == (string.length() - 1) || index == 0) continue;
|
||||
|
||||
char letter = string.charAt(index);
|
||||
if (letter == '\\') { // TODO Replace/remove it
|
||||
if (letter == '\\') {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
@@ -54,29 +54,5 @@ public abstract class DynamicTag extends Tag {
|
||||
if (indexEnd == -1) return null;
|
||||
|
||||
return string.substring(1, indexEnd);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String parseQuotedContentFix(@NotNull String string) {
|
||||
char quote = string.charAt(0);
|
||||
if (quote != '\'' && quote != '"') return null;
|
||||
|
||||
int indexEnd = -1;
|
||||
for (int index = 0; index < string.length(); index++) {
|
||||
if (index == (string.length() - 1) || index == 0) continue;
|
||||
|
||||
char letter = string.charAt(index);
|
||||
if (letter == '\\') {
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
if (letter == quote) {
|
||||
indexEnd = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexEnd == -1) return null;
|
||||
|
||||
return string.substring(1, indexEnd);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package su.nightexpress.nightcore.util.text.tag.impl;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ClickEventDecorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.Decorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ParsedDecorator;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.ContentTag;
|
||||
|
||||
public class ClickTag extends ContentTag {
|
||||
@@ -43,7 +43,7 @@ public class ClickTag extends ContentTag {
|
||||
int prefixSize = action.name().toLowerCase().length() + 1; // 1 for ':', like "run_command:"
|
||||
sub = sub.substring(prefixSize);
|
||||
|
||||
String content = DynamicTag.parseQuotedContent(sub);
|
||||
String content = StringUtil.parseQuotedContent(sub);
|
||||
if (content == null) return null;
|
||||
|
||||
int length = prefixSize + content.length();// + 2; // 2 for quotes
|
||||
|
||||
@@ -2,9 +2,9 @@ package su.nightexpress.nightcore.util.text.tag.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
import su.nightexpress.nightcore.util.text.decoration.FontDecorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ParsedDecorator;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.ContentTag;
|
||||
|
||||
public class FontTag extends ContentTag {
|
||||
@@ -18,7 +18,7 @@ public class FontTag extends ContentTag {
|
||||
@Override
|
||||
@Nullable
|
||||
public ParsedDecorator onParse(@NotNull String str) {
|
||||
String content = DynamicTag.parseQuotedContent(str);
|
||||
String content = StringUtil.parseQuotedContent(str);
|
||||
if (content == null) return null;
|
||||
|
||||
int length = content.length();// + 2; // 2 for quotes
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.ItemUtil;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
import su.nightexpress.nightcore.util.text.decoration.Decorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ParsedDecorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ShowItemDecorator;
|
||||
import su.nightexpress.nightcore.util.text.decoration.ShowTextDecorator;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.ContentTag;
|
||||
|
||||
public class HoverTag extends ContentTag {
|
||||
@@ -52,7 +52,7 @@ public class HoverTag extends ContentTag {
|
||||
int prefixSize = action.name().toLowerCase().length() + 1; // 1 for ':', like "show_text:"
|
||||
sub = sub.substring(prefixSize);
|
||||
|
||||
String content = DynamicTag.parseQuotedContent(sub);
|
||||
String content = StringUtil.parseQuotedContent(sub);
|
||||
if (content == null) return null;
|
||||
|
||||
int length = prefixSize + content.length();// + 2; // 2 for quotes
|
||||
|
||||
Reference in new issue
Block a user