Add work penalty type

This commit is contained in:
alexcrea 2024-08-31 15:09:04 +02:00
parent 98172a11c9
commit 519ab1853c
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 85 additions and 5 deletions

View file

@ -0,0 +1,50 @@
package xyz.alexcrea.cuanvil.config;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public enum WorkPenaltyType {
DEFAULT("default", true, true),
INCREASE("increase_only", true, false),
ADDITIVE("add_only", false, true),
DISABLED("disabled", false, false),
;
private final String name;
private final boolean penaltyIncrease;
private final boolean penaltyAdditive;
WorkPenaltyType(String name, boolean penaltyIncrease, boolean penaltyAdditive) {
this.name = name;
this.penaltyIncrease = penaltyIncrease;
this.penaltyAdditive = penaltyAdditive;
}
public boolean isPenaltyIncreasing() {
return penaltyIncrease;
}
public boolean isPenaltyAdditive() {
return penaltyAdditive;
}
private boolean doRepresentThisType(String toTest){
return name.equalsIgnoreCase(toTest);
}
@NotNull
public static WorkPenaltyType fromString(@Nullable String toTest){
if(toTest == null) return DEFAULT;
// Test if it matches any of values
for (WorkPenaltyType value : values()) {
if(value.doRepresentThisType(toTest)){
return value;
}
}
// Use default if not found
return DEFAULT;
}
}