Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Final
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Dec 14, 2023
1 parent 001f701 commit fb0ca17
Show file tree
Hide file tree
Showing 23 changed files with 502 additions and 361 deletions.
9 changes: 7 additions & 2 deletions NexEngine/src/main/java/su/nexmedia/engine/NexEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public void disable() {
if (this.menuListener != null) this.menuListener.unregisterListeners();
if (this.menuRefreshTask != null) this.menuRefreshTask.stop();

if (EngineUtils.hasVault()) VaultHook.shutdown();
if (EngineUtils.hasVault()) {
VaultHook.shutdown();
}
PlayerBlockTracker.shutdown();
}

Expand All @@ -64,7 +66,10 @@ public void registerHooks() {
@Override
public void registerCommands(@NotNull GeneralCommand<NexEngine> mainCommand) {
mainCommand.addChildren(new ReloadSubCommand<>(this, Placeholders.WILDCARD));
mainCommand.addChildren(new CheckPermCommand(this));

if (EngineUtils.hasVault() && VaultHook.hasPermissions()) {
mainCommand.addChildren(new CheckPermCommand(this));
}
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions NexEngine/src/main/java/su/nexmedia/engine/NexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public final void error(@NotNull String msg) {
this.logger.severe(msg);
}

public final void debug(@NotNull String msg) {
this.info("[DEBUG] " + msg);
}

private void unregisterListeners() {
for (Player player : this.getServer().getOnlinePlayers()) {
Menu<?> menu = Menu.getMenu(player);
Expand Down
1 change: 1 addition & 0 deletions NexEngine/src/main/java/su/nexmedia/engine/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum Version {
V1_19_R3("1.19.4"),
V1_20_R1("1.20.1", true),
V1_20_R2("1.20.2"),
V1_20_R3("1.20.4"),
UNKNOWN("Unknown", true),
// API-Version in plugin.yml won't allow to load this on lower version, so
// assume any other version not listed here is newer one.
Expand Down

This file was deleted.

65 changes: 45 additions & 20 deletions NexEngine/src/main/java/su/nexmedia/engine/api/config/JOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,79 +31,103 @@ public class JOption<T> {
protected Writer<T> writer;
protected Reader<T> reader;

public JOption(@NotNull String path, @NotNull Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
this(path, reader, defaultValue.get(), description);
public JOption(@NotNull String path, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
this(path, JYML::set, reader, defaultValue, description);
}

public JOption(@NotNull String path, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
this(path, null, reader, defaultValue, description);
public JOption(@NotNull String path, @NotNull Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
this(path, JYML::set, reader, defaultValue.get(), description);
}

public JOption(@NotNull String path, @Nullable Writer<T> writer, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
public JOption(@NotNull String path, @NotNull Writer<T> writer, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
this.path = path;
this.description = description == null ? new String[0] : description;
this.writer = writer;
this.reader = reader;
this.defaultValue = defaultValue;
}

@NotNull
public static <T> JOption<T> create(@NotNull ConfigKey<T> key, @NotNull T defaultValue, @Nullable String... description) {
return new JOption<>(key.getPath(), key.getWriter(), key.getReader(), defaultValue, description);
public static <T> JOption<T> create(@NotNull String path,
@NotNull Writer<T> writer,
@NotNull Reader<T> reader,
@NotNull T defaultValue,
@Nullable String... description) {
return new JOption<>(path, writer, reader, defaultValue, description);
}

@NotNull
public static <T> JOption<T> create(@NotNull String path,
@NotNull Writer<T> writer,
@NotNull Reader<T> reader,
@NotNull Supplier<T> defaultValue,
@Nullable String... description) {
return create(path, writer, reader, defaultValue.get(), description);
}

@NotNull
public static <T> JOption<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
return create(path, JYML::set, reader, defaultValue, description);
}

@NotNull
public static <T> JOption<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
return create(path, JYML::set, reader, defaultValue, description);
}

@NotNull
public static JOption<Boolean> create(@NotNull String path, boolean defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_BOOLEAN, defaultValue, description);
return create(path, READER_BOOLEAN, defaultValue, description);
}

@NotNull
public static JOption<Integer> create(@NotNull String path, int defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_INT, defaultValue, description);
return create(path, READER_INT, defaultValue, description);
}

@NotNull
public static JOption<Double> create(@NotNull String path, double defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_DOUBLE, defaultValue, description);
return create(path, READER_DOUBLE, defaultValue, description);
}

@NotNull
public static JOption<Long> create(@NotNull String path, long defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_LONG, defaultValue, description);
return create(path, READER_LONG, defaultValue, description);
}

@NotNull
public static JOption<String> create(@NotNull String path, @NotNull String defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_STRING, defaultValue, description);
return create(path, READER_STRING, defaultValue, description);
}

@NotNull
public static JOption<List<String>> create(@NotNull String path, @NotNull List<String> defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_LIST_STRING, defaultValue, description);
return create(path, READER_LIST_STRING, defaultValue, description);
}

@NotNull
public static JOption<Set<String>> create(@NotNull String path, @NotNull Set<String> defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_SET_STRING, defaultValue, description);
return create(path, READER_SET_STRING, defaultValue, description);
}

@NotNull
public static JOption<ItemStack> create(@NotNull String path, @NotNull ItemStack defaultValue, @Nullable String... description) {
return new JOption<>(path, READER_ITEM, defaultValue, description).setWriter(JYML::setItem);
return create(path, READER_ITEM, defaultValue, description).setWriter(JYML::setItem);
}

@NotNull
public static JOption<UniSound> create(@NotNull String path, @NotNull UniSound defaultValue, @Nullable String... description) {
return new JOption<>(path, (cfg, path1, def) -> UniSound.read(cfg, path1), defaultValue, description).setWriter((cfg, path2, us) -> us.write(cfg, path2));
return create(path, (cfg, path1, def) -> UniSound.read(cfg, path1), defaultValue, description).setWriter((cfg, path2, us) -> us.write(cfg, path2));
}

@NotNull
public static JOption<UniParticle> create(@NotNull String path, @NotNull UniParticle defaultValue, @Nullable String... description) {
return new JOption<>(path, (cfg, path1, def) -> UniParticle.read(cfg, path1), defaultValue, description).setWriter((cfg, path2, us) -> us.write(cfg, path2));
return create(path, (cfg, path1, def) -> UniParticle.read(cfg, path1), defaultValue, description).setWriter((cfg, path2, us) -> us.write(cfg, path2));
}

@NotNull
public static <E extends Enum<E>> JOption<E> create(@NotNull String path, @NotNull Class<E> clazz, @NotNull E defaultValue, @Nullable String... description) {
return new JOption<>(path, ((cfg, path1, def) -> cfg.getEnum(path1, clazz, defaultValue)), defaultValue, description)
return create(path, ((cfg, path1, def) -> cfg.getEnum(path1, clazz, defaultValue)), defaultValue, description)
.setWriter((cfg, path1, type) -> cfg.set(path1, type.name()));
}

Expand All @@ -116,7 +140,7 @@ public static <V> JOption<Set<V>> forSet(@NotNull String path, @NotNull Function
@NotNull
public static <V> JOption<Set<V>> forSet(@NotNull String path, @NotNull Function<String, V> valFun,
@NotNull Set<V> defaultValue, @Nullable String... description) {
return new JOption<>(path,
return create(path,
(cfg, path1, def) -> cfg.getStringSet(path1).stream().map(valFun).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new)),
defaultValue,
description);
Expand Down Expand Up @@ -160,7 +184,7 @@ public static <K, V, M extends Map<K, V>> JOption<M> forMap(@NotNull String path
@NotNull TriFunction<JYML, String, String, V> valFun,
@NotNull Supplier<M> mapSupplier,
@NotNull M defaultValue, @Nullable String... description) {
return new JOption<>(path,
return create(path,
(cfg, path1, def) -> {
M map = mapSupplier.get();
for (String id : cfg.getSection(path1)) {
Expand Down Expand Up @@ -228,6 +252,7 @@ public Reader<T> getReader() {
}

@NotNull
@Deprecated
public JOption<T> mapReader(@NotNull UnaryOperator<T> operator) {
if (this.reader == null) return this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ public Location getLocation(@NotNull String path) {
}

public int[] getIntArray(@NotNull String path) {
int[] slots = new int[0];
return getIntArray(path, new int[0]);
}

public int @NotNull [] getIntArray(@NotNull String path, int[] def) {
String str = this.getString(path);
return str == null ? slots : StringUtil.getIntArray(str);
return str == null ? def : StringUtil.getIntArray(str);
}

public void setIntArray(@NotNull String path, int[] arr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@

public abstract class AbstractUser<P extends NexPlugin<P>> {

protected transient final P plugin;
private transient boolean isRecent = false;

protected final P plugin;
protected final UUID uuid;

protected String name;
protected long dateCreated;
protected long lastOnline;
protected long dateCreated;
protected long lastOnline;
protected long cachedUntil;

@Deprecated private boolean isRecent = false;

public AbstractUser(@NotNull P plugin, @NotNull UUID uuid, @NotNull String name, long dateCreated, long lastOnline) {
this.plugin = plugin;
this.uuid = uuid;
this.name = name;
this.setDateCreated(dateCreated);
this.setLastOnline(lastOnline);
this.setCachedUntil(-1);
}

public void onLoad() {
Expand All @@ -40,14 +43,28 @@ public <U extends AbstractUser<P>> void saveData(@NotNull UserDataHolder<P, U> d
this.plugin.runTaskAsync(task -> dataHolder.getData().saveUser((U) this));
}

@Deprecated
public boolean isRecentlyCreated() {
return isRecent;
}

@Deprecated
public void setRecentlyCreated(boolean recent) {
isRecent = recent;
}

public boolean isCacheExpired() {
return this.getCachedUntil() > 0 && System.currentTimeMillis() > this.getCachedUntil();
}

public long getCachedUntil() {
return cachedUntil;
}

public void setCachedUntil(long cachedUntil) {
this.cachedUntil = cachedUntil;
}

@NotNull
public final UUID getId() {
return this.uuid;
Expand Down
Loading

0 comments on commit fb0ca17

Please sign in to comment.