This commit is contained in:
nulli0n committed 2024-11-20 19:40:15 +05:00
1 parent af553c6f63
commit 69f74b7451
5 files changed
+83 -14

No files matched your search

@@ -262,6 +262,11 @@ public class StringUtil {
return Color.fromRGB(red, green, blue);
}
@NotNull
public static String transformForID(@NotNull String str) {
return transformForID(str, -1);
}
@NotNull
public static String transformForID(@NotNull String str, int length) {
char[] chars = str.toCharArray();
@@ -6,16 +6,16 @@ import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.config.Writeable;
import su.nightexpress.nightcore.core.CoreLogger;
import su.nightexpress.nightcore.util.BukkitThing;
import su.nightexpress.nightcore.util.ItemUtil;
import su.nightexpress.nightcore.util.StringUtil;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.*;
import su.nightexpress.nightcore.util.placeholder.Replacer;
import su.nightexpress.nightcore.util.text.NightMessage;
@@ -258,7 +258,7 @@ public class NightItem implements Writeable {
List<String> replacedLore = replacer == null || this.lore == null ? this.lore : replacer.apply(this.lore);
meta.setDisplayName(replacedDisplayName == null ? null : (legacy ? NightMessage.asLegacy(replacedDisplayName) : replacedDisplayName));
meta.setLore(replacedLore == null ? null : (legacy ? NightMessage.asLegacy(replacedLore) : replacedLore));
meta.setLore(replacedLore == null ? null : (legacy ? NightMessage.asLegacy(this.addEmptyLines(replacedLore)) : this.addEmptyLines(replacedLore)));
meta.setCustomModelData(this.modelData);
meta.setUnbreakable(this.unbreakable);
@@ -288,6 +288,35 @@ public class NightItem implements Writeable {
return itemStack;
}
@NotNull
private List<String> addEmptyLines(@NotNull List<String> lore) {
for (int index = 0; index < lore.size(); index++) {
String line = lore.get(index);
if (line.equalsIgnoreCase(Placeholders.EMPTY_IF_ABOVE)) {
if (index == 0 || this.isEmpty(lore.get(index - 1))) {
lore.remove(index);
}
else lore.set(index, "");
return addEmptyLines(lore);
}
else if (line.equalsIgnoreCase(Placeholders.EMPTY_IF_BELOW)) {
if (index == lore.size() - 1 || this.isEmpty(lore.get(index + 1))) {
lore.remove(index);
}
else lore.set(index, "");
return addEmptyLines(lore);
}
}
return lore;
}
private boolean isEmpty(@NotNull String line) {
return line.isBlank() || line.equalsIgnoreCase(Placeholders.EMPTY_IF_ABOVE) || line.equalsIgnoreCase(Placeholders.EMPTY_IF_BELOW);
}
@NotNull
public NightItem removeNameAndLore() {
this.setItemName(null);
@@ -12,6 +12,7 @@ import su.nightexpress.nightcore.util.text.NightMessage;
import su.nightexpress.nightcore.util.text.TextRoot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -89,9 +90,16 @@ public class Replacer {
@NotNull
public List<String> apply(@NotNull List<String> list) {
List<String> replaced = new ArrayList<>();
list.forEach(line -> replaced.add(this.apply(line)));
return replaced;
// List<String> replaced = new ArrayList<>();
// list.forEach(line -> replaced.add(this.apply(line)));
// return replaced;
List<String> result = new ArrayList<>(list);
for (UnaryOperator<String> operator : this.getReplacers()) {
result = replaceList(result, operator);
}
return result;
}
@NotNull
@@ -115,6 +123,21 @@ public class Replacer {
return meta;
}
@NotNull
private static List<String> replaceList(@NotNull List<String> lore, @NotNull UnaryOperator<String> operator) {
List<String> replaced = new ArrayList<>();
for (String line : lore) {
if (!line.isBlank()) {
line = operator.apply(line);
if (line.isBlank()) continue;
replaced.addAll(Arrays.asList(line.split("\n")));
}
else replaced.add(line);
}
return replaced;
}
@NotNull
public Replacer replacePlaceholderAPI(@NotNull Player player) {
if (!Plugins.hasPlaceholderAPI()) return this;
@@ -33,12 +33,21 @@ public class Tag {
return OPEN_BRACKET + str + CLOSE_BRACKET;
}
@NotNull
public static String closedBrackets(@NotNull String str) {
return brackets(CLOSE_SLASH + str);
}
/*@NotNull
@Deprecated
public String enclose(@NotNull String text) {
return this.getBracketsName() + text + this.getClosingName();
}*/
public final boolean isNamed(@NotNull String name) {
return this.name.equalsIgnoreCase(name) || this.aliases.contains(name.toLowerCase());
}
@NotNull
@Deprecated
public final String getFullName() {
@@ -47,11 +56,7 @@ public class Tag {
@NotNull
public final String getClosingName() {
return brackets(CLOSE_SLASH + this.getName());
}
public final boolean isNamed(@NotNull String name) {
return this.name.equalsIgnoreCase(name) || this.aliases.contains(name.toLowerCase());
return closedBrackets(this.getName());
}
@NotNull
@@ -43,6 +43,13 @@ public class ColorTag extends SimpleTag implements ColorDecorator {
return color;
}
@NotNull
public String encloseHex(@NotNull String text) {
String hex = this.toHexString();
return brackets(hex) + text + closedBrackets(hex);
}
@Override
public void decorate(@NotNull BaseComponent component) {
component.setColor(ChatColor.of(this.getColor()));