Downgrade to java8 for 1.16.5

This commit is contained in:
alexcrea 2024-06-15 13:41:46 +02:00
parent 1e644f0a94
commit 9e53755c0c
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
2 changed files with 53 additions and 33 deletions

View file

@ -9,21 +9,32 @@ import xyz.alexcrea.cuanvil.config.ConfigHolderEnum;
import java.util.List;
public record 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
){
public class AtomicUpdate{
private static final String UPDATE_TYPE = "type";
private static final String CONFIG_TYPE_PATH = "config_type";
private static final String PATH_PATH = "path";
private static final String EXPECTED_PATH = "expected";
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){
String typeString = section.getString(UPDATE_TYPE);
String configTypeString = section.getString(CONFIG_TYPE_PATH);
@ -64,25 +75,23 @@ public record AtomicUpdate (
}
public boolean isExpected(boolean ignoreIfOperationIsDone){
String value;
List<String> values;
switch (this.type){
case SET -> {
String value = this.configType.getConfigHolder().getConfig().getString(this.path);
case SET:
value = this.configType.getConfigHolder().getConfig().getString(this.path);
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && isStringEqual(value, this.value));
}
case UNSET -> {
String value = this.configType.getConfigHolder().getConfig().getString(this.path);
case UNSET:
value = this.configType.getConfigHolder().getConfig().getString(this.path);
return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && (value == null));
}
case LIST_ADD -> {
List<String> values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
case LIST_ADD:
values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
return ignoreIfOperationIsDone || !values.contains(this.value);
}
case LIST_REMOVE -> {
List<String> values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
case LIST_REMOVE:
values = this.configType.getConfigHolder().getConfig().getStringList(this.path);
return ignoreIfOperationIsDone || values.contains(this.value);
}
}
return false;
}
@ -95,23 +104,24 @@ public record AtomicUpdate (
ConfigHolder configHolder = this.configType.getConfigHolder();
FileConfiguration config = configHolder.getConfig();
List<String> values;
switch (this.type){
case SET -> {
case SET:
config.set(this.path, this.value);
}
case UNSET -> {
break;
case UNSET:
config.set(this.path, null);
}
case LIST_ADD -> {
List<String> values = config.getStringList(this.path);
break;
case LIST_ADD:
values = config.getStringList(this.path);
values.add(this.value);
config.set(this.path, this.value);
}
case LIST_REMOVE -> {
List<String> values = config.getStringList(this.path);
break;
case LIST_REMOVE:
values = config.getStringList(this.path);
values.remove(this.value);
config.set(this.path, this.value);
}
break;
}
return true;

View file

@ -4,7 +4,16 @@ import com.google.common.primitives.Ints;
import org.jetbrains.annotations.NotNull;
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){
if(version == null) return null;
@ -52,7 +61,8 @@ public record Version(int major, int minor, int build) implements Comparable<Ver
@Override
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 false;