Skip to content

Commit

Permalink
1.6.21
Browse files Browse the repository at this point in the history
  • Loading branch information
ancap-kun committed Mar 30, 2023
1 parent 04387f2 commit 81967d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Artifex/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>Artifex</artifactId>
<name>Artifex</name>
<version>1.6.20</version>
<version>1.6.21</version>
<description>AncapAPI runtime part</description>
<build>
<finalName>artifex-v${version}</finalName>
Expand Down
2 changes: 1 addition & 1 deletion Artifex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<packaging>jar</packaging>

<artifactId>Artifex</artifactId>
<version>1.6.20</version>
<version>1.6.21</version>

<name>Artifex</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class ConfigurationDatabase implements PathDatabase {

public static PathDatabase plugin(JavaPlugin plugin) {
return ConfigurationDatabase.builder()
.plugin(plugin)
.build();
.plugin(plugin)
.build();
}

public static Builder builder() {
Expand Down Expand Up @@ -81,11 +81,11 @@ public Builder autoSave(long period) {
@SneakyThrows
protected PathDatabase build() {
return new ConfigurationDatabase(
this.config,
this.file,
"",
this.autoSave,
this.autoSavePeriod
this.config,
this.file,
"",
this.autoSave,
this.autoSavePeriod
);
}

Expand Down Expand Up @@ -165,18 +165,15 @@ private void set(String path, Object object) {
@NonBlocking
@Override public void save() {
this.modifyExecutor.execute(() -> {
try {
this.configuration.save(this.file);
} catch (IOException e) {
throw new RuntimeException(e);
}
try { this.configuration.save(this.file); }
catch (IOException e) { throw new RuntimeException(e); }
});
}

@ContextAware(handle = InsecureContextHandle.NO_HANDLE, awareOf = Aware.THREAD)
private void scheduleSave() {
if (ConfigurationDatabase.this.isScheduled) return;
this.next(
this.scheduleTask(
ConfigurationDatabase.this.autoSavePeriod - (System.currentTimeMillis() - ConfigurationDatabase.this.lastSave),
new TimerTask() {
@Override public void run() {
Expand All @@ -191,7 +188,7 @@ private void scheduleSave() {
}


private void next(long waitTime, TimerTask timerTask) {
private void scheduleTask(long waitTime, TimerTask timerTask) {
if (waitTime <= 0) timerTask.run();
else ConfigurationDatabase.this.timer.schedule(timerTask, waitTime);
}
Expand All @@ -216,6 +213,16 @@ private void performActionsAtModify() {
return this.withCurrentPath(this.attachedPath(path));
}

@Override public boolean isSet(String path) {
return this.configuration.isSet(this.attachedPath(path));
}

@Override public @NotNull Set<String> keys() {
ConfigurationSection section = this.configuration.getConfigurationSection(this.currentPath);
if (section == null) return Set.of();
return section.getKeys(false);
}

@Override public @Nullable String readString(String path) {
Object value = this.configuration.get(this.attachedPath(path));
if (value == null) return null;
Expand Down Expand Up @@ -260,16 +267,6 @@ private void performActionsAtModify() {
return List.copyOf(strings);
}

@Override public @Nullable Set<String> readKeys(String path) {
ConfigurationSection section = this.configuration.getConfigurationSection(this.attachedPath(path));
if (section == null) return null;
return section.getKeys(false);
}

@Override public boolean isSet(String path) {
return this.configuration.isSet(this.attachedPath(path));
}

private String attachedPath(@NotNull String path) {
return path.equals("") ? this.currentPath : this.currentPath+"."+path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
import lombok.experimental.StandardException;

@StandardException
public class DifferentDatatypeException extends RuntimeException {
}
public class DifferentDatatypeException extends RuntimeException {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,23 @@ static PathDatabase configuration(JavaPlugin plugin) {
void write(String path, ItemStack value);

@NotNull PathDatabase inner(String path);
boolean isSet(String path);
@NotNull Set<String> keys();

@Nullable String readString(String path);
@Nullable ItemStack readItemStack(String path);
@Nullable Boolean readBoolean(String path);
@Nullable Long readInteger(String path);
@Nullable Double readNumber(String path);
@Nullable List<String> readStrings(String path);
@Nullable Set<String> readKeys(String path);
@Nullable String readString (String path);
@Nullable ItemStack readItemStack (String path);
@Nullable Boolean readBoolean (String path);
@Nullable Long readInteger (String path);
@Nullable Double readNumber (String path);
@Nullable List<String> readStrings (String path);

default List<String> readStrings(String path, boolean nullIsEmpty) {
List<String> strings = this.readStrings(path);
if (strings == null && nullIsEmpty) strings = List.of();
return strings;
}

default Set<String> readKeys(String path, boolean nullIsEmpty) {
Set<String> keys = this.readKeys(path);
if (keys == null && nullIsEmpty) keys = Set.of();
return keys;
}

boolean isSet(String path);

default void add(String path, String value) {
this.add(path, value, false);
}
default void add(String path, String value) { this.add(path, value, false); }

default void add(String path, String value, boolean nullIsEmpty) {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
Expand All @@ -63,9 +54,7 @@ default void add(String path, String value, boolean nullIsEmpty) {
this.write(path, list);
}

default void remove(String path, String value) {
this.remove(path, value, false);
}
default void remove(String path, String value) { this.remove(path, value, false); }

default void remove(String path, String value, boolean nullIsEmpty) throws NoSuchElementException {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
Expand All @@ -76,9 +65,7 @@ default void remove(String path, String value, boolean nullIsEmpty) throws NoSuc
this.write(path, list);
}

default boolean contains(String path, String value) {
return this.contains(path, value, false);
}
default boolean contains(String path, String value) { return this.contains(path, value, false); }

default boolean contains(String path, String value, boolean nullIsEmpty) {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
Expand Down

0 comments on commit 81967d5

Please sign in to comment.