- Add support for the 'fallback' argument of the Translatable tag.
- Apply PlaceholderAPI for menu titles if enabled in the menu config.
- Split 'spigot' and 'paper' bridge into modules.
- Full reload support for the nightcore plugin.
This commit is contained in:
nulli0n committed 2025-05-30 20:45:33 +05:00
1 parent 84addd3454
commit 12a85ce198
326 files changed
+3586 -1534

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.7.6</version>
</parent>
<artifactId>utils</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,44 @@
package su.nightexpress.nightcore.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
public class Enums {
private static final String DEFAULT_DELIMITER = ", ";
@NotNull
public static <T extends Enum<T>> Optional<T> parse(String str, @NotNull Class<T> clazz) {
try {
return str == null ? Optional.empty() : Optional.of(Enum.valueOf(clazz, str.toUpperCase()));
}
catch (Exception exception) {
return Optional.empty();
}
}
@Nullable
public static <T extends Enum<T>> T get(String str, @NotNull Class<T> clazz) {
return parse(str, clazz).orElse(null);
}
@NotNull
public static String inline(@NotNull Class<? extends Enum<?>> clazz) {
return inline(clazz, DEFAULT_DELIMITER);
}
@NotNull
public static String inline(@NotNull Class<? extends Enum<?>> clazz, @NotNull String delimiter) {
return String.join(delimiter, Enums.getNames(clazz));
}
@NotNull
public static List<String> getNames(@NotNull Class<? extends Enum<?>> clazz) {
return Stream.of(clazz.getEnumConstants()).sorted(Comparator.comparingInt(Enum::ordinal)).map(Object::toString).toList();
}
}
@@ -0,0 +1,47 @@
package su.nightexpress.nightcore.util;
import org.jetbrains.annotations.NotNull;
public class LegacyColors {
private static final char COLOR_CHAR = '§';
private static final char ALT_COLOR_CHAR = '&';
private static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx";
@NotNull
public static String plainColors(@NotNull String string) {
string = plainHEXColors(string);
string = plainDefaultColors(string);
return string;
}
@NotNull
public static String plainDefaultColors(@NotNull String string) {
char[] b = string.toCharArray();
for (int i = 0; i < b.length - 1; i++) {
if (b[i] == COLOR_CHAR && ALL_CODES.indexOf(b[i + 1]) > -1) {
b[i] = ALT_COLOR_CHAR;
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);
}
@NotNull
public static String plainHEXColors(@NotNull String str) {
StringBuilder builder = new StringBuilder(str);
int index;
while ((index = builder.toString().indexOf(COLOR_CHAR + "x")) >= 0) {
int count = 0;
builder.replace(index, index + 2, "#");
for (int point = index + 1; count < 6; point += 1) {
builder.deleteCharAt(point);
count++;
}
}
return builder.toString();
}
}
@@ -0,0 +1,258 @@
package su.nightexpress.nightcore.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class Lists {
public static int indexOf(Object[] array, @NotNull Object objectToFind) {
return indexOf(array, objectToFind, 0);
}
public static int indexOf(Object[] array, @NotNull Object objectToFind, int startIndex) {
if (array == null || array.length == 0) return -1;
if (!array.getClass().getComponentType().isInstance(objectToFind)) return -1;
if (startIndex < 0) startIndex = 0;
int index;
for (index = startIndex; index < array.length; ++index) {
if (objectToFind.equals(array[index])) {
return index;
}
}
return -1;
}
public static boolean contains(Object[] array, Object objectToFind) {
return indexOf(array, objectToFind) != -1;
}
public static int indexOf(int[] array, int valueToFind) {
return indexOf(array, valueToFind, 0);
}
public static int indexOf(int[] array, int valueToFind, int startIndex) {
if (array == null || array.length == 0) return -1;
if (startIndex < 0) startIndex = 0;
for (int index = startIndex; index < array.length; ++index) {
if (valueToFind == array[index]) {
return index;
}
}
return -1;
}
public static boolean contains(int[] array, int valueToFind) {
return indexOf(array, valueToFind) != -1;
}
@NotNull
public static <T, R> Set<R> modify(@NotNull Set<T> set, @NotNull Function<T, R> function) {
return set.stream().map(function).collect(Collectors.toCollection(HashSet::new));
}
@NotNull
public static <T, R> List<R> modify(@NotNull List<T> set, @NotNull Function<T, R> function) {
return set.stream().map(function).collect(Collectors.toCollection(ArrayList::new));
}
@NotNull
public static <T> List<List<T>> split(@NotNull List<T> list, int targetSize) {
List<List<T>> lists = new ArrayList<>();
if (targetSize <= 0) return lists;
for (int index = 0; index < list.size(); index += targetSize) {
lists.add(list.subList(index, Math.min(index + targetSize, list.size())));
}
return lists;
}
@NotNull
public static List<String> replace(@NotNull List<String> origin, @NotNull String var, String... with) {
return replace(origin, var, Arrays.asList(with));
}
@NotNull
public static List<String> replace(@NotNull List<String> origin, @NotNull String var, @NotNull List<String> with) {
List<String> replaced = new ArrayList<>();
for (String line : origin) {
if (line.equalsIgnoreCase(var)) {
replaced.addAll(with);
}
else replaced.add(line);
}
return replaced;
}
/**
* @param original List to remove empty lines from.
* @return A list with no multiple empty lines in a row.
*/
@NotNull
@Deprecated
public static List<String> stripEmpty(@NotNull List<String> original) {
List<String> stripped = new ArrayList<>();
for (int index = 0; index < original.size(); index++) {
String line = original.get(index);
if (line.isEmpty()) {
String last = stripped.isEmpty() ? null : stripped.getLast();
if (last == null || last.isEmpty() || index == (original.size() - 1)) continue;
}
stripped.add(line);
}
return stripped;
}
@NotNull
public static List<String> getSequentialMatches(@NotNull List<String> results, @NotNull String input) {
if (input.isBlank()) return results;
char[] inputChars = input.toCharArray();
List<String> goods = new ArrayList<>();
Result:
for (String resultItem : results) {
int itemLength = resultItem.length();
if (input.length() > itemLength) continue;
int lastIndex = -1;
for (char letter : inputChars) {
int nextIndex = lastIndex;
if (nextIndex < 0) {
nextIndex = 0;
}
else if (nextIndex < itemLength - 1) {
nextIndex++; // This fixes an issue, where method fails for similar characters in a row, like 'oo'.
}
letter = Character.toLowerCase(letter);
int index = resultItem.toLowerCase().indexOf(letter, nextIndex);
if (index <= lastIndex) {
continue Result;
}
lastIndex = index;
}
goods.add(resultItem);
}
return goods;
}
@NotNull
public static <K, V extends Comparable<? super V>> Map<K, V> sortAscent(@NotNull Map<K, V> map) {
return sort(map, Map.Entry.comparingByValue());
}
@NotNull
public static <K, V extends Comparable<? super V>> Map<K, V> sortDescent(@NotNull Map<K, V> map) {
return sort(map, Collections.reverseOrder(Map.Entry.comparingByValue()));
}
@SafeVarargs
@NotNull
public static <T> List<T> newList(T... values) {
List<T> list = new ArrayList<>();
Collections.addAll(list, values);
return list;
}
@SafeVarargs
@NotNull
public static <T> Set<T> newSet(T... values) {
Set<T> list = new HashSet<>();
Collections.addAll(list, values);
return list;
}
@NotNull
public static <K, V extends Comparable<? super V>> Map<K, V> sort(@NotNull Map<K, V> map, @NotNull Comparator<Map.Entry<K, V>> comparator) {
return new LinkedList<>(map.entrySet()).stream().sorted(comparator)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old, nev) -> nev, LinkedHashMap::new));
}
@NotNull
@Deprecated
public static List<String> getEnums(@NotNull Class<? extends Enum<?>> clazz) {
return Enums.getNames(clazz);
//return new ArrayList<>(Stream.of(clazz.getEnumConstants()).map(Object::toString).toList());
}
// @NotNull
// @Deprecated
// public static String getEnums(@NotNull Class<? extends Enum<?>> clazz, @NotNull String delimiter) {
// return StringUtil.inlineEnum(clazz, delimiter);
// }
@NotNull
public static <T extends Enum<T>> T next(@NotNull Enum<T> numeration) {
return shifted(numeration, 1);
}
@NotNull
public static <T extends Enum<T>> T next(@NotNull Enum<T> numeration, @NotNull Predicate<T> predicate) {
return shifted(numeration, 1, predicate);
}
@NotNull
public static <T extends Enum<T>> T previous(@NotNull Enum<T> numeration) {
return shifted(numeration, -1);
}
@NotNull
public static <T extends Enum<T>> T previous(@NotNull Enum<T> numeration, @NotNull Predicate<T> predicate) {
return shifted(numeration, -1, predicate);
}
@NotNull
public static <T extends Enum<T>> T shifted(@NotNull Enum<T> numeration, int shift) {
return shifted(numeration, shift, null);
}
@NotNull
private static <T extends Enum<T>> T shifted(@NotNull Enum<T> numeration, int shift, @Nullable Predicate<T> predicate) {
T[] values = numeration.getDeclaringClass().getEnumConstants();
return shifted(values, numeration, shift, predicate);
}
@NotNull
private static <T extends Enum<T>> T shifted(T[] values, @NotNull Enum<T> origin, int shift, @Nullable Predicate<T> predicate) {
if (predicate != null) {
T source = origin.getDeclaringClass().cast(origin);
List<T> filtered = new ArrayList<>(Arrays.asList(values));
filtered.removeIf(num -> !predicate.test(num) && num != source);
int currentIndex = filtered.indexOf(source);
if (currentIndex < 0 | filtered.isEmpty()) return source;
return shifted(filtered, currentIndex, shift);
}
return shifted(values, origin.ordinal(), shift);
}
@NotNull
public static <T> T shifted(T[] values, int currentIndex, int shift) {
int index = currentIndex + shift;
return values[index >= values.length || index < 0 ? 0 : index];
}
@NotNull
public static <T> T shifted(@NotNull List<T> values, int currentIndex, int shift) {
int index = currentIndex + shift;
if (index < 0) return values.getLast();
return values.get(index >= values.size() ? 0 : index);
}
}