mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-01 14:38:47 +00:00
v2.7.4
- Migrate plugin name, commands, language, database and userdata settings to the engine.yml config file. - Added LangUIButton class with better localization of GUI editor buttons. - Make NightSound class compact for config files. - Added NightSound support for the `sound` tag of lang messages. This allows to use volume and pitch values and custom RP sounds. - Added 'Locale' config option for Number Formatter. - Added 'TimeZone' config option. - New TimeFormats class with different time format options. - Fixed NightTask#stop never worked properly. - Fixed possible CommandMap errors.
This commit is contained in:
1 parent
68a5b068e2
commit
b3136c3bd4
46 files changed
+1063
-344
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>su.nightexpress.nightcore</groupId>
|
||||
<artifactId>nightcore</artifactId>
|
||||
<version>2.7.3.4</version>
|
||||
<version>2.7.4</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
@@ -97,7 +97,7 @@
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.46.1.3</version>
|
||||
<version>3.47.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import su.nightexpress.nightcore.core.command.CoreCommands;
|
||||
import su.nightexpress.nightcore.integration.VaultHook;
|
||||
import su.nightexpress.nightcore.language.LangAssets;
|
||||
import su.nightexpress.nightcore.util.Plugins;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;
|
||||
import su.nightexpress.nightcore.util.text.tag.Tags;
|
||||
@@ -46,6 +47,7 @@ public class NightCore extends NightPlugin implements ImprovedCommands {
|
||||
LangAssets.load(this);
|
||||
this.loadIntegrations();
|
||||
this.loadCommands();
|
||||
this.info("Time zone set as " + TimeUtil.getTimeZone().getID());
|
||||
|
||||
this.coreManager.setup();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package su.nightexpress.nightcore;
|
||||
|
||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class NightCoreBootstrap implements PluginBootstrap {
|
||||
|
||||
@Override
|
||||
public void bootstrap(@NotNull BootstrapContext context) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package su.nightexpress.nightcore;
|
||||
|
||||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
|
||||
import io.papermc.paper.plugin.loader.PluginLoader;
|
||||
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class NightCoreLoader implements PluginLoader {
|
||||
|
||||
@Override
|
||||
public void classloader(PluginClasspathBuilder classpathBuilder) {
|
||||
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||
|
||||
resolver.addRepository(new RemoteRepository.Builder("maven", "default", "https://repo1.maven.org/maven2/").build());
|
||||
|
||||
resolver.addDependency(new Dependency(new DefaultArtifact("com.zaxxer:HikariCP:6.0.0"), null));
|
||||
resolver.addDependency(new Dependency(new DefaultArtifact("it.unimi.dsi:fastutil-core:8.5.13"), null));
|
||||
|
||||
classpathBuilder.addLibrary(resolver);
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,18 @@ import java.util.List;
|
||||
|
||||
public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin {
|
||||
|
||||
public static final String CONFIG_FILE = "config.yml";
|
||||
public static final String ENGINE_FILE = "engine.yml";
|
||||
|
||||
protected List<Runnable> postLoaders;
|
||||
|
||||
protected LangManager langManager;
|
||||
protected CommandManager commandManager;
|
||||
|
||||
protected FileConfig engineConf;
|
||||
protected FileConfig config;
|
||||
protected PluginDetails details;
|
||||
|
||||
// public final boolean isEngine() {
|
||||
// return this == Plugins.getCore();
|
||||
// }
|
||||
|
||||
private boolean isCore() {
|
||||
return this instanceof NightCore;
|
||||
}
|
||||
@@ -73,6 +73,11 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FileConfig getEngineConfig() {
|
||||
return this.engineConf;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final FileConfig getLang() {
|
||||
return this.langManager.getConfig();
|
||||
@@ -81,7 +86,10 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
@NotNull
|
||||
@Override
|
||||
public PluginDetails getDetails() {
|
||||
return this.details == null ? this.getDefaultDetails() : this.details;
|
||||
if (this.details == null) throw new IllegalStateException("Plugin is not yet initialized!");
|
||||
|
||||
return this.details;
|
||||
//return this.details == null ? this.getDefaultDetails() : this.details;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -96,8 +104,18 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
}
|
||||
|
||||
protected void setupConfig() {
|
||||
this.config = FileConfig.loadOrExtract(this, "config.yml");
|
||||
this.details = PluginDetails.read(this);
|
||||
this.engineConf = FileConfig.loadOrExtract(this, ENGINE_FILE);
|
||||
this.config = FileConfig.loadOrExtract(this, CONFIG_FILE);
|
||||
|
||||
// ---------- MIGRATION - START ----------
|
||||
if (this.config.contains("Plugin")) {
|
||||
PluginDetails details = PluginDetails.read(this, this.config, this.getDefaultDetails());
|
||||
details.write(this.engineConf, "");
|
||||
this.config.remove("Plugin");
|
||||
}
|
||||
// ---------- MIGRATION - END ----------
|
||||
|
||||
this.details = PluginDetails.read(this, this.engineConf, this.getDefaultDetails());
|
||||
|
||||
if (this.details.getConfigClass() != null) {
|
||||
this.config.initializeOptions(this.details.getConfigClass());
|
||||
@@ -137,8 +155,9 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
|
||||
this.postLoad(); // Load some stuff that needs to be injected after the rest managers.
|
||||
|
||||
this.getConfig().saveChanges();
|
||||
this.config.saveChanges();
|
||||
this.getLang().saveChanges();
|
||||
this.engineConf.saveChanges();
|
||||
}
|
||||
|
||||
protected void unloadManagers() {
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
import su.nightexpress.nightcore.util.TriFunction;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightSound;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightSound;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniFormatter;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniParticle;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniSound;
|
||||
@@ -20,14 +20,14 @@ public class ConfigValue<T> {
|
||||
private final String path;
|
||||
private final T defaultValue;
|
||||
private final String[] description;
|
||||
private final Reader<T> reader;
|
||||
private final Loader<T> reader;
|
||||
private final Writer<T> writer;
|
||||
|
||||
private T value;
|
||||
private UnaryOperator<T> onRead;
|
||||
|
||||
public ConfigValue(@NotNull String path,
|
||||
@NotNull Reader<T> reader,
|
||||
@NotNull ConfigValue.Loader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
@NotNull T defaultValue,
|
||||
@Nullable String... description) {
|
||||
@@ -38,9 +38,18 @@ public class ConfigValue<T> {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigValue(@NotNull String path,
|
||||
@NotNull ConfigValue.Reader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
@NotNull T defaultValue,
|
||||
@Nullable String... description) {
|
||||
this(path, reader.update(), writer, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> ConfigValue<T> create(@NotNull String path,
|
||||
@NotNull Reader<T> reader,
|
||||
@NotNull ConfigValue.Loader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
@NotNull T defaultValue,
|
||||
@Nullable String... description) {
|
||||
@@ -49,116 +58,149 @@ public class ConfigValue<T> {
|
||||
|
||||
@NotNull
|
||||
public static <T> ConfigValue<T> create(@NotNull String path,
|
||||
@NotNull Reader<T> reader,
|
||||
@NotNull ConfigValue.Loader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
|
||||
@NotNull Supplier<T> defaultValue,
|
||||
@Nullable String... description) {
|
||||
return create(path, reader, writer, defaultValue.get(), description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
|
||||
@Deprecated
|
||||
private static <T> ConfigValue<T> create(@NotNull String path,
|
||||
@NotNull ConfigValue.Reader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
@NotNull T defaultValue,
|
||||
@Nullable String... description) {
|
||||
return new ConfigValue<>(path, reader.update(), writer, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static <T> ConfigValue<T> create(@NotNull String path,
|
||||
@NotNull ConfigValue.Reader<T> reader,
|
||||
@NotNull Writer<T> writer,
|
||||
@NotNull Supplier<T> defaultValue,
|
||||
@Nullable String... description) {
|
||||
return create(path, reader, writer, defaultValue.get(), description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull ConfigValue.Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
|
||||
return create(path, reader.update(), FileConfig::set, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull ConfigValue.Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
|
||||
return create(path, reader.update(), FileConfig::set, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull ConfigValue.Loader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
|
||||
return create(path, reader, FileConfig::set, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
|
||||
public static <T> ConfigValue<T> create(@NotNull String path, @NotNull ConfigValue.Loader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
|
||||
return create(path, reader, FileConfig::set, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<Boolean> create(@NotNull String path, boolean defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getBoolean, defaultValue, description);
|
||||
return create(path, (Loader<Boolean>) FileConfig::getBoolean, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<Integer> create(@NotNull String path, int defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getInt, defaultValue, description);
|
||||
return create(path, (Loader<Integer>) FileConfig::getInt, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<int[]> create(@NotNull String path, int[] defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getIntArray, FileConfig::setIntArray, defaultValue, description);
|
||||
return create(path, (Loader<int[]>) FileConfig::getIntArray, FileConfig::setIntArray, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<Double> create(@NotNull String path, double defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getDouble, defaultValue, description);
|
||||
return create(path, (Loader<Double>) FileConfig::getDouble, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<Long> create(@NotNull String path, long defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getLong, defaultValue, description);
|
||||
return create(path, (Loader<Long>) FileConfig::getLong, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<String> create(@NotNull String path, @NotNull String defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getString, defaultValue, description);
|
||||
return create(path, (Loader<String>) FileConfig::getString, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<String[]> create(@NotNull String path, @NotNull String[] defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getStringArray, FileConfig::setStringArray, defaultValue, description);
|
||||
return create(path, (Loader<String[]>) FileConfig::getStringArray, FileConfig::setStringArray, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<List<String>> create(@NotNull String path, @NotNull List<String> defaultValue, @Nullable String... description) {
|
||||
return create(path, (cfg, path1, def) -> cfg.getStringList(path1), defaultValue, description);
|
||||
return create(path, FileConfig::getStringList, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<Set<String>> create(@NotNull String path, @NotNull Set<String> defaultValue, @Nullable String... description) {
|
||||
return create(path, (cfg, path1, def) -> cfg.getStringSet(path1), defaultValue, description);
|
||||
return create(path, FileConfig::getStringSet, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static ConfigValue<ItemStack> create(@NotNull String path, @NotNull ItemStack defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getItem, FileConfig::setItem, defaultValue, description);
|
||||
return create(path, (Loader<ItemStack>) FileConfig::getItem, FileConfig::setItem, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<NightItem> create(@NotNull String path, @NotNull NightItem defaultValue, @Nullable String... description) {
|
||||
return create(path, FileConfig::getCosmeticItem, FileConfig::set, defaultValue, description);
|
||||
return create(path, (Loader<NightItem>) FileConfig::getCosmeticItem, FileConfig::set, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static ConfigValue<UniSound> create(@NotNull String path, @NotNull UniSound defaultValue, @Nullable String... description) {
|
||||
Reader<UniSound> reader = (cfg, path1, def) -> UniSound.read(cfg, path1);
|
||||
Writer<UniSound> writer = (cfg, path1, obj) -> obj.write(cfg, path1);
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
return create(path, UniSound::read, writer, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<NightSound> create(@NotNull String path, @NotNull NightSound defaultValue, @Nullable String... description) {
|
||||
Reader<NightSound> reader = (cfg, readPath, def) -> NightSound.read(cfg, readPath);
|
||||
Writer<NightSound> writer = (cfg, writePath, sound) -> sound.write(cfg, writePath);
|
||||
// Reader<NightSound> reader = NightSound::read;
|
||||
// Writer<NightSound> writer = (cfg, writePath, sound) -> sound.write(cfg, writePath);
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
return create(path, FileConfig::getSound, FileConfig::setSound, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigValue<UniParticle> create(@NotNull String path, @NotNull UniParticle defaultValue, @Nullable String... description) {
|
||||
Reader<UniParticle> reader = (cfg, path1, def) -> UniParticle.read(cfg, path1);
|
||||
Loader<UniParticle> reader = UniParticle::read;
|
||||
Writer<UniParticle> writer = (cfg, path1, obj) -> obj.write(cfg, path1);
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static ConfigValue<UniFormatter> create(@NotNull String path, @NotNull UniFormatter defaultValue, @Nullable String... description) {
|
||||
Reader<UniFormatter> reader = (cfg, path1, def) -> UniFormatter.read(cfg, path1);
|
||||
Writer<UniFormatter> writer = (cfg, path1, obj) -> obj.write(cfg, path1);
|
||||
// Reader<UniFormatter> reader = UniFormatter::read;
|
||||
// Writer<UniFormatter> writer = (cfg, path1, obj) -> obj.write(cfg, path1);
|
||||
//
|
||||
// return create(path, reader, writer, defaultValue, description);
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
return create(path, UniFormatter::read, defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <E extends Enum<E>> ConfigValue<E> create(@NotNull String path, @NotNull Class<E> clazz, @NotNull E defaultValue, @Nullable String... description) {
|
||||
Reader<E> reader = (cfg, path1, def) -> cfg.getEnum(path1, clazz, def);
|
||||
Loader<E> reader = (cfg, path1) -> cfg.getEnum(path1, clazz);
|
||||
Writer<E> writer = (cfg, path1, obj) -> cfg.set(path1, obj.name());
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
@@ -180,7 +222,7 @@ public class ConfigValue<T> {
|
||||
@NotNull Set<V> defaultValue,
|
||||
@Nullable String... description) {
|
||||
|
||||
Reader<Set<V>> reader = (cfg, path1, def) -> cfg.getStringSet(path1).stream().map(valFun).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));
|
||||
Loader<Set<V>> reader = (cfg, path1) -> cfg.getStringSet(path1).stream().map(valFun).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
}
|
||||
@@ -235,7 +277,7 @@ public class ConfigValue<T> {
|
||||
@NotNull Supplier<M> mapSupplier,
|
||||
@NotNull Writer<M> writer,
|
||||
@NotNull M defaultValue, @Nullable String... description) {
|
||||
Reader<M> reader = (cfg, path1, def) -> {
|
||||
Loader<M> reader = (cfg, path1) -> {
|
||||
M map = mapSupplier.get();
|
||||
for (String id : cfg.getSection(path1)) {
|
||||
K key = keyFun.apply(id);
|
||||
@@ -254,17 +296,17 @@ public class ConfigValue<T> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <K, V extends Writeable> ConfigValue<Map<K, V>> forMap(@NotNull String path,
|
||||
public static <K, V> ConfigValue<Map<K, V>> forMap(@NotNull String path,
|
||||
@NotNull Function<String, K> keyReadFun,
|
||||
@NotNull Function<K, String> keyWriteFun,
|
||||
@NotNull ReadFunction<V> valReadFun,
|
||||
@NotNull Consumer<Map<K, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
Reader<Map<K, V>> reader = (cfg, readPath, def) -> {
|
||||
Loader<Map<K, V>> reader = (config, readPath) -> {
|
||||
var map = new HashMap<K, V>();
|
||||
for (String keyRaw : cfg.getSection(readPath)) {
|
||||
for (String keyRaw : config.getSection(readPath)) {
|
||||
K key = keyReadFun.apply(keyRaw);
|
||||
V val = valReadFun.read(cfg, readPath + "." + keyRaw, keyRaw);
|
||||
V val = valReadFun.read(config, readPath + "." + keyRaw, keyRaw);
|
||||
if (key == null || val == null) continue;
|
||||
|
||||
map.put(key, val);
|
||||
@@ -272,10 +314,11 @@ public class ConfigValue<T> {
|
||||
return map;
|
||||
};
|
||||
|
||||
Writer<Map<K, V>> writer = (cfg, writePath, map) -> {
|
||||
Writer<Map<K, V>> writer = (config, writePath, map) -> {
|
||||
map.forEach((key, value) -> {
|
||||
String keyRaw = keyWriteFun.apply(key);
|
||||
value.write(cfg, writePath + "." + keyRaw);
|
||||
config.set(writePath + "." + keyRaw, value);
|
||||
//value.write(config, writePath + "." + keyRaw);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -330,10 +373,20 @@ public class ConfigValue<T> {
|
||||
// @NotNull Consumer<HashMap<K, V>> defaultValue,
|
||||
// @Nullable String... description) {
|
||||
// return forMap(path, keyReadFun, keyWriteFun, valReadFun, HashMap::new, defaultValue, description);
|
||||
// }
|
||||
|
||||
// @NotNull
|
||||
// public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
// @NotNull Loader<V> valReadFun,
|
||||
// @NotNull Consumer<Map<String, V>> defaultValue,
|
||||
// @Nullable String... description) {
|
||||
// //return forMap(path, String::toLowerCase, key -> key, valReadFun, defaultValue, description);
|
||||
//
|
||||
// return forMapById(path, (cfg, path2, id) -> valReadFun.read(cfg, path2 + "." + id), defaultValue, description);
|
||||
// }
|
||||
|
||||
@NotNull
|
||||
public static <V extends Writeable> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
@NotNull BiFunction<FileConfig, String, V> valReadFun,
|
||||
@NotNull Consumer<Map<String, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
@@ -342,7 +395,7 @@ public class ConfigValue<T> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <V extends Writeable> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
@NotNull ReadFunction<V> valReadFun,
|
||||
@NotNull Consumer<Map<String, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
@@ -406,16 +459,23 @@ public class ConfigValue<T> {
|
||||
|
||||
@NotNull
|
||||
public T read(@NotNull FileConfig config) {
|
||||
if (!config.contains(this.getPath())) {
|
||||
if (!config.contains(this.path)) {
|
||||
this.write(config);
|
||||
}
|
||||
if (this.getDescription().length > 0 && !this.getDescription()[0].isEmpty()) {
|
||||
config.setComments(this.getPath(), this.getDescription());
|
||||
if (this.description.length > 0 && !this.description[0].isEmpty()) {
|
||||
config.setComments(this.path, this.description);
|
||||
}
|
||||
|
||||
UnaryOperator<T> operator = this.onRead == null ? value -> value : this.onRead;
|
||||
UnaryOperator<T> postRead = this.onRead == null ? value -> value : this.onRead;
|
||||
|
||||
return (this.value = operator.apply(this.reader.read(config, this.getPath(), this.getDefaultValue())));
|
||||
T read = this.reader.read(config, this.path);
|
||||
if (read == null) {
|
||||
read = this.defaultValue;
|
||||
}
|
||||
|
||||
return (this.value = postRead.apply(read));
|
||||
|
||||
//return (this.value = postRead.apply(this.reader.read(config, this.path, this.defaultValue)));
|
||||
}
|
||||
|
||||
public void write(@NotNull FileConfig config) {
|
||||
@@ -428,7 +488,7 @@ public class ConfigValue<T> {
|
||||
|
||||
@NotNull
|
||||
public T get() {
|
||||
return this.value == null ? this.getDefaultValue() : this.value;
|
||||
return this.value == null ? this.defaultValue : this.value;
|
||||
}
|
||||
|
||||
public void set(@NotNull T value) {
|
||||
@@ -451,7 +511,7 @@ public class ConfigValue<T> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Reader<T> getReader() {
|
||||
public ConfigValue.Loader<T> getReader() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
@@ -460,9 +520,19 @@ public class ConfigValue<T> {
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public interface Reader<T> {
|
||||
|
||||
@NotNull T read(@NotNull FileConfig config, @NotNull String path, @NotNull T def);
|
||||
@NotNull T read(@NotNull FileConfig config, @NotNull String path, T def);
|
||||
|
||||
default Loader<T> update() {
|
||||
return (cfg, path) -> read(cfg, path, null);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Loader<T> {
|
||||
|
||||
@Nullable T read(@NotNull FileConfig config, @NotNull String path);
|
||||
}
|
||||
|
||||
public interface Writer<T> {
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
import su.nightexpress.nightcore.util.*;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightSound;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
|
||||
@@ -251,6 +252,11 @@ public class FileConfig extends YamlConfiguration {
|
||||
this.set(path, String.join(",", IntStream.of(arr).boxed().map(String::valueOf).toList()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[] getStringArray(@NotNull String path) {
|
||||
return this.getStringArray(path, new String[0]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[] getStringArray(@NotNull String path, @NotNull String[] def) {
|
||||
String str = this.getString(path);
|
||||
@@ -320,6 +326,15 @@ public class FileConfig extends YamlConfiguration {
|
||||
return NightItem.read(this, path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightSound getSound(@NotNull String path) {
|
||||
return NightSound.deserialize(this.getString(path, "null"));
|
||||
}
|
||||
|
||||
public void setSound(@NotNull String path, @NotNull NightSound sound) {
|
||||
this.set(path, sound.serialize());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public ItemStack getItem(@NotNull String path, @Nullable ItemStack def) {
|
||||
|
||||
@@ -2,15 +2,15 @@ package su.nightexpress.nightcore.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
import su.nightexpress.nightcore.NightDataPlugin;
|
||||
import su.nightexpress.nightcore.NightPlugin;
|
||||
import su.nightexpress.nightcore.database.DatabaseConfig;
|
||||
import su.nightexpress.nightcore.language.LangManager;
|
||||
import su.nightexpress.nightcore.util.text.tag.Tags;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class PluginDetails {
|
||||
public class PluginDetails implements Writeable {
|
||||
|
||||
private final String name;
|
||||
private final String prefix;
|
||||
@@ -45,9 +45,9 @@ public class PluginDetails {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PluginDetails read(@NotNull NightCorePlugin plugin) {
|
||||
FileConfig config = plugin.getConfig();
|
||||
PluginDetails defaults = plugin.getDetails();
|
||||
public static PluginDetails read(@NotNull NightPlugin plugin, @NotNull FileConfig config, @NotNull PluginDetails defaults) {
|
||||
//FileConfig config = plugin.getConfig();
|
||||
//PluginDetails defaults = plugin.getDetails();
|
||||
|
||||
String pluginName = ConfigValue.create("Plugin.Name", defaults.getName(),
|
||||
"Localized plugin name. It's used in messages and with internal placeholders.")
|
||||
@@ -82,6 +82,14 @@ public class PluginDetails {
|
||||
.setPermissionsClass(defaults.getPermissionsClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Plugin.Name", this.name);
|
||||
config.set(path + ".Plugin.Prefix", this.prefix);
|
||||
config.setStringArray(path + ".Plugin.Command_Aliases", this.commandAliases);
|
||||
config.set(path + ".Plugin.Language", this.language);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
@@ -3,11 +3,13 @@ package su.nightexpress.nightcore.core;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.util.Placeholders;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
import su.nightexpress.nightcore.util.number.NumberShortcut;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniFormatter;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class CoreConfig {
|
||||
|
||||
@@ -18,40 +20,22 @@ public class CoreConfig {
|
||||
"IMPORTANT NOTE: You need to use this setting only once! Enable it, reboot the server and re-save all configurations that stores compressed item data: shops, crates, etc."
|
||||
);
|
||||
|
||||
@Deprecated
|
||||
public static final ConfigValue<Boolean> MODERN_TEXT_PRECOMPILE_LANG = ConfigValue.create("ModernTextFormation.Precompile_Language",
|
||||
true,
|
||||
"When enabled, parses (deserializes) language messages to Spigot TextComponent(s) on plugin load.",
|
||||
"When disabled, parses (deserializes) language texts to Spigot TextComponent(s) in runtime when sending it to player.",
|
||||
"Enabling this setting is good for performance, however messages with placeholders will be recompiled in runtime anyway.",
|
||||
"(Side Note) Unlike NexEngine, it does not uses regex anymore, which makes deserialization significantly faster and accurate.",
|
||||
"[Default is true]"
|
||||
);
|
||||
|
||||
public static final ConfigValue<Long> MENU_CLICK_COOLDOWN = ConfigValue.create("Menu.Click_Cooldown",
|
||||
150L,
|
||||
"Sets cooldown (in milliseconds) for player clicks in GUIs.",
|
||||
"[Default is 150ms]"
|
||||
);
|
||||
|
||||
// @Deprecated
|
||||
// public static final ConfigValue<Boolean> USER_DEBUG_ENABLED = ConfigValue.create("UserData.Debug",
|
||||
// false,
|
||||
// "Enables debug messages for user data management.",
|
||||
// "[Default is false]");
|
||||
|
||||
@Deprecated
|
||||
public static final ConfigValue<Integer> USER_CACHE_LIFETIME = ConfigValue.create("UserData.Cache.LifeTime",
|
||||
300,
|
||||
"[ OUTDATED, MOVED IN PER-PLUGIN config.yml ]"
|
||||
"[ OUTDATED, MOVED IN PER-PLUGIN engine.yml ]"
|
||||
);
|
||||
|
||||
// @Deprecated
|
||||
// public static final ConfigValue<Boolean> USER_CACHE_NAME_AND_UUID = ConfigValue.create("UserData.Cache.Names_And_UUIDs",
|
||||
// true,
|
||||
// "Sets whether or not plugin will cache player names and UUIDs.",
|
||||
// "This will improve database performance when checking if user exists, but will use more memory to store UUIDs and names.",
|
||||
// "[Default is true]");
|
||||
public static final ConfigValue<String> TIME_ZONE = ConfigValue.create("Time.TimeZone",
|
||||
TimeZone.getDefault().getID(),
|
||||
"Sets timezone for plugins to handle local dates and times properly."
|
||||
).whenRead(TimeUtil::setTimeZone);
|
||||
|
||||
public static final ConfigValue<Boolean> LEGACY_COLOR_SUPPORT = ConfigValue.create("Engine.Legacy_Color_Support",
|
||||
true,
|
||||
@@ -61,14 +45,8 @@ public class CoreConfig {
|
||||
"You should migrate to new text format as soon as possible: " + Placeholders.URL_WIKI_TEXT
|
||||
);
|
||||
|
||||
// public static final ConfigValue<Boolean> RESPECT_PLAYER_DISPLAYNAME = ConfigValue.create("Engine.Respect_Player_DisplayName",
|
||||
// false,
|
||||
// "Sets whether or not 'Player#getDisplayName' can be used to find & get players in addition to regular 'Player#getName'.",
|
||||
// "This is useful if you want to use custom player nicknames in commands.",
|
||||
// "(Works only for nightcore based plugins.)",
|
||||
// "[Default is false]");
|
||||
|
||||
public static final ConfigValue<UniFormatter> NUMBER_FORMAT = ConfigValue.create("Number.Format",
|
||||
UniFormatter::read,
|
||||
UniFormatter.of("#,###.###", RoundingMode.HALF_EVEN),
|
||||
"Control over how numerical data is formatted and rounded.",
|
||||
"Allowed modes: " + StringUtil.inlineEnum(RoundingMode.class, ", "),
|
||||
|
||||
@@ -4,16 +4,25 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.dialog.Dialog;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.language.entry.LangString;
|
||||
import su.nightexpress.nightcore.language.entry.LangText;
|
||||
import su.nightexpress.nightcore.language.entry.*;
|
||||
import su.nightexpress.nightcore.ui.dialog.DialogManager;
|
||||
import su.nightexpress.nightcore.ui.menu.click.ClickKey;
|
||||
|
||||
import static su.nightexpress.nightcore.util.Placeholders.*;
|
||||
import static su.nightexpress.nightcore.util.text.tag.Tags.*;
|
||||
|
||||
public class CoreLang {
|
||||
|
||||
public static final LangEnum<ClickKey> CLICK_KEY = LangEnum.of("ClickKey", ClickKey.class, map -> {
|
||||
map.put(ClickKey.LEFT, "L-Click");
|
||||
map.put(ClickKey.RIGHT, "R-Click");
|
||||
map.put(ClickKey.SHIFT_LEFT, "Shift + L-Click");
|
||||
map.put(ClickKey.SHIFT_RIGHT, "Shift + R-Click");
|
||||
map.put(ClickKey.DROP_KEY, "Drop [Q]");
|
||||
map.put(ClickKey.SWAP_KEY, "Swap [F]");
|
||||
map.put(ClickKey.DRAG_N_DROP, "Drag & Drop");
|
||||
});
|
||||
|
||||
public static final LangString COMMAND_ARGUMENT_FORMAT_REQUIRED = LangString.of("Command.Argument.Type.Required",
|
||||
LIGHT_RED.enclose("<" + GENERIC_NAME + ">"));
|
||||
|
||||
@@ -179,11 +188,42 @@ public class CoreLang {
|
||||
@Deprecated
|
||||
public static final LangString EDITOR_INPUT_ERROR_GENERIC = LangString.of("Editor.Input.Error.Generic", GRAY.enclose("Invalid value!"));
|
||||
|
||||
|
||||
public static final LangString EDITOR_BUTTON_NAME = LangString.of("Editor.Button.Name",
|
||||
LIGHT_YELLOW.enclose(BOLD.enclose(GENERIC_NAME))
|
||||
);
|
||||
|
||||
public static final LangString EDITOR_BUTTON_DESCRIPTION = LangString.of("Editor.Button.Description",
|
||||
GRAY.enclose(GENERIC_ENTRY)
|
||||
);
|
||||
|
||||
public static final LangString EDITOR_BUTTON_CURRENT_DEFAULT_NAME = LangString.of("Editor.Button.Current.DefaultName",
|
||||
"Current"
|
||||
);
|
||||
|
||||
public static final LangString EDITOR_BUTTON_CURRENT_INFO = LangString.of("Editor.Button.Current.Info",
|
||||
LIGHT_YELLOW.enclose("● " + LIGHT_GRAY.enclose(GENERIC_NAME + ": ") + GENERIC_VALUE)
|
||||
);
|
||||
|
||||
public static final LangString EDITOR_BUTTON_CLICK_KEY = LangString.of("Editor.Button.ClickKey",
|
||||
LIGHT_YELLOW.enclose("[▶]") + " " + LIGHT_GRAY.enclose(GENERIC_NAME + " to " + LIGHT_YELLOW.enclose(GENERIC_VALUE) + ".")
|
||||
);
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static final LangItem EDITOR_ITEM_CLOSE = LangItem.of("Editor.Generic.Close", LIGHT_RED.enclose(BOLD.enclose("Exit")));
|
||||
@Deprecated
|
||||
public static final LangItem EDITOR_ITEM_RETURN = LangItem.of("Editor.Generic.Return", LIGHT_GRAY.enclose(BOLD.enclose("Return")));
|
||||
@Deprecated
|
||||
public static final LangItem EDITOR_ITEM_NEXT_PAGE = LangItem.of("Editor.Generic.NextPage", LIGHT_GRAY.enclose("Next Page →"));
|
||||
@Deprecated
|
||||
public static final LangItem EDITOR_ITEM_PREVIOUS_PAGE = LangItem.of("Editor.Generic.PreviousPage", LIGHT_GRAY.enclose("← Previous Page"));
|
||||
|
||||
public static final LangUIButton EDITOR_ITEM_EXIT = LangUIButton.builder("Editor.Item.Exit", LIGHT_RED.enclose(BOLD.enclose("Exit"))).build();
|
||||
public static final LangUIButton EDITOR_ITEM_BACK = LangUIButton.builder("Editor.Item.Return", LIGHT_GRAY.enclose(BOLD.enclose("Return"))).build();
|
||||
public static final LangUIButton EDITOR_ITEM_NEXT = LangUIButton.builder("Editor.Item.NextPage", LIGHT_GRAY.enclose(UNBOLD.enclose("Next Page →"))).build();
|
||||
public static final LangUIButton EDITOR_ITEM_PREVIOUS = LangUIButton.builder("Editor.Item.PreviousPage", LIGHT_GRAY.enclose(UNBOLD.enclose("← Previous Page"))).build();
|
||||
|
||||
@NotNull
|
||||
public static String getYesOrNo(boolean value) {
|
||||
return (value ? OTHER_YES : OTHER_NO).getString();
|
||||
|
||||
@@ -44,13 +44,6 @@ public abstract class AbstractDataManager<P extends NightPlugin> extends Abstrac
|
||||
|
||||
@NotNull
|
||||
protected static DatabaseConfig getDataConfig(@NotNull NightPlugin plugin) {
|
||||
// DbConfig dataConfig = plugin.getDetails().getDatabaseConfig();
|
||||
// if (dataConfig == null) {
|
||||
// plugin.warn("The plugin didn't have database configuration. Fixing it now...");
|
||||
// dataConfig = DbConfig.read(plugin);
|
||||
// }
|
||||
// return dataConfig;
|
||||
//
|
||||
return DatabaseConfig.read(plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightPlugin;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.Writeable;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DatabaseConfig {
|
||||
public class DatabaseConfig implements Writeable {
|
||||
|
||||
public static final String DEF_FILE_NAME = "data.db";
|
||||
public static final String DEF_PATH = "Database.";
|
||||
|
||||
private final int syncInterval;
|
||||
private final DatabaseType databaseType;
|
||||
@@ -57,67 +61,79 @@ public class DatabaseConfig {
|
||||
@NotNull
|
||||
public static DatabaseConfig read(@NotNull NightPlugin plugin) {
|
||||
String defPrefix = StringUtil.lowerCaseUnderscore(plugin.getName());
|
||||
return read(plugin.getConfig(), defPrefix);
|
||||
|
||||
FileConfig config = plugin.getConfig();
|
||||
FileConfig engineConf = plugin.getEngineConfig();
|
||||
|
||||
// ---------- MIGRATION - START ----------
|
||||
if (config.contains(DEF_PATH)) {
|
||||
DatabaseConfig old = read(config, defPrefix);
|
||||
old.write(engineConf, DEF_PATH);
|
||||
//config.remove(DEF_PATH);
|
||||
if (!config.contains(DEF_PATH + "UserData")) {
|
||||
config.remove(DEF_PATH);
|
||||
}
|
||||
}
|
||||
// ---------- MIGRATION - END ----------
|
||||
|
||||
return read(engineConf, defPrefix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DatabaseConfig read(@NotNull FileConfig config, @NotNull String defaultPrefix) {
|
||||
return read(config, defaultPrefix, "data.db");
|
||||
return read(config, DEF_PATH, defaultPrefix, DEF_FILE_NAME);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DatabaseConfig read(@NotNull FileConfig config, @NotNull String defaultPrefix, @NotNull String defFileName) {
|
||||
String path = "Database.";
|
||||
|
||||
DatabaseType databaseType = ConfigValue.create(path + "Type", DatabaseType.class, DatabaseType.SQLITE,
|
||||
public static DatabaseConfig read(@NotNull FileConfig config, @NotNull String path, @NotNull String defaultPrefix, @NotNull String defFileName) {
|
||||
DatabaseType databaseType = ConfigValue.create(path + ".Type", DatabaseType.class, DatabaseType.SQLITE,
|
||||
"Sets database type.",
|
||||
"Available values: " + String.join(",", Stream.of(DatabaseType.values()).map(Enum::name).toList()))
|
||||
.read(config);
|
||||
|
||||
int syncInterval = ConfigValue.create(path + "Sync_Interval", -1,
|
||||
int syncInterval = ConfigValue.create(path + ".Sync_Interval", -1,
|
||||
"Sets how often (in seconds) plugin data will be fetched and loaded from the remote database.",
|
||||
"Useless for " + DatabaseType.SQLITE.name() + ".",
|
||||
"Set to '-1' to disable.")
|
||||
.read(config);
|
||||
|
||||
String tablePrefix = ConfigValue.create(path + "Table_Prefix", defaultPrefix,
|
||||
String tablePrefix = ConfigValue.create(path + ".Table_Prefix", defaultPrefix,
|
||||
"Custom prefix for plugin tables in database.")
|
||||
.read(config);
|
||||
|
||||
String mysqlUser = ConfigValue.create(path + "MySQL.Username", "root",
|
||||
String mysqlUser = ConfigValue.create(path + ".MySQL.Username", "root",
|
||||
"Database user name.")
|
||||
.read(config);
|
||||
|
||||
String mysqlPassword = ConfigValue.create(path + "MySQL.Password", "root",
|
||||
String mysqlPassword = ConfigValue.create(path + ".MySQL.Password", "root",
|
||||
"Database password.")
|
||||
.read(config);
|
||||
|
||||
String mysqlHost = ConfigValue.create(path + "MySQL.Host", "localhost:3306",
|
||||
String mysqlHost = ConfigValue.create(path + ".MySQL.Host", "localhost:3306",
|
||||
"Database host. Example: localhost:3306, 127.0.0.1:3306")
|
||||
.read(config);
|
||||
|
||||
String mysqlBase = ConfigValue.create(path + "MySQL.Database", "minecraft",
|
||||
String mysqlBase = ConfigValue.create(path + ".MySQL.Database", "minecraft",
|
||||
"Name of the MySQL database where plugin will create tables.")
|
||||
.read(config);
|
||||
|
||||
String urlOptions = ConfigValue.create(path + "MySQL.Options",
|
||||
String urlOptions = ConfigValue.create(path + ".MySQL.Options",
|
||||
"?allowPublicKeyRetrieval=true&useSSL=false",
|
||||
"Connection options. Do not touch unless you know what you're doing."
|
||||
).read(config);
|
||||
|
||||
String sqliteFilename = ConfigValue.create(path + "SQLite.FileName", defFileName,
|
||||
String sqliteFilename = ConfigValue.create(path + ".SQLite.FileName", defFileName,
|
||||
"File name for the SQLite database file.",
|
||||
"Actually it's a path to the file, so you can use directories here.")
|
||||
.read(config);
|
||||
|
||||
|
||||
path = "Database.Purge.";
|
||||
boolean purgeEnabled = ConfigValue.create(path + "Enabled", false,
|
||||
boolean purgeEnabled = ConfigValue.create(path + ".Purge.Enabled", false,
|
||||
"Enables the purge feature.",
|
||||
"Purge will remove all records from the plugin tables that are 'old' enough.")
|
||||
.read(config);
|
||||
|
||||
int purgePeriod = ConfigValue.create(path + "For_Period", 60,
|
||||
int purgePeriod = ConfigValue.create(path + ".Purge.For_Period", 60,
|
||||
"Sets maximal 'age' for the database records before they will be purged.",
|
||||
"This option may have different behavior depends on the plugin.",
|
||||
"By default it's days of inactivity for the plugin users.")
|
||||
@@ -133,6 +149,21 @@ public class DatabaseConfig {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Type", this.databaseType.name());
|
||||
config.set(path + ".Sync_Interval", this.syncInterval);
|
||||
config.set(path + ".Table_Prefix", this.tablePrefix);
|
||||
config.set(path + ".MySQL.Username", this.username);
|
||||
config.set(path + ".MySQL.Password", this.password);
|
||||
config.set(path + ".MySQL.Host", this.host);
|
||||
config.set(path + ".MySQL.Database", this.database);
|
||||
config.set(path + ".MySQL.Options", this.urlOptions);
|
||||
config.set(path + ".SQLite.FileName", this.filename);
|
||||
config.set(path + ".Purge.Enabled", this.purgeEnabled);
|
||||
config.set(path + ".Purge.For_Period", this.purgePeriod);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DatabaseType getStorageType() {
|
||||
return databaseType;
|
||||
|
||||
@@ -4,11 +4,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightPlugin;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.Writeable;
|
||||
|
||||
public class UserdataConfig {
|
||||
public class UserdataConfig implements Writeable {
|
||||
|
||||
private final long cacheLifetime;
|
||||
private final int cacheCleanupInterval;
|
||||
private final int cacheCleanupInterval;
|
||||
|
||||
private final long saveInterval;
|
||||
private final double saveDelay;
|
||||
@@ -25,8 +26,22 @@ public class UserdataConfig {
|
||||
@NotNull
|
||||
public static UserdataConfig read(@NotNull NightPlugin plugin) {
|
||||
FileConfig config = plugin.getConfig();
|
||||
FileConfig engineConf = plugin.getEngineConfig();
|
||||
|
||||
long cacheLifetime = ConfigValue.create("Database.UserData.Cache.LifeTime",
|
||||
// ---------- MIGRATION - START ----------
|
||||
if (config.contains("Database.UserData")) {
|
||||
UserdataConfig old = read(config, "Database.UserData");
|
||||
old.write(engineConf, "UserData");
|
||||
config.remove("Database");
|
||||
}
|
||||
// ---------- MIGRATION - END ----------
|
||||
|
||||
return read(engineConf, "UserData");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UserdataConfig read(@NotNull FileConfig config, @NotNull String path) {
|
||||
long cacheLifetime = ConfigValue.create(path + ".Cache.LifeTime",
|
||||
300L,
|
||||
"Sets cache lifetime for player's data.",
|
||||
"Data loaded for offline players and data of previously online players will be cached in the memory for that time.",
|
||||
@@ -36,7 +51,7 @@ public class UserdataConfig {
|
||||
"[Default is 300 (5 minutes)]"
|
||||
).read(config);
|
||||
|
||||
int cacheCleanupInterval = ConfigValue.create("Database.UserData.Cache.CleanUp_Interval",
|
||||
int cacheCleanupInterval = ConfigValue.create(path + ".Cache.CleanUp_Interval",
|
||||
300,
|
||||
"Sets how often (in seconds) plugin will clean up user data cache.",
|
||||
"Cache contains data loaded for offline players and data of previously online players",
|
||||
@@ -44,7 +59,7 @@ public class UserdataConfig {
|
||||
"[Default is 300 (5 minutes)]"
|
||||
).read(config);
|
||||
|
||||
long saveInterval = ConfigValue.create("Database.UserData.Scheduled_Save_Interval",
|
||||
long saveInterval = ConfigValue.create(path + ".Scheduled_Save_Interval",
|
||||
20L,
|
||||
"Sets how often (in ticks) plugin will attempt to save data of users marked to be saved.",
|
||||
"This will save only users that are 'ready' to save (see 'Scheduled_Save_Delay').",
|
||||
@@ -53,7 +68,7 @@ public class UserdataConfig {
|
||||
"[Default is 20]"
|
||||
).read(config);
|
||||
|
||||
double saveDelay = ConfigValue.create("Database.UserData.Scheduled_Save_Delay",
|
||||
double saveDelay = ConfigValue.create(path + ".Scheduled_Save_Delay",
|
||||
1D,
|
||||
"Sets scheduled save delay (in seconds) for a user when marked to be saved.",
|
||||
"This means that a user will be saved X seconds later after being marked.",
|
||||
@@ -69,7 +84,7 @@ public class UserdataConfig {
|
||||
"[Default is 1]"
|
||||
).read(config);
|
||||
|
||||
int saveSyncPause = ConfigValue.create("Database.UserData.Scheduled_Save_Sync_Pause",
|
||||
int saveSyncPause = ConfigValue.create(path + ".Scheduled_Save_Sync_Pause",
|
||||
3,
|
||||
"Sets synchronization delay (in seconds) before the plugin can continue syncing data for a user after its scheduled save.",
|
||||
"When a user marked for saving has been saved, their synchronization will be unlocked but delayed for this value.",
|
||||
@@ -81,6 +96,15 @@ public class UserdataConfig {
|
||||
return new UserdataConfig(cacheLifetime, cacheCleanupInterval, saveInterval, saveDelay, saveSyncPause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Cache.LifeTime", this.cacheLifetime);
|
||||
config.set(path + ".Cache.CleanUp_Interval", this.cacheCleanupInterval);
|
||||
config.set(path + ".Scheduled_Save_Interval", this.saveInterval);
|
||||
config.set(path + ".Scheduled_Save_Delay", this.saveDelay);
|
||||
config.set(path + ".Scheduled_Save_Sync_Pause", this.saveSyncPause);
|
||||
}
|
||||
|
||||
public long getCacheLifetime() {
|
||||
return this.cacheLifetime;
|
||||
}
|
||||
@@ -100,13 +124,4 @@ public class UserdataConfig {
|
||||
public int getSaveSyncPause() {
|
||||
return this.saveSyncPause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserdataConfig{" +
|
||||
"scheduledSaveInterval=" + saveInterval +
|
||||
", scheduledSaveDelay=" + saveDelay +
|
||||
", scheduledSaveSyncPause=" + saveSyncPause +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -8,23 +8,35 @@ import su.nightexpress.nightcore.util.StringUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LangEnum<E extends Enum<E>> implements LangElement {
|
||||
|
||||
private final String path;
|
||||
private final Class<E> clazz;
|
||||
|
||||
private final Map<E, String> defaultsMap;
|
||||
private final Map<E, String> localeMap;
|
||||
|
||||
public LangEnum(@NotNull String path, @NotNull Class<E> clazz) {
|
||||
public LangEnum(@NotNull String path, @NotNull Class<E> clazz, @NotNull Map<E, String> defaultsMap) {
|
||||
this.path = path;
|
||||
this.clazz = clazz;
|
||||
this.defaultsMap = defaultsMap;
|
||||
this.localeMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <E extends Enum<E>> LangEnum<E> of(@NotNull String path, @NotNull Class<E> clazz) {
|
||||
return new LangEnum<>(path, clazz);
|
||||
return of(path, clazz, map -> {});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <E extends Enum<E>> LangEnum<E> of(@NotNull String path, @NotNull Class<E> clazz, @NotNull Consumer<Map<E, String>> consumer) {
|
||||
Map<E, String> defaults = new HashMap<>();
|
||||
consumer.accept(defaults);
|
||||
|
||||
return new LangEnum<>(path, clazz, defaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +48,8 @@ public class LangEnum<E extends Enum<E>> implements LangElement {
|
||||
FileConfig config = plugin.getLang();
|
||||
|
||||
Stream.of(this.clazz.getEnumConstants()).forEach(con -> {
|
||||
String text = ConfigValue.create(this.path + "." + con.name(), StringUtil.capitalizeUnderscored(con.name())).read(config);
|
||||
String def = this.defaultsMap.getOrDefault(con, StringUtil.capitalizeUnderscored(con.name()));
|
||||
String text = ConfigValue.create(this.path + "." + con.name(), def).read(config);
|
||||
this.localeMap.put(con, text);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
|
||||
import static su.nightexpress.nightcore.util.text.tag.Tags.*;
|
||||
|
||||
@Deprecated
|
||||
public class LangItem extends LangEntry {
|
||||
|
||||
private final List<String> defaultLore;
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
package su.nightexpress.nightcore.language.entry;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.core.CoreLang;
|
||||
import su.nightexpress.nightcore.ui.menu.click.ClickKey;
|
||||
import su.nightexpress.nightcore.util.StringUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LangUIButton implements LangElement {
|
||||
|
||||
private final String path;
|
||||
private final Details defaults;
|
||||
|
||||
private Details details;
|
||||
|
||||
protected LangUIButton(@NotNull String path, @NotNull Details defaults) {
|
||||
this.path = path;
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Builder builder(@NotNull String path, @NotNull String name) {
|
||||
return new Builder(path, name);
|
||||
}
|
||||
|
||||
protected record Details(String name, List<String> description, Map<String, String> currentInfo, Map<ClickKey, String> clickActions){}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FileConfig config) {
|
||||
config.set(this.path + ".Name", this.defaults.name);
|
||||
config.set(this.path + ".Description", this.defaults.description);
|
||||
|
||||
config.remove(this.path + ".CurrentInfo");
|
||||
this.defaults.currentInfo.forEach((name, value) -> config.set(this.path + ".CurrentInfo." + name, value));
|
||||
|
||||
config.remove(this.path + ".ClickActions");
|
||||
this.defaults.clickActions.forEach((key, action) -> config.set(this.path + ".ClickActions." + key.name(), action));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(@NotNull NightCorePlugin plugin) {
|
||||
FileConfig config = plugin.getLang();
|
||||
|
||||
if (!config.contains(this.path) || !config.contains(this.path + ".ClickActions")) {
|
||||
this.write(config);
|
||||
}
|
||||
|
||||
String name = ConfigValue.create(this.path + ".Name", this.defaults.name).read(config);
|
||||
List<String> description = ConfigValue.create(this.path + ".Description", this.defaults.description).read(config);
|
||||
|
||||
Map<String, String> currentInfo = new LinkedHashMap<>();
|
||||
config.getSection(this.path + ".CurrentInfo").forEach(sId -> {
|
||||
String value = config.getString(this.path + ".CurrentInfo." + sId);
|
||||
if (value == null) return;
|
||||
|
||||
currentInfo.put(sId, value);
|
||||
});
|
||||
|
||||
Map<ClickKey, String> clickActions = new LinkedHashMap<>();
|
||||
config.getSection(this.path + ".ClickActions").forEach(sId -> {
|
||||
ClickKey key = StringUtil.getEnum(sId, ClickKey.class).orElse(null);
|
||||
if (key == null) return;
|
||||
|
||||
String action = config.getString(this.path + ".ClickActions." + sId);
|
||||
if (action == null) return;
|
||||
|
||||
clickActions.put(key, action);
|
||||
});
|
||||
|
||||
this.details = new Details(name, description, currentInfo, clickActions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return this.details.name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getDescription() {
|
||||
return this.details.description;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, String> getCurrentInfo() {
|
||||
return this.details.currentInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<ClickKey, String> getClickActions() {
|
||||
return this.details.clickActions;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private final String path;
|
||||
|
||||
private final List<String> description;
|
||||
private final Map<String, String> currentInfo;
|
||||
private final Map<ClickKey, String> clickActions;
|
||||
|
||||
private String name;
|
||||
|
||||
public Builder(@NotNull String path, @NotNull String name) {
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.description = new ArrayList<>();
|
||||
this.currentInfo = new LinkedHashMap<>();
|
||||
this.clickActions = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LangUIButton build() {
|
||||
return new LangUIButton(this.path, new Details(this.name, new ArrayList<>(this.description), this.currentInfo, new HashMap<>(this.clickActions)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder name(@NotNull String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder description(@NotNull String... text) {
|
||||
this.description.addAll(Arrays.asList(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder current(@NotNull String value) {
|
||||
return this.current(CoreLang.EDITOR_BUTTON_CURRENT_DEFAULT_NAME.getString(), value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder current(@NotNull String name, @NotNull String value) {
|
||||
this.currentInfo.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder click(@NotNull String action) {
|
||||
return this.leftClick(action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder leftClick(@NotNull String action) {
|
||||
return this.click(ClickKey.LEFT, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder rightClick(@NotNull String action) {
|
||||
return this.click(ClickKey.RIGHT, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder shiftLeft(@NotNull String action) {
|
||||
return this.click(ClickKey.SHIFT_LEFT, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder shiftRight(@NotNull String action) {
|
||||
return this.click(ClickKey.SHIFT_RIGHT, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder dropKey(@NotNull String action) {
|
||||
return this.click(ClickKey.DROP_KEY, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder swapKey(@NotNull String action) {
|
||||
return this.click(ClickKey.SWAP_KEY, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder dragAndDrop(@NotNull String action) {
|
||||
return this.click(ClickKey.DRAG_N_DROP, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder click(@NotNull ClickKey click, @NotNull String action) {
|
||||
this.clickActions.put(click, action);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class LangMessage {
|
||||
}
|
||||
}
|
||||
else if (type.equalsIgnoreCase("sound")) {
|
||||
options.setSound(BukkitThing.getSound(typeContent));
|
||||
options.setSound(NightSound.deserialize(typeContent));
|
||||
}
|
||||
else if (type.equalsIgnoreCase("prefix")) {
|
||||
boolean b = Boolean.parseBoolean(typeContent);
|
||||
@@ -284,7 +284,7 @@ public class LangMessage {
|
||||
if (this.isDisabled()) return;
|
||||
|
||||
if (this.options.getSound() != null && sender instanceof Player player) {
|
||||
NightSound.of(this.options.getSound()).play(player);
|
||||
this.options.getSound().play(player);
|
||||
}
|
||||
|
||||
Replacer replacer = new Replacer();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package su.nightexpress.nightcore.language.message;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightSound;
|
||||
|
||||
public class MessageOptions {
|
||||
|
||||
private OutputType outputType;
|
||||
private boolean hasPrefix;
|
||||
private boolean usePlaceholderAPI;
|
||||
private Sound sound;
|
||||
private NightSound sound;
|
||||
private int[] titleTimes;
|
||||
|
||||
public MessageOptions() {
|
||||
@@ -54,11 +54,11 @@ public class MessageOptions {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sound getSound() {
|
||||
public NightSound getSound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public void setSound(@Nullable Sound sound) {
|
||||
public void setSound(@Nullable NightSound sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.language.message.MessageOptions;
|
||||
import su.nightexpress.nightcore.language.tag.MessageTag;
|
||||
import su.nightexpress.nightcore.util.BukkitThing;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightSound;
|
||||
|
||||
public class SoundTag extends MessageTag {
|
||||
|
||||
@@ -15,13 +15,18 @@ public class SoundTag extends MessageTag {
|
||||
|
||||
@NotNull
|
||||
public String enclose(@NotNull Sound sound) {
|
||||
return this.enclose(BukkitThing.toString(sound));
|
||||
return this.enclose(NightSound.of(sound, 0.6F));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String enclose(@NotNull NightSound sound) {
|
||||
return this.enclose(sound.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull MessageOptions options, @Nullable String tagContent) {
|
||||
if (tagContent == null) return;
|
||||
|
||||
options.setSound(BukkitThing.getSound(tagContent));
|
||||
options.setSound(NightSound.deserialize(tagContent));
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import su.nightexpress.nightcore.ui.menu.MenuRegistry;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||
import su.nightexpress.nightcore.util.Placeholders;
|
||||
import su.nightexpress.nightcore.util.Players;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
import su.nightexpress.nightcore.util.time.TimeFormats;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DialogManager {
|
||||
|
||||
private static void displayPrompt(@NotNull Dialog dialog, int fade) {
|
||||
Player player = dialog.getPlayer();
|
||||
String title = NightMessage.asLegacy(CoreLang.DIALOG_HEADER.getString().replace(Placeholders.GENERIC_TIME, TimeUtil.formatTime(dialog.getLifetimeMillis())));
|
||||
String title = NightMessage.asLegacy(CoreLang.DIALOG_HEADER.getString().replace(Placeholders.GENERIC_TIME, TimeFormats.toLiteral(dialog.getLifetimeMillis())));
|
||||
String sub = NightMessage.asLegacy(dialog.getPrompt());
|
||||
|
||||
player.sendTitle(title, sub, fade, 40, 20);
|
||||
|
||||
@@ -2,16 +2,24 @@ package su.nightexpress.nightcore.ui.menu.click;
|
||||
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum ClickKey {
|
||||
|
||||
LEFT, RIGHT, SHIFT_LEFT, SHIFT_RIGHT,
|
||||
DROP_KEY, SWAP_KEY,
|
||||
DRAG_N_DROP,
|
||||
;
|
||||
|
||||
@NotNull
|
||||
public static ClickKey from(@NotNull InventoryClickEvent event) {
|
||||
ItemStack cursor = event.getCursor();
|
||||
ItemStack target = event.getCurrentItem();
|
||||
if (!cursor.getType().isAir() && target != null && !target.getType().isAir()) {
|
||||
return DRAG_N_DROP;
|
||||
}
|
||||
|
||||
if (event.getClick() == ClickType.DROP) return DROP_KEY;
|
||||
if (event.getClick() == ClickType.SWAP_OFFHAND) return SWAP_KEY;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.language.entry.LangUIButton;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.ui.menu.Menu;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||
@@ -28,18 +29,38 @@ public interface Linked<T> extends Menu {
|
||||
|
||||
ItemClick manageLink(@NotNull LinkHandler<T> handler);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull Material material, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull Material material, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull ItemStack itemStack, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull ItemStack itemStack, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
@Deprecated
|
||||
void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
|
||||
void addItem(@NotNull Material material, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull Material material, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
void addItem(@NotNull ItemStack itemStack, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull ItemStack itemStack, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
void addItem(@NotNull NightItem item, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull NightItem item, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
|
||||
void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
@@ -32,21 +32,21 @@ public class MenuItem {
|
||||
|
||||
@NotNull
|
||||
public static Builder buildNextPage(@NotNull Menu menu, int slot) {
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_RIGHT).localized(CoreLang.EDITOR_ITEM_NEXT_PAGE))
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_RIGHT).localized(CoreLang.EDITOR_ITEM_NEXT))
|
||||
.setHandler(ItemHandler.forNextPage(menu))
|
||||
.setSlots(slot);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Builder buildPreviousPage(@NotNull Menu menu, int slot) {
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_LEFT).localized(CoreLang.EDITOR_ITEM_PREVIOUS_PAGE))
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_LEFT).localized(CoreLang.EDITOR_ITEM_PREVIOUS))
|
||||
.setHandler(ItemHandler.forPreviousPage(menu))
|
||||
.setSlots(slot);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Builder buildExit(@NotNull Menu menu, int slot) {
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_WRONG_MARK).localized(CoreLang.EDITOR_ITEM_CLOSE))
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_WRONG_MARK).localized(CoreLang.EDITOR_ITEM_EXIT))
|
||||
.setHandler(ItemHandler.forClose(menu))
|
||||
.setSlots(slot);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class MenuItem {
|
||||
|
||||
@NotNull
|
||||
public static Builder buildReturn(@NotNull Menu menu, int slot, @NotNull ItemClick click, @Nullable ItemOptions options) {
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_DOWN).localized(CoreLang.EDITOR_ITEM_RETURN))
|
||||
return builder(NightItem.asCustomHead(Placeholders.SKIN_ARROW_DOWN).localized(CoreLang.EDITOR_ITEM_BACK))
|
||||
.setHandler(ItemHandler.forReturn(menu, click, options))
|
||||
.setSlots(slot);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import su.nightexpress.nightcore.ui.menu.item.ItemHandler;
|
||||
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
|
||||
import su.nightexpress.nightcore.util.Lists;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
import su.nightexpress.nightcore.util.bridge.ServerBridge;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
@@ -158,7 +157,7 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
if (builder instanceof LocationInventoryViewBuilder<?> locationBuilder) {
|
||||
locationBuilder.location(player.getEyeLocation());
|
||||
}
|
||||
view = ServerBridge.createView(builder, this.getTitle(viewer), player);
|
||||
view = Version.software().createView(builder, this.getTitle(viewer), player);
|
||||
}
|
||||
else {
|
||||
view = this.menuType.typed().create(player, NightMessage.asLegacy(this.getTitle(viewer)));
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.inventory.MenuType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.NightPlugin;
|
||||
import su.nightexpress.nightcore.language.entry.LangUIButton;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.ui.dialog.Dialog;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||
@@ -91,35 +92,74 @@ public abstract class LinkedMenu<P extends NightPlugin, T> extends AbstractMenu<
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull Material material, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(material, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull Material material, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(new NightItem(material).localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull ItemStack itemStack, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(itemStack, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull ItemStack itemStack, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(new NightItem(itemStack).localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(item, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(item.localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull Material material, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(material, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull Material material, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(new NightItem(material).localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull ItemStack itemStack, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(itemStack, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull ItemStack itemStack, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(new NightItem(itemStack).localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(item, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangUIButton locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(item.localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(item, slot, handler, null);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Deprecated
|
||||
public class Colorizer {
|
||||
|
||||
@Deprecated public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package su.nightexpress.nightcore.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -11,30 +10,27 @@ import su.nightexpress.nightcore.command.api.NightPluginCommand;
|
||||
import su.nightexpress.nightcore.command.experimental.CommandContext;
|
||||
import su.nightexpress.nightcore.command.experimental.argument.ParsedArguments;
|
||||
import su.nightexpress.nightcore.command.impl.WrappedCommand;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandUtil {
|
||||
|
||||
private static final String FIELD_COMMAND_MAP = "commandMap";
|
||||
private static final String FIELD_KNOWN_COMMANDS = "knownCommands";
|
||||
|
||||
private static final SimpleCommandMap COMMAND_MAP = getCommandMap();
|
||||
|
||||
@NotNull
|
||||
private static SimpleCommandMap getCommandMap() {
|
||||
return (SimpleCommandMap) Reflex.getFieldValue(Bukkit.getServer(), FIELD_COMMAND_MAP);
|
||||
return Version.software().getCommandMap();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void register(@NotNull Plugin plugin, @NotNull NightPluginCommand command) {
|
||||
WrappedCommand wrappedCommand = new WrappedCommand(plugin, command);
|
||||
if (COMMAND_MAP.register(plugin.getName(), wrappedCommand)) {
|
||||
if (getCommandMap().register(plugin.getName(), wrappedCommand)) {
|
||||
command.setBackend(wrappedCommand);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean register(@NotNull Plugin plugin, @NotNull WrappedCommand wrappedCommand) {
|
||||
return COMMAND_MAP.register(plugin.getName(), wrappedCommand);
|
||||
return getCommandMap().register(plugin.getName(), wrappedCommand);
|
||||
}
|
||||
|
||||
/*public static void syncCommands() {
|
||||
@@ -46,14 +42,14 @@ public class CommandUtil {
|
||||
Reflex.invokeMethod(method, server);
|
||||
}*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean unregister(@NotNull String name) {
|
||||
Command command = getCommand(name).orElse(null);
|
||||
if (command == null) return false;
|
||||
|
||||
Map<String, Command> knownCommands = (HashMap<String, Command>) Reflex.getFieldValue(COMMAND_MAP, FIELD_KNOWN_COMMANDS);
|
||||
if (knownCommands == null) return false;
|
||||
if (!command.unregister(COMMAND_MAP)) return false;
|
||||
SimpleCommandMap commandMap = getCommandMap();
|
||||
|
||||
Map<String, Command> knownCommands = Version.software().getKnownCommands(commandMap);
|
||||
if (!command.unregister(commandMap)) return false;
|
||||
|
||||
return knownCommands.keySet().removeIf(key -> key.equalsIgnoreCase(command.getName()) || command.getAliases().contains(key));
|
||||
}
|
||||
@@ -75,14 +71,14 @@ public class CommandUtil {
|
||||
|
||||
@NotNull
|
||||
public static Optional<Command> getCommand(@NotNull String name) {
|
||||
return COMMAND_MAP.getCommands().stream()
|
||||
return getCommandMap().getCommands().stream()
|
||||
.filter(command -> command.getName().equalsIgnoreCase(name) || command.getLabel().equalsIgnoreCase(name) || command.getAliases().contains(name))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getCommandName(@NotNull String str) {
|
||||
String name = Colorizer.strip(str).split(" ")[0].substring(1);
|
||||
String name = NightMessage.stripAll(str).split(" ")[0].substring(1);
|
||||
|
||||
String[] pluginPrefix = name.split(":");
|
||||
if (pluginPrefix.length == 2) {
|
||||
|
||||
@@ -10,12 +10,10 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.NightCore;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class EntityUtil {
|
||||
|
||||
@@ -23,39 +21,8 @@ public class EntityUtil {
|
||||
EquipmentSlot.HAND, EquipmentSlot.OFF_HAND, EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET
|
||||
};
|
||||
|
||||
private static AtomicInteger entityCounter;
|
||||
|
||||
public static boolean loadEntityCounter(@NotNull NightCore core) {
|
||||
Class<?> entityClass = Reflex.getClass("net.minecraft.world.entity", "Entity");
|
||||
if (entityClass == null) {
|
||||
core.error("Could not find NMS Entity class!");
|
||||
return false;
|
||||
}
|
||||
|
||||
String fieldName = "c";
|
||||
if (Version.isAtLeast(Version.V1_19_R3) && Version.isBehind(Version.MC_1_20_6)) {
|
||||
fieldName = "d";
|
||||
}
|
||||
|
||||
Object object = Reflex.getFieldValue(entityClass, fieldName);
|
||||
if (!(object instanceof AtomicInteger atomicInteger)) {
|
||||
if (object == null) {
|
||||
core.error("Could not find entity counter field!");
|
||||
}
|
||||
else core.error("Field '" + fieldName + "' in " + entityClass.getName() + " class is " + object.getClass().getName() + " (expected AtomicInteger)");
|
||||
return false;
|
||||
}
|
||||
|
||||
entityCounter = atomicInteger;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AtomicInteger getEntityCounter() {
|
||||
return entityCounter;
|
||||
}
|
||||
|
||||
public static int nextEntityId() {
|
||||
return entityCounter.incrementAndGet();
|
||||
return Version.software().nextEntityId();
|
||||
}
|
||||
|
||||
public static double getAttribute(@NotNull LivingEntity entity, @NotNull Attribute attribute) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@Deprecated
|
||||
public class ItemReplacer {
|
||||
|
||||
private final ItemStack item;
|
||||
|
||||
@@ -9,10 +9,12 @@ public class Plugins {
|
||||
public static final String VAULT = "Vault";
|
||||
public static final String PLACEHOLDER_API = "PlaceholderAPI";
|
||||
public static final String FLOODGATE = "floodgate";
|
||||
public static final String ECONOMY_BRIDGE = "EconomyBridge";
|
||||
|
||||
private static boolean hasPlaceholderAPI;
|
||||
private static boolean hasVault;
|
||||
private static boolean hasFloodgate;
|
||||
private static boolean hasEconomyBridge;
|
||||
|
||||
private static NightCore core;
|
||||
|
||||
@@ -24,6 +26,7 @@ public class Plugins {
|
||||
hasPlaceholderAPI = isInstalled(PLACEHOLDER_API);
|
||||
hasVault = isInstalled(VAULT);
|
||||
hasFloodgate = isInstalled(FLOODGATE);
|
||||
hasEconomyBridge = isInstalled(ECONOMY_BRIDGE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -57,4 +60,8 @@ public class Plugins {
|
||||
public static boolean hasFloodgate() {
|
||||
return hasFloodgate;
|
||||
}
|
||||
|
||||
public static boolean hasEconomyBridge() {
|
||||
return hasEconomyBridge;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,35 @@
|
||||
package su.nightexpress.nightcore.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.core.CoreLang;
|
||||
import su.nightexpress.nightcore.util.time.TimeFormatType;
|
||||
import su.nightexpress.nightcore.util.time.TimeFormats;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.*;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TimeUtil {
|
||||
|
||||
private static TimeZone timeZone;
|
||||
|
||||
public static void setTimeZone(@NotNull String name) {
|
||||
timeZone = TimeZone.getTimeZone(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TimeZone getTimeZone() {
|
||||
return timeZone;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ZoneId getZoneId() {
|
||||
return timeZone.toZoneId();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static String formatTime(long time) {
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time) % 24;
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) % 60;
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) % 60;
|
||||
String delimiter = CoreLang.TIME_DELIMITER.getString();
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (days > 0) {
|
||||
if (!str.isEmpty()) {
|
||||
str.append(delimiter);
|
||||
}
|
||||
str.append(CoreLang.TIME_DAY.getString().replace(Placeholders.GENERIC_AMOUNT, String.valueOf(days)));
|
||||
}
|
||||
if (hours > 0) {
|
||||
if (!str.isEmpty()) {
|
||||
str.append(delimiter);
|
||||
}
|
||||
str.append(CoreLang.TIME_HOUR.getString().replace(Placeholders.GENERIC_AMOUNT, String.valueOf(hours)));
|
||||
}
|
||||
if (minutes > 0) {
|
||||
if (!str.isEmpty()) {
|
||||
str.append(delimiter);
|
||||
}
|
||||
str.append(CoreLang.TIME_MINUTE.getString().replace(Placeholders.GENERIC_AMOUNT, String.valueOf(minutes)));
|
||||
}
|
||||
if (str.isEmpty() || seconds > 0) {
|
||||
if (!str.isEmpty()) {
|
||||
str.append(delimiter);
|
||||
}
|
||||
|
||||
boolean doDecimal = seconds != 0 && seconds < 5 && str.isEmpty();
|
||||
String secondsStr = doDecimal ? NumberUtil.format((double) time / 1000D) : String.valueOf(seconds);
|
||||
|
||||
str.append(CoreLang.TIME_SECOND.getString().replace(Placeholders.GENERIC_AMOUNT, secondsStr));
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
return TimeFormats.toLiteral(time);
|
||||
}
|
||||
|
||||
public static boolean isPassed(long timestamp) {
|
||||
@@ -77,14 +57,18 @@ public class TimeUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static String formatDuration(long from, long to) {
|
||||
long time = to - from;
|
||||
return formatTime(time);
|
||||
//return formatTime(time);
|
||||
return TimeFormats.toLiteral(time);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static String formatDuration(long until) {
|
||||
return formatTime(until - System.currentTimeMillis());
|
||||
return TimeFormats.formatDuration(until, TimeFormatType.LITERAL);
|
||||
//return formatTime(until - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -96,13 +80,28 @@ public class TimeUtil {
|
||||
return LocalTime.of((int) hours, (int) minutes, (int) seconds);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalDateTime getCurrentDateTime() {
|
||||
return LocalDateTime.now(getZoneId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalDate getCurrentDate() {
|
||||
return LocalDate.now(getZoneId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalTime getCurrentTime() {
|
||||
return LocalTime.now(getZoneId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalDateTime getLocalDateTimeOf(long ms) {
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), TimeZone.getDefault().toZoneId());
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), getZoneId());
|
||||
}
|
||||
|
||||
public static long toEpochMillis(@NotNull LocalDateTime dateTime) {
|
||||
Instant instant = dateTime.atZone(TimeZone.getDefault().toZoneId()).toInstant();
|
||||
Instant instant = dateTime.atZone(getZoneId()).toInstant();
|
||||
return instant.toEpochMilli();
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,16 @@ import su.nightexpress.nightcore.NightCorePlugin;
|
||||
import su.nightexpress.nightcore.util.bridge.PaperBridge;
|
||||
import su.nightexpress.nightcore.util.bridge.Software;
|
||||
import su.nightexpress.nightcore.util.bridge.SpigotBridge;
|
||||
import su.nightexpress.nightcore.util.version.VersionComponent;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum Version {
|
||||
|
||||
V1_19_R3("1.19.4"),
|
||||
V1_19_R3("1.19.4", Status.OUTDATED),
|
||||
V1_20_R1("1.20.1", Status.OUTDATED),
|
||||
V1_20_R2("1.20.2", Status.OUTDATED),
|
||||
V1_20_R3("1.20.4"),
|
||||
V1_20_R3("1.20.4", Status.OUTDATED),
|
||||
MC_1_20_6("1.20.6", Status.OUTDATED),
|
||||
MC_1_21_0("1.21", Status.OUTDATED),
|
||||
MC_1_21("1.21.1"),
|
||||
@@ -29,11 +26,9 @@ public enum Version {
|
||||
UNKNOWN("Unknown"),
|
||||
;
|
||||
|
||||
public static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private static final Set<VersionComponent> LOADED_COMPONENTS = new HashSet<>();
|
||||
public static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
|
||||
|
||||
private static Version current;
|
||||
//private static boolean spigot;
|
||||
private static Software software;
|
||||
|
||||
private final Status status;
|
||||
@@ -48,12 +43,6 @@ public enum Version {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static String getProtocol() {
|
||||
return Bukkit.getServer().getBukkitVersion();
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
SUPPORTED,
|
||||
OUTDATED,
|
||||
@@ -68,28 +57,22 @@ public enum Version {
|
||||
|
||||
current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> exact.equalsIgnoreCase(version.getLocalized())).findFirst().orElse(UNKNOWN);
|
||||
software = isSpigot ? new SpigotBridge() : new PaperBridge();
|
||||
software.initialize(core);
|
||||
core.info("Server version detected as " + bukkitName + " " + current.getLocalized() + ". Using " + software().getName() + ".");
|
||||
|
||||
loadComponents(core);
|
||||
}
|
||||
|
||||
private static void loadComponents(@NotNull NightCore core) {
|
||||
LOADED_COMPONENTS.clear();
|
||||
|
||||
loadComponent(core, VersionComponent.ENTITY_ID_GENERATOR, EntityUtil.loadEntityCounter(core));
|
||||
loadComponent(core, VersionComponent.ITEM_NBT_COMPRESSOR, ItemNbt.load(core));
|
||||
|
||||
if (hasComponent(VersionComponent.ITEM_NBT_COMPRESSOR) && !ItemNbt.test()) {
|
||||
core.error(VersionComponent.ITEM_NBT_COMPRESSOR.name() + ": Test failed.");
|
||||
boolean nbtLoad = ItemNbt.load(core);
|
||||
if (!nbtLoad) {
|
||||
core.error("Could not load Item NBT Compressor.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadComponent(@NotNull NightCore core, @NotNull VersionComponent component, boolean state) {
|
||||
if (state) {
|
||||
LOADED_COMPONENTS.add(component);
|
||||
core.info("[Core Components] " + component.name() + ": Loaded");
|
||||
if (!ItemNbt.test()) {
|
||||
core.error("Failed test of Item NBT Compressor.");
|
||||
}
|
||||
else core.error("[Core Components] " + component.name() + ": Error");
|
||||
}
|
||||
|
||||
public static void printCaution(@NotNull NightCorePlugin plugin) {
|
||||
@@ -130,8 +113,8 @@ public enum Version {
|
||||
return software.isSpigot();
|
||||
}
|
||||
|
||||
public static boolean hasComponent(@NotNull VersionComponent component) {
|
||||
return LOADED_COMPONENTS.contains(component);
|
||||
public static boolean isPaper() {
|
||||
return software.isPaper();
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
@@ -148,12 +131,12 @@ public enum Version {
|
||||
|
||||
@NotNull
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLocalized() {
|
||||
return localized;
|
||||
return this.localized;
|
||||
}
|
||||
|
||||
public boolean isLower(@NotNull Version version) {
|
||||
|
||||
@@ -2,12 +2,18 @@ package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCore;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class PaperBridge implements Software {
|
||||
|
||||
@@ -27,9 +33,34 @@ public class PaperBridge implements Software {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryView create(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
@Override
|
||||
public boolean initialize(@NotNull NightCore core) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InventoryView createView(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
Component component = JSONComponentSerializer.json().deserialize(NightMessage.asJson(title)); // TODO Direct NightMessage to component
|
||||
|
||||
return builder.title(component).build(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public SimpleCommandMap getCommandMap() {
|
||||
return (SimpleCommandMap) Bukkit.getCommandMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Command> getKnownCommands(@NotNull SimpleCommandMap commandMap) {
|
||||
return commandMap.getKnownCommands();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int nextEntityId() {
|
||||
return Bukkit.getUnsafe().nextEntityId();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ServerBridge {
|
||||
|
||||
@NotNull
|
||||
public static InventoryView createView(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
if (Version.isSpigot()) {
|
||||
return SpigotBridge.create(builder, title, player);
|
||||
}
|
||||
else {
|
||||
return PaperBridge.create(builder, title, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,31 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public interface Software {
|
||||
|
||||
boolean initialize(@NotNull NightCore core);
|
||||
|
||||
@NotNull String getName();
|
||||
|
||||
boolean isSpigot();
|
||||
|
||||
boolean isPaper();
|
||||
|
||||
@NotNull InventoryView createView(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player);
|
||||
|
||||
@NotNull SimpleCommandMap getCommandMap();
|
||||
|
||||
@NotNull Map<String, Command> getKnownCommands(@NotNull SimpleCommandMap commandMap);
|
||||
|
||||
int nextEntityId();
|
||||
}
|
||||
@@ -1,15 +1,65 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCore;
|
||||
import su.nightexpress.nightcore.util.Reflex;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class SpigotBridge implements Software {
|
||||
|
||||
private static final String FIELD_COMMAND_MAP = "commandMap";
|
||||
private static final String FIELD_KNOWN_COMMANDS = "knownCommands";
|
||||
|
||||
private static SimpleCommandMap commandMap;
|
||||
private static AtomicInteger entityCounter;
|
||||
|
||||
@Override
|
||||
public boolean initialize(@NotNull NightCore core) {
|
||||
loadCommandMap();
|
||||
loadEntityCounter(core);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void loadCommandMap() {
|
||||
commandMap = (SimpleCommandMap) Reflex.getFieldValue(Bukkit.getServer(), FIELD_COMMAND_MAP);
|
||||
}
|
||||
|
||||
private static void loadEntityCounter(NightCore core) {
|
||||
Class<?> entityClass = Reflex.getClass("net.minecraft.world.entity", "Entity");
|
||||
if (entityClass == null) {
|
||||
core.error("Could not find NMS Entity class!");
|
||||
return;
|
||||
}
|
||||
|
||||
String fieldName = "c";
|
||||
if (Version.isAtLeast(Version.V1_19_R3) && Version.isBehind(Version.MC_1_20_6)) {
|
||||
fieldName = "d";
|
||||
}
|
||||
|
||||
Object object = Reflex.getFieldValue(entityClass, fieldName);
|
||||
if (!(object instanceof AtomicInteger atomicInteger)) {
|
||||
if (object == null) {
|
||||
core.error("Could not find entity counter field!");
|
||||
}
|
||||
else core.error("Field '" + fieldName + "' in " + entityClass.getName() + " class is " + object.getClass().getName() + " (expected AtomicInteger)");
|
||||
return;
|
||||
}
|
||||
|
||||
entityCounter = atomicInteger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
@@ -26,8 +76,32 @@ public class SpigotBridge implements Software {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static InventoryView create(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
@NotNull
|
||||
@Override
|
||||
public InventoryView createView(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
Reflex.setFieldValue(builder, "title", NightMessage.asLegacy(title));
|
||||
return builder.build(player);//menuType.typed().builder().title(title).build(player);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleCommandMap getCommandMap() {
|
||||
//SimpleCommandMap commandMap = (SimpleCommandMap) Reflex.getFieldValue(Bukkit.getServer(), FIELD_COMMAND_MAP);
|
||||
if (commandMap == null) throw new IllegalStateException("Command map is null!");
|
||||
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Command> getKnownCommands(@NotNull SimpleCommandMap commandMap) {
|
||||
Map<String, Command> knownCommands = (Map<String, Command>) Reflex.getFieldValue(commandMap, FIELD_KNOWN_COMMANDS);
|
||||
return knownCommands == null ? Collections.emptyMap() : knownCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextEntityId() {
|
||||
return entityCounter.incrementAndGet();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ 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.language.entry.LangUIButton;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
|
||||
import su.nightexpress.nightcore.util.BukkitThing;
|
||||
@@ -183,9 +184,17 @@ public class NightItem implements Writeable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public NightItem localized(@NotNull LangItem langItem) {
|
||||
this.setDisplayName(langItem.getLocalizedName());
|
||||
this.setLore(langItem.getLocalizedLore());
|
||||
// this.setDisplayName(langItem.getLocalizedName());
|
||||
// this.setLore(langItem.getLocalizedLore());
|
||||
this.meta.localized(langItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightItem localized(@NotNull LangUIButton langUIButton) {
|
||||
this.meta.localized(langUIButton);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ 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.CoreLang;
|
||||
import su.nightexpress.nightcore.language.entry.LangUIButton;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.util.*;
|
||||
import su.nightexpress.nightcore.util.placeholder.Replacer;
|
||||
@@ -336,12 +338,42 @@ public class NightMeta implements Writeable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public NightMeta localized(@NotNull LangItem langItem) {
|
||||
this.setDisplayName(langItem.getLocalizedName());
|
||||
this.setLore(langItem.getLocalizedLore());
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightMeta localized(@NotNull LangUIButton locale) {
|
||||
String name = CoreLang.EDITOR_BUTTON_NAME.getString().replace(Placeholders.GENERIC_NAME, locale.getName());
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
locale.getCurrentInfo().forEach((title, value) -> {
|
||||
lore.add(CoreLang.EDITOR_BUTTON_CURRENT_INFO.getString()
|
||||
.replace(Placeholders.GENERIC_NAME, title)
|
||||
.replace(Placeholders.GENERIC_VALUE, value));
|
||||
});
|
||||
lore.add(Placeholders.EMPTY_IF_ABOVE);
|
||||
|
||||
for (String entry : locale.getDescription()) {
|
||||
lore.add(CoreLang.EDITOR_BUTTON_DESCRIPTION.getString().replace(Placeholders.GENERIC_ENTRY, entry));
|
||||
}
|
||||
lore.add(Placeholders.EMPTY_IF_BELOW);
|
||||
|
||||
locale.getClickActions().forEach((key, action) -> {
|
||||
lore.add(CoreLang.EDITOR_BUTTON_CLICK_KEY.getString()
|
||||
.replace(Placeholders.GENERIC_NAME, CoreLang.CLICK_KEY.getLocalized(key))
|
||||
.replace(Placeholders.GENERIC_VALUE, action)
|
||||
);
|
||||
});
|
||||
|
||||
this.setDisplayName(name);
|
||||
this.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightMeta ignoreNameAndLore() {
|
||||
this.setItemName(null);
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.Writeable;
|
||||
import su.nightexpress.nightcore.util.BukkitThing;
|
||||
@@ -14,6 +13,8 @@ import su.nightexpress.nightcore.util.NumberUtil;
|
||||
|
||||
public class NightSound implements Writeable {
|
||||
|
||||
private static final String DELIMITER = ":";
|
||||
|
||||
private static final float MIN_PITCH = 0.5f;
|
||||
private static final float MAX_PITCH = 2.0f;
|
||||
private static final float MIN_VOLUME = 0f;
|
||||
@@ -48,34 +49,53 @@ public class NightSound implements Writeable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NightSound read(@NotNull FileConfig config, @NotNull String path) {
|
||||
String name = ConfigValue.create(path + ".Name", "null",
|
||||
"Sound name. Use vanilla sound names or custom ones from your resource pack(s).",
|
||||
"All vanilla sound names: https://minecraft.wiki/w/Sounds.json#Sound_events -> 'Java Edition values' -> 'Sound Event' column."
|
||||
).read(config);
|
||||
|
||||
float volume = ConfigValue.create(path + ".Volume", MAX_VOLUME,
|
||||
"Sound volume. [" + MIN_VOLUME + " to " + MAX_VOLUME + "]"
|
||||
).read(config).floatValue();
|
||||
|
||||
float pitch = ConfigValue.create(path + ".Pitch", 1D,
|
||||
"Sound speed. [" + MIN_PITCH + " to " + MAX_PITCH + "]"
|
||||
).read(config).floatValue();
|
||||
|
||||
public static NightSound of(@NotNull String name, float volume, float pitch) {
|
||||
Sound bukkit = BukkitThing.getSound(name);
|
||||
|
||||
return new NightSound(name, bukkit, volume, pitch);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NightSound deserialize(@NotNull String from) {
|
||||
String[] split = from.split(DELIMITER);
|
||||
|
||||
String name = split[0];
|
||||
float volume = split.length >= 2 ? (float) NumberUtil.getDoubleAbs(split[1], MAX_VOLUME) : MAX_VOLUME;
|
||||
float pitch = split.length >= 3 ? (float) NumberUtil.getDoubleAbs(split[2], 1f) : 1f;
|
||||
|
||||
return of(name, volume, pitch);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String serialize() {
|
||||
return this.name + DELIMITER + this.volume + DELIMITER + this.pitch;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static NightSound read(@NotNull FileConfig config, @NotNull String path) {
|
||||
|
||||
if (config.contains(path + ".Name")) {
|
||||
String oldName = config.getString(path + ".Name", "null");
|
||||
float volume = (float) config.getDouble(path + ".Volume");
|
||||
float pitch = (float) config.getDouble(path + ".Putch");
|
||||
|
||||
NightSound old = of(oldName, volume, pitch);
|
||||
config.remove(path);
|
||||
config.set(path, old.serialize());
|
||||
}
|
||||
|
||||
return deserialize(config.getString(path, "null"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Name", this.name);
|
||||
config.set(path + ".Volume", this.volume);
|
||||
config.set(path + ".Pitch", this.pitch);
|
||||
config.set(path, this.serialize());
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.volume <= 0F || this.name.isEmpty();
|
||||
return this.volume <= 0F || this.name.isBlank();
|
||||
}
|
||||
|
||||
public void play(@NotNull Player player) {
|
||||
|
||||
@@ -54,12 +54,13 @@ public class NightTask {
|
||||
return this.bukkitTask != null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isRunning() {
|
||||
return this.bukkitTask != null && this.plugin.getScheduler().isCurrentlyRunning(this.bukkitTask.getTaskId());
|
||||
return this.isValid();//this.bukkitTask != null && this.plugin.getScheduler().isCurrentlyRunning(this.bukkitTask.getTaskId());
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
if (!this.isRunning() || this.bukkitTask == null) return false;
|
||||
if (this.bukkitTask == null) return false;
|
||||
|
||||
this.plugin.getScheduler().cancelTask(this.bukkitTask.getTaskId());
|
||||
return true;
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class RankMap<T extends Number> {
|
||||
@NotNull Creator<T, R> creator,
|
||||
@NotNull Function<Double, T> converter,
|
||||
@NotNull String... description) {
|
||||
ConfigValue.Reader<R> reader = (config, path2, def) -> read(config, path2, creator, converter);
|
||||
ConfigValue.Loader<R> reader = (config, path2) -> read(config, path2, creator, converter);
|
||||
ConfigValue.Writer<R> writer = (config, path2, obj) -> obj.write(config, path2);
|
||||
|
||||
return ConfigValue.create(path, reader, writer, () -> defaultValue, description);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package su.nightexpress.nightcore.util.time;
|
||||
|
||||
public enum TimeFormatType {
|
||||
LITERAL, DIGITAL, SECONDS
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package su.nightexpress.nightcore.util.time;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.core.CoreLang;
|
||||
import su.nightexpress.nightcore.language.entry.LangString;
|
||||
import su.nightexpress.nightcore.util.NumberUtil;
|
||||
import su.nightexpress.nightcore.util.Placeholders;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TimeFormats {
|
||||
|
||||
private static final DateTimeFormatter DIGITAL_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
|
||||
@NotNull
|
||||
public static String formatDuration(long until, @NotNull TimeFormatType formatType) {
|
||||
return formatAmount(until - System.currentTimeMillis(), formatType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatSince(long since, @NotNull TimeFormatType formatType) {
|
||||
return formatAmount(System.currentTimeMillis() - since, formatType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatAmount(long millis, @NotNull TimeFormatType formatType) {
|
||||
return switch (formatType) {
|
||||
case LITERAL -> toLiteral(millis);
|
||||
case DIGITAL -> toDigital(millis);
|
||||
case SECONDS -> toSeconds(millis);
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toDigital(long millis) {
|
||||
return TimeUtil.getLocalTimeOf(millis).format(DIGITAL_FORMATTER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toSeconds(long millis) {
|
||||
long whole = TimeUnit.MILLISECONDS.toSeconds(millis);
|
||||
|
||||
return whole > 0 ? String.valueOf(whole) : NumberUtil.format(millis / 1000D);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toLiteral(long millis) {
|
||||
TimeUnit[] units = {TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.MINUTES, TimeUnit.SECONDS};
|
||||
long[] scales = {0, 24, 60, 60};
|
||||
LangString[] literals = {CoreLang.TIME_DAY, CoreLang.TIME_HOUR, CoreLang.TIME_MINUTE, CoreLang.TIME_SECOND};
|
||||
String delimiter = CoreLang.TIME_DELIMITER.getString();
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int index = 0; index < units.length; index++) {
|
||||
TimeUnit unit = units[index];
|
||||
long scale = scales[index];
|
||||
LangString literal = literals[index];
|
||||
|
||||
long converted = unit.convert(millis, TimeUnit.MILLISECONDS);
|
||||
long result = scale != 0 ? converted % scale : converted;
|
||||
|
||||
if (result > 0) {
|
||||
if (!str.isEmpty()) {
|
||||
str.append(delimiter);
|
||||
}
|
||||
str.append(literal.getString().replace(Placeholders.GENERIC_AMOUNT, String.valueOf(result)));
|
||||
}
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package su.nightexpress.nightcore.util.version;
|
||||
|
||||
public enum VersionComponent {
|
||||
ENTITY_ID_GENERATOR,
|
||||
ITEM_NBT_COMPRESSOR
|
||||
}
|
||||
@@ -3,53 +3,73 @@ package su.nightexpress.nightcore.util.wrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.Writeable;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
public class UniFormatter {
|
||||
public class UniFormatter implements Writeable {
|
||||
|
||||
private final DecimalFormat formatter;
|
||||
|
||||
private final String format;
|
||||
private final String format;
|
||||
private final RoundingMode rounding;
|
||||
private final Locale locale;
|
||||
|
||||
private UniFormatter(@NotNull String format, @NotNull RoundingMode rounding) {
|
||||
private UniFormatter(@NotNull String format, @NotNull RoundingMode rounding, @NotNull Locale locale) {
|
||||
this.format = format;
|
||||
this.rounding = rounding;
|
||||
this.formatter = new DecimalFormat(format, new DecimalFormatSymbols(Locale.US));
|
||||
this.locale = locale;
|
||||
this.formatter = new DecimalFormat(format, new DecimalFormatSymbols(locale));
|
||||
this.formatter.setRoundingMode(rounding);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UniFormatter of(@NotNull String format, @NotNull RoundingMode rounding) {
|
||||
return new UniFormatter(format, rounding);
|
||||
return of(format, rounding, Locale.US);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UniFormatter of(@NotNull String format, @NotNull RoundingMode rounding, @NotNull Locale locale) {
|
||||
return new UniFormatter(format, rounding, locale);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UniFormatter read(@NotNull FileConfig config, @NotNull String path) {
|
||||
String format = ConfigValue.create(path + ".Format", "#,###.##").read(config);
|
||||
RoundingMode rounding = ConfigValue.create(path + ".Rounding", RoundingMode.class, RoundingMode.HALF_EVEN).read(config);
|
||||
String lang = ConfigValue.create(path + ".Locale", Locale.US.toLanguageTag()).read(config);
|
||||
Locale locale = Locale.forLanguageTag(lang);
|
||||
|
||||
return of(format, rounding);
|
||||
return of(format, rounding, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Format", this.getFormat());
|
||||
config.set(path + ".Rounding", this.getRounding().name().toLowerCase());
|
||||
config.set(path + ".Format", this.format);
|
||||
config.set(path + ".Rounding", this.rounding.name());
|
||||
config.set(path + ".Locale", this.locale.toLanguageTag());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String format(double value) {
|
||||
return this.formatter.format(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RoundingMode getRounding() {
|
||||
return this.rounding;
|
||||
}
|
||||
|
||||
public String format(double value) {
|
||||
return this.formatter.format(value);
|
||||
@NotNull
|
||||
public Locale getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
main: su.nightexpress.nightcore.NightCore
|
||||
bootstrapper: su.nightexpress.nightcore.NightCoreBootstrap
|
||||
loader: su.nightexpress.nightcore.NightCoreLoader
|
||||
name: nightcore
|
||||
version: '${project.version}'
|
||||
description: Plugin engine
|
||||
load: STARTUP
|
||||
authors:
|
||||
- NightExpress
|
||||
api-version: '1.19'
|
||||
dependencies:
|
||||
server:
|
||||
Vault:
|
||||
required: false
|
||||
join-classpath: true
|
||||
PlaceholderAPI:
|
||||
required: false
|
||||
join-classpath: true
|
||||
floodgate:
|
||||
required: false
|
||||
join-classpath: true
|
||||
Reference in new issue
Block a user