mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Downgrade to java8 for 1.16.5
This commit is contained in:
parent
1e644f0a94
commit
9e53755c0c
2 changed files with 53 additions and 33 deletions
|
|
@ -9,21 +9,32 @@ import xyz.alexcrea.cuanvil.config.ConfigHolderEnum;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record AtomicUpdate (
|
public class AtomicUpdate{
|
||||||
@NotNull AtomicUpdateType type,
|
|
||||||
@NotNull ConfigHolderEnum configType,
|
|
||||||
@NotNull String path,
|
|
||||||
@Nullable String expected, // Ignored on list
|
|
||||||
@Nullable String value // Ignored on unset. not null if not unset
|
|
||||||
|
|
||||||
){
|
|
||||||
|
|
||||||
private static final String UPDATE_TYPE = "type";
|
private static final String UPDATE_TYPE = "type";
|
||||||
private static final String CONFIG_TYPE_PATH = "config_type";
|
private static final String CONFIG_TYPE_PATH = "config_type";
|
||||||
private static final String PATH_PATH = "path";
|
private static final String PATH_PATH = "path";
|
||||||
private static final String EXPECTED_PATH = "expected";
|
private static final String EXPECTED_PATH = "expected";
|
||||||
private static final String VALUE_PATH = "value";
|
private static final String VALUE_PATH = "value";
|
||||||
|
|
||||||
|
private final @NotNull AtomicUpdateType type;
|
||||||
|
private final @NotNull ConfigHolderEnum configType;
|
||||||
|
private final @NotNull String path;
|
||||||
|
private final @Nullable String expected; // Ignored on list
|
||||||
|
private final @Nullable String value; // Ignored on unset. not null if not unset
|
||||||
|
|
||||||
|
public AtomicUpdate(
|
||||||
|
@NotNull AtomicUpdateType type,
|
||||||
|
@NotNull ConfigHolderEnum configType,
|
||||||
|
@NotNull String path,
|
||||||
|
@Nullable String expected, // Ignored on list
|
||||||
|
@Nullable String value) {
|
||||||
|
this.type = type;
|
||||||
|
this.configType = configType;
|
||||||
|
this.path = path;
|
||||||
|
this.expected = expected;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
public static @Nullable AtomicUpdate fromConfig(@NotNull ConfigurationSection section){
|
public static @Nullable AtomicUpdate fromConfig(@NotNull ConfigurationSection section){
|
||||||
String typeString = section.getString(UPDATE_TYPE);
|
String typeString = section.getString(UPDATE_TYPE);
|
||||||
String configTypeString = section.getString(CONFIG_TYPE_PATH);
|
String configTypeString = section.getString(CONFIG_TYPE_PATH);
|
||||||
|
|
@ -64,25 +75,23 @@ public record AtomicUpdate (
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpected(boolean ignoreIfOperationIsDone){
|
public boolean isExpected(boolean ignoreIfOperationIsDone){
|
||||||
|
String value;
|
||||||
|
List<String> values;
|
||||||
switch (this.type){
|
switch (this.type){
|
||||||
case SET -> {
|
case SET:
|
||||||
String value = this.configType.getConfigHolder().getConfig().getString(this.path);
|
value = this.configType.getConfigHolder().getConfig().getString(this.path);
|
||||||
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && isStringEqual(value, this.value));
|
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && isStringEqual(value, this.value));
|
||||||
}
|
case UNSET:
|
||||||
case UNSET -> {
|
value = this.configType.getConfigHolder().getConfig().getString(this.path);
|
||||||
String value = this.configType.getConfigHolder().getConfig().getString(this.path);
|
|
||||||
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && (value == null));
|
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && (value == null));
|
||||||
}
|
case LIST_ADD:
|
||||||
case LIST_ADD -> {
|
values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
|
||||||
List<String> values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
|
|
||||||
return ignoreIfOperationIsDone || !values.contains(this.value);
|
return ignoreIfOperationIsDone || !values.contains(this.value);
|
||||||
}
|
|
||||||
|
|
||||||
case LIST_REMOVE -> {
|
case LIST_REMOVE:
|
||||||
List<String> values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
|
values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
|
||||||
return ignoreIfOperationIsDone || values.contains(this.value);
|
return ignoreIfOperationIsDone || values.contains(this.value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -95,23 +104,24 @@ public record AtomicUpdate (
|
||||||
ConfigHolder configHolder = this.configType.getConfigHolder();
|
ConfigHolder configHolder = this.configType.getConfigHolder();
|
||||||
FileConfiguration config = configHolder.getConfig();
|
FileConfiguration config = configHolder.getConfig();
|
||||||
|
|
||||||
|
List<String> values;
|
||||||
switch (this.type){
|
switch (this.type){
|
||||||
case SET -> {
|
case SET:
|
||||||
config.set(this.path, this.value);
|
config.set(this.path, this.value);
|
||||||
}
|
break;
|
||||||
case UNSET -> {
|
case UNSET:
|
||||||
config.set(this.path, null);
|
config.set(this.path, null);
|
||||||
}
|
break;
|
||||||
case LIST_ADD -> {
|
case LIST_ADD:
|
||||||
List<String> values = config.getStringList(this.path);
|
values = config.getStringList(this.path);
|
||||||
values.add(this.value);
|
values.add(this.value);
|
||||||
config.set(this.path, this.value);
|
config.set(this.path, this.value);
|
||||||
}
|
break;
|
||||||
case LIST_REMOVE -> {
|
case LIST_REMOVE:
|
||||||
List<String> values = config.getStringList(this.path);
|
values = config.getStringList(this.path);
|
||||||
values.remove(this.value);
|
values.remove(this.value);
|
||||||
config.set(this.path, this.value);
|
config.set(this.path, this.value);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,16 @@ import com.google.common.primitives.Ints;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public record Version(int major, int minor, int build) implements Comparable<Version>{
|
public class Version implements Comparable<Version>{
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int build;
|
||||||
|
|
||||||
|
public Version(int major, int minor, int build) {
|
||||||
|
this.major = major;
|
||||||
|
this.minor = minor;
|
||||||
|
this.build = build;
|
||||||
|
}
|
||||||
|
|
||||||
public static @Nullable Version versionOf(@Nullable String version){
|
public static @Nullable Version versionOf(@Nullable String version){
|
||||||
if(version == null) return null;
|
if(version == null) return null;
|
||||||
|
|
@ -52,7 +61,8 @@ public record Version(int major, int minor, int build) implements Comparable<Ver
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(obj instanceof Version other){
|
if(obj instanceof Version){
|
||||||
|
Version other = (Version) obj;
|
||||||
return (other.major == this.major) && (other.minor == this.minor) && (other.build == this.build);
|
return (other.major == this.major) && (other.minor == this.minor) && (other.build == this.build);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue