This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nulli0n
committed
Nov 16, 2022
1 parent
48ea297
commit 56cf60e
Showing
33 changed files
with
633 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
...ine/src/main/java/su/nexmedia/engine/actions/parameter/parser/ParameterParserBoolean.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
...gine/src/main/java/su/nexmedia/engine/actions/parameter/parser/ParameterParserString.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
NexEngine/src/main/java/su/nexmedia/engine/api/config/JOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package su.nexmedia.engine.api.config; | ||
|
||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import su.nexmedia.engine.utils.StringUtil; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
public class JOption<T> { | ||
|
||
public static final ValueLoader<Boolean> LOADER_BOOLEAN = JYML::getBoolean; | ||
public static final ValueLoader<Integer> LOADER_INT = JYML::getInt; | ||
public static final ValueLoader<Double> LOADER_DOUBLE = JYML::getDouble; | ||
public static final ValueLoader<Long> LOADER_LONG = JYML::getLong; | ||
public static final ValueLoader<String> LOADER_STRING = (cfg, path, def) -> StringUtil.color(cfg.getString(path, def)); | ||
public static final ValueLoader<Set<String>> LOADER_SET_STRING = (cfg, path, def) -> StringUtil.color(cfg.getStringSet(path)); | ||
public static final ValueLoader<List<String>> LOADER_LIST_STRING = (cfg, path, def) -> StringUtil.color(cfg.getStringList(path)); | ||
public static final ValueLoader<ItemStack> LOADER_ITEM = JYML::getItem; | ||
|
||
protected final ValueLoader<T> valueLoader; | ||
protected final String path; | ||
protected final String[] description; | ||
protected final T defaultValue; | ||
protected T value; | ||
|
||
public JOption(@NotNull String path, @NotNull ValueLoader<T> valueLoader, @NotNull T defaultValue) { | ||
this(path, "", valueLoader, defaultValue); | ||
} | ||
|
||
public JOption(@NotNull String path, @NotNull String description, @NotNull ValueLoader<T> valueLoader, @NotNull Supplier<T> defaultValue) { | ||
this(path, description, valueLoader, defaultValue.get()); | ||
} | ||
|
||
public JOption(@NotNull String path, @NotNull String description, @NotNull ValueLoader<T> valueLoader, @NotNull T defaultValue) { | ||
this.path = path; | ||
this.description = description.split("\n"); | ||
this.valueLoader = valueLoader; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@NotNull | ||
public static JOption<Boolean> create(@NotNull String path, @NotNull String description, boolean defaultValue) { | ||
return new JOption<>(path, description, LOADER_BOOLEAN, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<Integer> create(@NotNull String path, @NotNull String description, int defaultValue) { | ||
return new JOption<>(path, description, LOADER_INT, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<Double> create(@NotNull String path, @NotNull String description, double defaultValue) { | ||
return new JOption<>(path, description, LOADER_DOUBLE, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<Long> create(@NotNull String path, @NotNull String description, long defaultValue) { | ||
return new JOption<>(path, description, LOADER_LONG, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<String> create(@NotNull String path, @NotNull String description, @NotNull String defaultValue) { | ||
return new JOption<>(path, description, LOADER_STRING, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<List<String>> create(@NotNull String path, @NotNull String description, @NotNull List<String> defaultValue) { | ||
return new JOption<>(path, description, LOADER_LIST_STRING, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<Set<String>> create(@NotNull String path, @NotNull String description, @NotNull Set<String> defaultValue) { | ||
return new JOption<>(path, description, LOADER_SET_STRING, defaultValue); | ||
} | ||
|
||
@NotNull | ||
public static JOption<ItemStack> create(@NotNull String path, @NotNull String description, @NotNull ItemStack defaultValue) { | ||
return new JOption<>(path, description, LOADER_ITEM, defaultValue); | ||
} | ||
|
||
public void load(@NotNull JYML cfg) { | ||
cfg.addMissing(this.getPath(), this.getDefaultValue()); | ||
cfg.setComments(this.getPath(), this.getDescription()); | ||
this.value = this.valueLoader.loadFromConfig(cfg, this.getPath(), this.getDefaultValue()); | ||
} | ||
|
||
@NotNull | ||
public String getPath() { | ||
return path; | ||
} | ||
|
||
@NotNull | ||
public String[] getDescription() { | ||
return description; | ||
} | ||
|
||
@NotNull | ||
public ValueLoader<T> getValueLoader() { | ||
return valueLoader; | ||
} | ||
|
||
@NotNull | ||
public T getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@NotNull | ||
public T get() { | ||
return value; | ||
} | ||
|
||
public void set(@NotNull JYML cfg, @NotNull T value) { | ||
cfg.set(this.getPath(), value); | ||
} | ||
|
||
public void remove(@NotNull JYML cfg) { | ||
cfg.remove(this.getPath()); | ||
} | ||
|
||
public interface ValueLoader<T> { | ||
|
||
@NotNull T loadFromConfig(@NotNull JYML cfg, @NotNull String path, @NotNull T def); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
NexEngine/src/main/java/su/nexmedia/engine/api/config/JWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package su.nexmedia.engine.api.config; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface JWriter { | ||
|
||
void write(@NotNull JYML cfg, @NotNull String path); | ||
} |
Oops, something went wrong.