Skip to content

Commit c9062f6

Browse files
committed
v2.4.4
1 parent 851e0b0 commit c9062f6

26 files changed

+501
-319
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ allprojects {
1010
apply plugin: 'maven-publish'
1111

1212
group = 'plazmer'
13-
version = '2.4.3'
13+
version = '2.4.4'
1414
sourceCompatibility = 17
1515
targetCompatibility = 17
1616

engine/src/main/java/t/me/p1azmer/engine/NexEngine.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public void registerHooks() {
6464
@Override
6565
public void registerCommands(@NotNull GeneralCommand<NexEngine> mainCommand) {
6666
mainCommand.addChildren(new ReloadSubCommand<>(this, Placeholders.WILDCARD));
67-
mainCommand.addChildren(new CheckPermCommand(this));
67+
if (EngineUtils.hasVault() && VaultHook.hasPermissions()) {
68+
mainCommand.addChildren(new CheckPermCommand(this));
69+
}
6870
}
6971

7072
@Override

engine/src/main/java/t/me/p1azmer/engine/NexPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ public final void error(@NotNull String msg) {
171171
this.logger.severe(msg);
172172
}
173173

174+
public final void debug(@NotNull String msg) {
175+
this.info("[DEBUG] " + msg);
176+
}
177+
174178
private void unregisterListeners() {
175179
for (Player player : this.getServer().getOnlinePlayers()) {
176180
Menu<?> menu = Menu.getMenu(player);

engine/src/main/java/t/me/p1azmer/engine/Version.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum Version {
1414
V1_19_R3("1.19.4"),
1515
V1_20_R1("1.20.1"),
1616
V1_20_R2("1.20.2"),
17+
V1_20_R3("1.20.4"),
1718
UNKNOWN("Unknown", true),
1819
// API-Version in plugin.yml won't allow to load this on lower version, so
1920
// assume any other version not listed here is newer one.

engine/src/main/java/t/me/p1azmer/engine/api/config/JOption.java

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,79 +31,103 @@ public class JOption<T> {
3131
protected Writer<T> writer;
3232
protected Reader<T> reader;
3333

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

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

42-
public JOption(@NotNull String path, @Nullable Writer<T> writer, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
42+
public JOption(@NotNull String path, @NotNull Writer<T> writer, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
4343
this.path = path;
4444
this.description = description == null ? new String[0] : description;
45+
this.writer = writer;
4546
this.reader = reader;
4647
this.defaultValue = defaultValue;
4748
}
4849

4950
@NotNull
50-
public static <T> JOption<T> create(@NotNull ConfigKey<T> key, @NotNull T defaultValue, @Nullable String... description) {
51-
return new JOption<>(key.getPath(), key.getWriter(), key.getReader(), defaultValue, description);
51+
public static <T> JOption<T> create(@NotNull String path,
52+
@NotNull Writer<T> writer,
53+
@NotNull Reader<T> reader,
54+
@NotNull T defaultValue,
55+
@Nullable String... description) {
56+
return new JOption<>(path, writer, reader, defaultValue, description);
57+
}
58+
59+
@NotNull
60+
public static <T> JOption<T> create(@NotNull String path,
61+
@NotNull Writer<T> writer,
62+
@NotNull Reader<T> reader,
63+
@NotNull Supplier<T> defaultValue,
64+
@Nullable String... description) {
65+
return create(path, writer, reader, defaultValue.get(), description);
66+
}
67+
68+
@NotNull
69+
public static <T> JOption<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull T defaultValue, @Nullable String... description) {
70+
return create(path, JYML::set, reader, defaultValue, description);
71+
}
72+
73+
@NotNull
74+
public static <T> JOption<T> create(@NotNull String path, @NotNull Reader<T> reader, @NotNull Supplier<T> defaultValue, @Nullable String... description) {
75+
return create(path, JYML::set, reader, defaultValue, description);
5276
}
5377

5478
@NotNull
5579
public static JOption<Boolean> create(@NotNull String path, boolean defaultValue, @Nullable String... description) {
56-
return new JOption<>(path, READER_BOOLEAN, defaultValue, description);
80+
return create(path, READER_BOOLEAN, defaultValue, description);
5781
}
5882

5983
@NotNull
6084
public static JOption<Integer> create(@NotNull String path, int defaultValue, @Nullable String... description) {
61-
return new JOption<>(path, READER_INT, defaultValue, description);
85+
return create(path, READER_INT, defaultValue, description);
6286
}
6387

6488
@NotNull
6589
public static JOption<Double> create(@NotNull String path, double defaultValue, @Nullable String... description) {
66-
return new JOption<>(path, READER_DOUBLE, defaultValue, description);
90+
return create(path, READER_DOUBLE, defaultValue, description);
6791
}
6892

6993
@NotNull
7094
public static JOption<Long> create(@NotNull String path, long defaultValue, @Nullable String... description) {
71-
return new JOption<>(path, READER_LONG, defaultValue, description);
95+
return create(path, READER_LONG, defaultValue, description);
7296
}
7397

7498
@NotNull
7599
public static JOption<String> create(@NotNull String path, @NotNull String defaultValue, @Nullable String... description) {
76-
return new JOption<>(path, READER_STRING, defaultValue, description);
100+
return create(path, READER_STRING, defaultValue, description);
77101
}
78102

79103
@NotNull
80104
public static JOption<List<String>> create(@NotNull String path, @NotNull List<String> defaultValue, @Nullable String... description) {
81-
return new JOption<>(path, READER_LIST_STRING, defaultValue, description);
105+
return create(path, READER_LIST_STRING, defaultValue, description);
82106
}
83107

84108
@NotNull
85109
public static JOption<Set<String>> create(@NotNull String path, @NotNull Set<String> defaultValue, @Nullable String... description) {
86-
return new JOption<>(path, READER_SET_STRING, defaultValue, description);
110+
return create(path, READER_SET_STRING, defaultValue, description);
87111
}
88112

89113
@NotNull
90114
public static JOption<ItemStack> create(@NotNull String path, @NotNull ItemStack defaultValue, @Nullable String... description) {
91-
return new JOption<>(path, READER_ITEM, defaultValue, description).setWriter(JYML::setItem);
115+
return create(path, READER_ITEM, defaultValue, description).setWriter(JYML::setItem);
92116
}
93117

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

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

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

@@ -116,7 +140,7 @@ public static <V> JOption<Set<V>> forSet(@NotNull String path, @NotNull Function
116140
@NotNull
117141
public static <V> JOption<Set<V>> forSet(@NotNull String path, @NotNull Function<String, V> valFun,
118142
@NotNull Set<V> defaultValue, @Nullable String... description) {
119-
return new JOption<>(path,
143+
return create(path,
120144
(cfg, path1, def) -> cfg.getStringSet(path1).stream().map(valFun).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new)),
121145
defaultValue,
122146
description);
@@ -160,7 +184,7 @@ public static <K, V, M extends Map<K, V>> JOption<M> forMap(@NotNull String path
160184
@NotNull TriFunction<JYML, String, String, V> valFun,
161185
@NotNull Supplier<M> mapSupplier,
162186
@NotNull M defaultValue, @Nullable String... description) {
163-
return new JOption<>(path,
187+
return create(path,
164188
(cfg, path1, def) -> {
165189
M map = mapSupplier.get();
166190
for (String id : cfg.getSection(path1)) {
@@ -228,6 +252,7 @@ public Reader<T> getReader() {
228252
}
229253

230254
@NotNull
255+
@Deprecated
231256
public JOption<T> mapReader(@NotNull UnaryOperator<T> operator) {
232257
if (this.reader == null) return this;
233258

engine/src/main/java/t/me/p1azmer/engine/api/config/JYML.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,12 @@ public Location getLocation(@NotNull String path) {
224224
}
225225

226226
public int[] getIntArray(@NotNull String path) {
227-
int[] slots = new int[0];
227+
return getIntArray(path, new int[0]);
228+
}
228229

230+
public int @NotNull [] getIntArray(@NotNull String path, int[] def) {
229231
String str = this.getString(path);
230-
return str == null ? slots : StringUtil.getIntArray(str);
232+
return str == null ? def : StringUtil.getIntArray(str);
231233
}
232234

233235
public void setIntArray(@NotNull String path, int[] arr) {

engine/src/main/java/t/me/p1azmer/engine/api/data/AbstractUser.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,61 @@
1010

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

13-
protected transient final P plugin;
14-
private transient boolean isRecent = false;
15-
13+
protected final P plugin;
1614
protected final UUID uuid;
15+
1716
protected String name;
18-
protected long dateCreated;
19-
protected long lastOnline;
17+
protected long dateCreated;
18+
protected long lastOnline;
19+
protected long cachedUntil;
20+
21+
@Deprecated private boolean isRecent = false;
2022

2123
public AbstractUser(@NotNull P plugin, @NotNull UUID uuid, @NotNull String name, long dateCreated, long lastOnline) {
2224
this.plugin = plugin;
2325
this.uuid = uuid;
2426
this.name = name;
2527
this.setDateCreated(dateCreated);
2628
this.setLastOnline(lastOnline);
29+
this.setCachedUntil(-1);
30+
}
31+
32+
public void onLoad() {
33+
2734
}
2835

29-
public void onLoad() {}
36+
public void onUnload() {
3037

31-
public void onUnload() {}
38+
}
3239

3340
@SuppressWarnings("unchecked")
3441
@Deprecated
3542
public <U extends AbstractUser<P>> void saveData(@NotNull UserDataHolder<P, U> dataHolder) {
3643
this.plugin.runTaskAsync(task -> dataHolder.getData().saveUser((U) this));
3744
}
3845

46+
@Deprecated
3947
public boolean isRecentlyCreated() {
4048
return isRecent;
4149
}
4250

51+
@Deprecated
4352
public void setRecentlyCreated(boolean recent) {
4453
isRecent = recent;
4554
}
4655

56+
public boolean isCacheExpired() {
57+
return this.getCachedUntil() > 0 && System.currentTimeMillis() > this.getCachedUntil();
58+
}
59+
60+
public long getCachedUntil() {
61+
return cachedUntil;
62+
}
63+
64+
public void setCachedUntil(long cachedUntil) {
65+
this.cachedUntil = cachedUntil;
66+
}
67+
4768
@NotNull
4869
public final UUID getId() {
4970
return this.uuid;
@@ -54,7 +75,7 @@ public final String getName() {
5475
return this.name;
5576
}
5677

57-
void setName(@NotNull String name) {
78+
void setName(String name) {
5879
this.name = name;
5980
}
6081

0 commit comments

Comments
 (0)