mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-01 14:38:47 +00:00
tag fixes
This commit is contained in:
1 parent
2f9ba7d063
commit
c76a241d09
5 files changed
+54
-22
No files matched your search
@@ -84,13 +84,13 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
return this.addItem(item, locale, slot, handler);
|
||||
}
|
||||
|
||||
/*@NotNull
|
||||
@NotNull
|
||||
@Deprecated
|
||||
protected MenuItem addExit(int... slots) {
|
||||
protected MenuItem addExit(int[] slots) {
|
||||
//ItemStack item = ItemUtil.getSkinHead("27548362a24c0fa8453e4d93e68c5969ddbde57bf6666c0319c1ed1e84d89065");
|
||||
//return this.addItem(item, CoreLang.EDITOR_ITEM_CLOSE, slots).setHandler(ItemHandler.forClose(this));
|
||||
return this.addExit(slots[0]);
|
||||
}*/
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MenuItem addExit(int slot) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package su.nightexpress.nightcore.util;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.regex.TimedMatcher;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.Tag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -13,7 +14,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
|
||||
@@ -126,20 +127,48 @@ public class Colorizer {
|
||||
|
||||
@NotNull
|
||||
public static String plainHex(@NotNull String str) {
|
||||
StringBuilder buffer = new StringBuilder(str);
|
||||
StringBuilder builder = new StringBuilder(str);
|
||||
|
||||
int index;
|
||||
while ((index = buffer.toString().indexOf(ChatColor.COLOR_CHAR + "x")) >= 0) {
|
||||
while ((index = builder.toString().indexOf(ChatColor.COLOR_CHAR + "x")) >= 0) {
|
||||
int count = 0;
|
||||
buffer.replace(index, index + 2, "#");
|
||||
builder.replace(index, index + 2, "#");
|
||||
|
||||
for (int point = index + 1; count < 6; point += 1) {
|
||||
buffer.deleteCharAt(point);
|
||||
builder.deleteCharAt(point);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
return tagPlainHex(builder.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String tagPlainHex(@NotNull String str) {
|
||||
StringBuilder builder = new StringBuilder(str);
|
||||
|
||||
int index;
|
||||
int lastIndex = 0;
|
||||
|
||||
while ((index = builder.toString().indexOf("#", lastIndex)) >= 0) {
|
||||
lastIndex = index + 1;
|
||||
|
||||
if (builder.length() < 7) break;
|
||||
if (index > 0 && builder.charAt(index - 1) == Tag.OPEN_BRACKET) continue;
|
||||
|
||||
String sub = builder.substring(index, index + 7);
|
||||
try {
|
||||
Integer.decode(sub);
|
||||
}
|
||||
catch (NumberFormatException exception) {
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.insert(index, Tag.OPEN_BRACKET);
|
||||
builder.insert(index + 8, Tag.CLOSE_BRACKET);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -111,6 +111,8 @@ public class Lists {
|
||||
|
||||
@NotNull
|
||||
public static List<String> getSequentialMatches(@NotNull List<String> results, @NotNull String input) {
|
||||
if (input.isBlank()) return results;
|
||||
|
||||
char[] chars = input.toCharArray();
|
||||
List<String> goods = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -75,7 +75,10 @@ public class TextGroup implements ComponentBuildable {
|
||||
}
|
||||
|
||||
this.childrens.forEach(child -> {
|
||||
builder.append(child.toComponent());
|
||||
BaseComponent childComponent = child.toComponent();
|
||||
if (!TextRoot.isEmpty(childComponent)) {
|
||||
builder.append(childComponent);
|
||||
}
|
||||
});
|
||||
|
||||
return builder.build();
|
||||
|
||||
@@ -6,21 +6,17 @@ import net.md_5.bungee.chat.ComponentSerializer;
|
||||
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.regex.TimedMatcher;
|
||||
import su.nightexpress.nightcore.util.text.tag.TagPool;
|
||||
import su.nightexpress.nightcore.util.text.tag.Tags;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.ContentTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.PlaceholderTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.api.Tag;
|
||||
import su.nightexpress.nightcore.util.text.tag.decorator.Decorator;
|
||||
import su.nightexpress.nightcore.util.text.tag.impl.ShortHexColorTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.impl.ResetTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.impl.ShortHexColorTag;
|
||||
import su.nightexpress.nightcore.util.text.tag.impl.TranslationTag;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class TextRoot {
|
||||
@@ -42,7 +38,9 @@ public class TextRoot {
|
||||
}
|
||||
|
||||
public void setString(@NotNull String string) {
|
||||
if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
|
||||
string = Colorizer.plain(string);
|
||||
|
||||
/*if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
|
||||
TimedMatcher timedMatcher = TimedMatcher.create(Colorizer.PATTERN_HEX_LEGACY, string);
|
||||
Set<String> rawCodes = new HashSet<>();
|
||||
while (timedMatcher.find()) {
|
||||
@@ -52,7 +50,7 @@ public class TextRoot {
|
||||
for (String hex : rawCodes) {
|
||||
string = string.replace(hex, Tag.brackets(hex));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
this.string = string;
|
||||
this.component = null;
|
||||
@@ -81,13 +79,9 @@ public class TextRoot {
|
||||
|
||||
@NotNull
|
||||
public String toLegacy() {
|
||||
if (this.string.isBlank()) return "";
|
||||
|
||||
this.parseIfAbsent();
|
||||
|
||||
if (this.component instanceof TextComponent textComponent && textComponent.getText().isBlank() && textComponent.getExtra() == null) {
|
||||
return "";
|
||||
}
|
||||
if (this.string.isBlank() || isEmpty(this.component)) return "";
|
||||
|
||||
return TextComponent.toLegacyText(this.parseIfAbsent());
|
||||
}
|
||||
@@ -282,6 +276,10 @@ public class TextRoot {
|
||||
return component;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(@NotNull BaseComponent component) {
|
||||
return component instanceof TextComponent textComponent && textComponent.getText().isBlank() && textComponent.getExtra() == null;
|
||||
}
|
||||
|
||||
public static int indexOfIgnoreEscaped(@NotNull String string, char what, int from) {
|
||||
int length = string.length();
|
||||
if (from >= length) return -1;
|
||||
|
||||
Reference in new issue
Block a user