Moved operation classes into new package.
This commit is contained in:
@ -0,0 +1,28 @@
|
||||
package dev.micle.xptools.operation;
|
||||
|
||||
import dev.micle.xptools.util.EnumUtils;
|
||||
|
||||
public class GlobalOperationItem extends OperationItem {
|
||||
public GlobalOperationItem(OperationType type, float min, float max, int priority) {
|
||||
super(false, "", type, min, max, priority, false);
|
||||
}
|
||||
|
||||
public static GlobalOperationItem fromConfig(String configString) {
|
||||
String[] splitString = configString.split(",");
|
||||
|
||||
if (splitString.length == 4) {
|
||||
OperationType type = EnumUtils.valueOf(OperationType.class, splitString[0]);
|
||||
float min = Float.parseFloat(splitString[1]);
|
||||
float max = Float.parseFloat(splitString[2]);
|
||||
int priority = Integer.parseInt(splitString[3]);
|
||||
|
||||
return new GlobalOperationItem(type, min, max, priority);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s,%f,%f,%d", getType().toString(), getMin(), getMax(), getPriority());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package dev.micle.xptools.operation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class OperationCache {
|
||||
private static HashMap<String, List<OperationItem>> blockBreakCache;
|
||||
|
||||
public static void clearBlockBreakCache() {
|
||||
blockBreakCache = new HashMap<>();
|
||||
}
|
||||
|
||||
public static @Nullable List<OperationItem> getBlockBreakCacheEntry(String key) {
|
||||
if (blockBreakCache.containsKey(key)) {
|
||||
return new ArrayList<>(blockBreakCache.get(key));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addBlockBreakCacheEntry(String key, List<OperationItem> value) {
|
||||
blockBreakCache.putIfAbsent(key, new ArrayList<>(value));
|
||||
}
|
||||
}
|
84
src/main/java/dev/micle/xptools/operation/OperationItem.java
Normal file
84
src/main/java/dev/micle/xptools/operation/OperationItem.java
Normal file
@ -0,0 +1,84 @@
|
||||
package dev.micle.xptools.operation;
|
||||
|
||||
import dev.micle.xptools.util.EnumUtils;
|
||||
|
||||
public class OperationItem {
|
||||
private final boolean isTag;
|
||||
private final String id;
|
||||
private final OperationType type;
|
||||
private final float min;
|
||||
private final float max;
|
||||
private final int priority;
|
||||
private final boolean isLast;
|
||||
|
||||
public OperationItem(boolean isTag, String id, OperationType type, float min, float max, int priority, boolean isLast) {
|
||||
this.isTag = isTag;
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.priority = priority;
|
||||
this.isLast = isLast;
|
||||
}
|
||||
|
||||
public static OperationItem fromConfig(String configString) {
|
||||
String[] splitString = configString.split(",");
|
||||
|
||||
if (splitString.length == 6) {
|
||||
boolean isTag = splitString[0].startsWith("#");
|
||||
String id = isTag ? splitString[0].substring(1) : splitString[0];
|
||||
OperationType type = EnumUtils.valueOf(OperationType.class, splitString[1]);
|
||||
float min = Float.parseFloat(splitString[2]);
|
||||
float max = Float.parseFloat(splitString[3]);
|
||||
int priority = Integer.parseInt(splitString[4]);
|
||||
boolean isLast = Boolean.parseBoolean(splitString[5]);
|
||||
|
||||
return new OperationItem(isTag, id, type, min, max, priority, isLast);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (isTag) {
|
||||
builder.append("#");
|
||||
}
|
||||
builder
|
||||
.append(id).append(",")
|
||||
.append(type.toString()).append(",")
|
||||
.append(min).append(",").append(max).append(",")
|
||||
.append(priority).append(",")
|
||||
.append(isLast);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public boolean isTag() {
|
||||
return isTag;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public OperationType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public float getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public boolean isLast() {
|
||||
return isLast;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.micle.xptools.operation;
|
||||
|
||||
public enum OperationType {
|
||||
SET,
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
MULTIPLY,
|
||||
DIVIDE
|
||||
}
|
Reference in New Issue
Block a user