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

Commit

Permalink
v2.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nulli0n committed Nov 16, 2022
1 parent 48ea297 commit 56cf60e
Show file tree
Hide file tree
Showing 33 changed files with 633 additions and 179 deletions.
2 changes: 1 addition & 1 deletion NMS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>NexEnginePlugin</artifactId>
<groupId>su.nexmedia</groupId>
<version>2.2.6</version>
<version>2.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
10 changes: 5 additions & 5 deletions NexEngine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>NexEnginePlugin</artifactId>
<groupId>su.nexmedia</groupId>
<version>2.2.6</version>
<version>2.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -99,22 +99,22 @@
<dependency>
<groupId>su.nexmedia</groupId>
<artifactId>NMS</artifactId>
<version>2.2.6</version>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>su.nexmedia</groupId>
<artifactId>NexEngineCompat_V1_17_R1</artifactId>
<version>2.2.6</version>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>su.nexmedia</groupId>
<artifactId>NexEngineCompat_V1_18_R2</artifactId>
<version>2.2.6</version>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>su.nexmedia</groupId>
<artifactId>NexEngineCompat_V1_19_R1</artifactId>
<version>2.2.6</version>
<version>2.2.7</version>
</dependency>
</dependencies>

Expand Down
3 changes: 3 additions & 0 deletions NexEngine/src/main/java/su/nexmedia/engine/NexEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.actions.ActionsManager;
import su.nexmedia.engine.api.command.GeneralCommand;
import su.nexmedia.engine.api.menu.MenuItemType;
import su.nexmedia.engine.config.EngineConfig;
import su.nexmedia.engine.craft.CraftManager;
import su.nexmedia.engine.editor.EditorManager;
Expand Down Expand Up @@ -141,6 +142,8 @@ public void loadConfig() {
@Override
public void loadLang() {
this.getLangManager().loadMissing(EngineLang.class);
this.getLangManager().setupEditorEnum(MenuItemType.class);
this.getLang().saveChanges();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.regex.Pattern;

// TODO Remove abstraction
public abstract class AbstractParameter<T> {

protected final String name;
Expand Down Expand Up @@ -33,5 +34,6 @@ public final String getFlag() {
}

@NotNull
@Deprecated // TODO Create field, move in constructor
public abstract IParameterValueParser<T> getParser();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import su.nexmedia.engine.actions.parameter.AbstractParameter;
import su.nexmedia.engine.actions.parameter.parser.IParameterValueParser;

@Deprecated // TODO Move in Paramter class as static constructor.
public class ParameterDefaultBoolean extends AbstractParameter<Boolean> {

public ParameterDefaultBoolean(@NotNull String key, @NotNull String flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import su.nexmedia.engine.actions.parameter.parser.IParameterValueParser;
import su.nexmedia.engine.actions.parameter.value.ParameterValueNumber;

@Deprecated // TODO Move in Paramter class as static constructor.
public class ParameterDefaultNumber extends AbstractParameter<ParameterValueNumber> {

public ParameterDefaultNumber(@NotNull String key, @NotNull String flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import su.nexmedia.engine.actions.parameter.AbstractParameter;
import su.nexmedia.engine.actions.parameter.parser.IParameterValueParser;

@Deprecated // TODO Move in Paramter class as static constructor.
public class ParameterDefaultString extends AbstractParameter<String> {

public ParameterDefaultString(@NotNull String key, @NotNull String flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.utils.StringUtil;

@Deprecated // TODO Move in Parameter class
public interface IParameterValueParser<T> {

ParameterParserString STRING = new ParameterParserString();
ParameterParserBoolean BOOLEAN = new ParameterParserBoolean();
IParameterValueParser<String> STRING = StringUtil::color;
IParameterValueParser<Boolean> BOOLEAN = Boolean::parseBoolean;
ParameterParserNumber NUMBER = new ParameterParserNumber();

@Nullable T parse(@NotNull String str);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import su.nexmedia.engine.actions.parameter.value.ParameterValueNumber;
import su.nexmedia.engine.utils.StringUtil;

@Deprecated
public class ParameterParserNumber implements IParameterValueParser<ParameterValueNumber> {

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.NotNull;

@Deprecated
public class ParameterValueNumber {

private double value;
Expand Down
126 changes: 126 additions & 0 deletions NexEngine/src/main/java/su/nexmedia/engine/api/config/JOption.java
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);
}
}
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);
}
Loading

0 comments on commit 56cf60e

Please sign in to comment.