v2.6.3, update 2

This commit is contained in:
nulli0n committed 2024-07-22 17:06:54 +05:00
1 parent 137f656c7a
commit 5c4477847d
12 files changed
+48 -13

No files matched your search

@@ -8,6 +8,7 @@ import su.nightexpress.nightcore.util.NumberUtil;
import java.util.function.Function; import java.util.function.Function;
@Deprecated
public class CommandFlag<T> { public class CommandFlag<T> {
public static final char PREFIX = '-'; public static final char PREFIX = '-';
@@ -7,6 +7,7 @@ import su.nightexpress.nightcore.util.NumberUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Deprecated
public class CommandResult { public class CommandResult {
private final String label; private final String label;
@@ -12,6 +12,7 @@ import su.nightexpress.nightcore.util.placeholder.Placeholder;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@Deprecated
public interface NightCommand extends Placeholder { public interface NightCommand extends Placeholder {
@NotNull List<String> getTab(@NotNull Player player, int arg, @NotNull String[] args); @NotNull List<String> getTab(@NotNull Player player, int arg, @NotNull String[] args);
@@ -5,6 +5,7 @@ import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@Deprecated
public interface NightPluginCommand extends NightCommand, TabExecutor { public interface NightPluginCommand extends NightCommand, TabExecutor {
@Nullable NightCommand getDefaultCommand(); @Nullable NightCommand getDefaultCommand();
@@ -13,6 +13,7 @@ import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@Deprecated
public class HelpSubCommand extends AbstractCommand<NightCorePlugin> { public class HelpSubCommand extends AbstractCommand<NightCorePlugin> {
public HelpSubCommand(@NotNull NightCorePlugin plugin) { public HelpSubCommand(@NotNull NightCorePlugin plugin) {
@@ -8,6 +8,7 @@ import su.nightexpress.nightcore.command.CommandResult;
import su.nightexpress.nightcore.command.impl.AbstractCommand; import su.nightexpress.nightcore.command.impl.AbstractCommand;
import su.nightexpress.nightcore.core.CoreLang; import su.nightexpress.nightcore.core.CoreLang;
@Deprecated
public class ReloadSubCommand extends AbstractCommand<NightCorePlugin> { public class ReloadSubCommand extends AbstractCommand<NightCorePlugin> {
public ReloadSubCommand(@NotNull NightCorePlugin plugin, @NotNull Permission permission) { public ReloadSubCommand(@NotNull NightCorePlugin plugin, @NotNull Permission permission) {
@@ -17,6 +17,7 @@ import su.nightexpress.nightcore.util.placeholder.PlaceholderMap;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
@Deprecated
public abstract class AbstractCommand<P extends NightCorePlugin> implements NightCommand { public abstract class AbstractCommand<P extends NightCorePlugin> implements NightCommand {
protected final P plugin; protected final P plugin;
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.NightCorePlugin; import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.command.CommandResult; import su.nightexpress.nightcore.command.CommandResult;
@Deprecated
public class BaseCommand extends PluginCommand<NightCorePlugin> { public class BaseCommand extends PluginCommand<NightCorePlugin> {
public BaseCommand(@NotNull NightCorePlugin plugin) { public BaseCommand(@NotNull NightCorePlugin plugin) {
@@ -16,6 +16,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@Deprecated
public abstract class PluginCommand<P extends NightCorePlugin> extends AbstractCommand<P> implements NightPluginCommand { public abstract class PluginCommand<P extends NightCorePlugin> extends AbstractCommand<P> implements NightPluginCommand {
private Command backend; private Command backend;
@@ -11,6 +11,7 @@ import su.nightexpress.nightcore.util.wrapper.UniSound;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ConfigValue<T> { public class ConfigValue<T> {
@@ -22,6 +23,7 @@ public class ConfigValue<T> {
private final Writer<T> writer; private final Writer<T> writer;
private T value; private T value;
private UnaryOperator<T> onRead;
public ConfigValue(@NotNull String path, public ConfigValue(@NotNull String path,
@NotNull Reader<T> reader, @NotNull Reader<T> reader,
@@ -246,22 +248,31 @@ public class ConfigValue<T> {
} }
@NotNull @NotNull
public T read(@NotNull FileConfig cfg) { public ConfigValue<T> onRead(@NotNull UnaryOperator<T> onRead) {
if (!cfg.contains(this.getPath())) { this.onRead = onRead;
this.write(cfg); return this;
}
@NotNull
public T read(@NotNull FileConfig config) {
if (!config.contains(this.getPath())) {
this.write(config);
} }
if (this.getDescription().length > 0 && !this.getDescription()[0].isEmpty()) { if (this.getDescription().length > 0 && !this.getDescription()[0].isEmpty()) {
cfg.setComments(this.getPath(), this.getDescription()); config.setComments(this.getPath(), this.getDescription());
} }
return (this.value = this.reader.read(cfg, this.getPath(), this.getDefaultValue()));
UnaryOperator<T> operator = this.onRead == null ? value -> value : this.onRead;
return (this.value = operator.apply(this.reader.read(config, this.getPath(), this.getDefaultValue())));
} }
public void write(@NotNull FileConfig cfg) { public void write(@NotNull FileConfig config) {
this.getWriter().write(cfg, this.getPath(), this.get()); this.getWriter().write(config, this.getPath(), this.get());
} }
public boolean remove(@NotNull FileConfig cfg) { public boolean remove(@NotNull FileConfig config) {
return cfg.remove(this.getPath()); return config.remove(this.getPath());
} }
@NotNull @NotNull
@@ -300,11 +311,11 @@ public class ConfigValue<T> {
public interface Reader<T> { public interface Reader<T> {
@NotNull T read(@NotNull FileConfig cfg, @NotNull String path, @NotNull T def); @NotNull T read(@NotNull FileConfig config, @NotNull String path, @NotNull T def);
} }
public interface Writer<T> { public interface Writer<T> {
void write(@NotNull FileConfig cfg, @NotNull String path, @NotNull T obj); void write(@NotNull FileConfig config, @NotNull String path, @NotNull T obj);
} }
} }
@@ -13,9 +13,9 @@ import java.util.stream.Collectors;
public class Colorizer { public class Colorizer {
public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})"); @Deprecated 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() + ">"); @Deprecated public static final Pattern PATTERN_GRADIENT = Pattern.compile("<gradient:" + PATTERN_HEX.pattern() + ">(.*?)</gradient:" + PATTERN_HEX.pattern() + ">");
@NotNull @NotNull
public static String apply(@NotNull String str) { public static String apply(@NotNull String str) {
@@ -44,6 +44,7 @@ public class Colorizer {
} }
@NotNull @NotNull
@Deprecated
public static String hex(@NotNull String str) { public static String hex(@NotNull String str) {
TimedMatcher timedMatcher = TimedMatcher.create(PATTERN_HEX, str); TimedMatcher timedMatcher = TimedMatcher.create(PATTERN_HEX, str);
//Matcher matcher = PATTERN_HEX.matcher(str); //Matcher matcher = PATTERN_HEX.matcher(str);
@@ -60,6 +61,7 @@ public class Colorizer {
return timedMatcher.getMatcher().appendTail(buffer).toString(); return timedMatcher.getMatcher().appendTail(buffer).toString();
} }
@Deprecated
private static ChatColor[] createGradient(@NotNull java.awt.Color start, @NotNull java.awt.Color end, int length) { private static ChatColor[] createGradient(@NotNull java.awt.Color start, @NotNull java.awt.Color end, int length) {
ChatColor[] colors = new ChatColor[length]; ChatColor[] colors = new ChatColor[length];
for (int index = 0; index < length; index++) { for (int index = 0; index < length; index++) {
@@ -76,6 +78,7 @@ public class Colorizer {
} }
@NotNull @NotNull
@Deprecated
public static String gradient(@NotNull String string) { public static String gradient(@NotNull String string) {
TimedMatcher timedMatcher = TimedMatcher.create(PATTERN_GRADIENT, string); TimedMatcher timedMatcher = TimedMatcher.create(PATTERN_GRADIENT, string);
//Matcher matcher = PATTERN_GRADIENT.matcher(string); //Matcher matcher = PATTERN_GRADIENT.matcher(string);
@@ -126,6 +129,7 @@ public class Colorizer {
} }
@NotNull @NotNull
@Deprecated
public static String plainHex(@NotNull String str) { public static String plainHex(@NotNull String str) {
StringBuilder builder = new StringBuilder(str); StringBuilder builder = new StringBuilder(str);
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -63,6 +64,16 @@ public class Lists {
return indexOf(array, valueToFind) != -1; 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 @NotNull
public static <T> List<List<T>> split(@NotNull List<T> list, int targetSize) { public static <T> List<List<T>> split(@NotNull List<T> list, int targetSize) {
List<List<T>> lists = new ArrayList<>(); List<List<T>> lists = new ArrayList<>();