mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 14:38:46 +00:00
v2.7.2
This commit is contained in:
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);
|
return Color.fromRGB(red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String transformForID(@NotNull String str) {
|
||||||
|
return transformForID(str, -1);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String transformForID(@NotNull String str, int length) {
|
public static String transformForID(@NotNull String str, int length) {
|
||||||
char[] chars = str.toCharArray();
|
char[] chars = str.toCharArray();
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import org.bukkit.Color;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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.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.config.Writeable;
|
import su.nightexpress.nightcore.config.Writeable;
|
||||||
import su.nightexpress.nightcore.core.CoreLogger;
|
import su.nightexpress.nightcore.core.CoreLogger;
|
||||||
import su.nightexpress.nightcore.util.BukkitThing;
|
import su.nightexpress.nightcore.util.*;
|
||||||
import su.nightexpress.nightcore.util.ItemUtil;
|
|
||||||
import su.nightexpress.nightcore.util.StringUtil;
|
|
||||||
import su.nightexpress.nightcore.util.Version;
|
|
||||||
import su.nightexpress.nightcore.util.placeholder.Replacer;
|
import su.nightexpress.nightcore.util.placeholder.Replacer;
|
||||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
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);
|
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.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.setCustomModelData(this.modelData);
|
||||||
meta.setUnbreakable(this.unbreakable);
|
meta.setUnbreakable(this.unbreakable);
|
||||||
|
|
||||||
@@ -288,6 +288,35 @@ public class NightItem implements Writeable {
|
|||||||
return itemStack;
|
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
|
@NotNull
|
||||||
public NightItem removeNameAndLore() {
|
public NightItem removeNameAndLore() {
|
||||||
this.setItemName(null);
|
this.setItemName(null);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import su.nightexpress.nightcore.util.text.NightMessage;
|
|||||||
import su.nightexpress.nightcore.util.text.TextRoot;
|
import su.nightexpress.nightcore.util.text.TextRoot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -89,9 +90,16 @@ public class Replacer {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> apply(@NotNull List<String> list) {
|
public List<String> apply(@NotNull List<String> list) {
|
||||||
List<String> replaced = new ArrayList<>();
|
// List<String> replaced = new ArrayList<>();
|
||||||
list.forEach(line -> replaced.add(this.apply(line)));
|
// list.forEach(line -> replaced.add(this.apply(line)));
|
||||||
return replaced;
|
// return replaced;
|
||||||
|
|
||||||
|
List<String> result = new ArrayList<>(list);
|
||||||
|
for (UnaryOperator<String> operator : this.getReplacers()) {
|
||||||
|
result = replaceList(result, operator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -115,6 +123,21 @@ public class Replacer {
|
|||||||
return meta;
|
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
|
@NotNull
|
||||||
public Replacer replacePlaceholderAPI(@NotNull Player player) {
|
public Replacer replacePlaceholderAPI(@NotNull Player player) {
|
||||||
if (!Plugins.hasPlaceholderAPI()) return this;
|
if (!Plugins.hasPlaceholderAPI()) return this;
|
||||||
|
|||||||
@@ -33,12 +33,21 @@ public class Tag {
|
|||||||
return OPEN_BRACKET + str + CLOSE_BRACKET;
|
return OPEN_BRACKET + str + CLOSE_BRACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String closedBrackets(@NotNull String str) {
|
||||||
|
return brackets(CLOSE_SLASH + str);
|
||||||
|
}
|
||||||
|
|
||||||
/*@NotNull
|
/*@NotNull
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String enclose(@NotNull String text) {
|
public String enclose(@NotNull String text) {
|
||||||
return this.getBracketsName() + text + this.getClosingName();
|
return this.getBracketsName() + text + this.getClosingName();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
public final boolean isNamed(@NotNull String name) {
|
||||||
|
return this.name.equalsIgnoreCase(name) || this.aliases.contains(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final String getFullName() {
|
public final String getFullName() {
|
||||||
@@ -47,11 +56,7 @@ public class Tag {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public final String getClosingName() {
|
public final String getClosingName() {
|
||||||
return brackets(CLOSE_SLASH + this.getName());
|
return closedBrackets(this.getName());
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isNamed(@NotNull String name) {
|
|
||||||
return this.name.equalsIgnoreCase(name) || this.aliases.contains(name.toLowerCase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ public class ColorTag extends SimpleTag implements ColorDecorator {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String encloseHex(@NotNull String text) {
|
||||||
|
String hex = this.toHexString();
|
||||||
|
|
||||||
|
return brackets(hex) + text + closedBrackets(hex);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decorate(@NotNull BaseComponent component) {
|
public void decorate(@NotNull BaseComponent component) {
|
||||||
component.setColor(ChatColor.of(this.getColor()));
|
component.setColor(ChatColor.of(this.getColor()));
|
||||||
|
|||||||
Reference in new issue
Block a user