Upload files to "src/openonyx/history/internal"
This commit is contained in:
1 parent
8d3ce6856e
commit
77493827f8
5 files changed
+950
No files matched your search
@@ -0,0 +1,171 @@
|
|||||||
|
package openonyx.history.internal;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import openonyx.history.SettingValue;
|
||||||
|
import openonyx.utilities.ItemSpec;
|
||||||
|
|
||||||
|
public class ItemListSetting extends SettingValue<List<ItemSpec>> {
|
||||||
|
public ItemListSetting describe(String string) {
|
||||||
|
super.describe(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void D(ItemSpec itemSpec) {
|
||||||
|
if (this.L(itemSpec)) {
|
||||||
|
this.L(itemSpec);
|
||||||
|
} else {
|
||||||
|
this.d(itemSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemListSetting visibleWhen(SettingValue<Boolean> settingValue) {
|
||||||
|
super.visibleWhen(settingValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemListSetting(String string, String... strings) {
|
||||||
|
super(string, L(strings));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean L(ItemStack itemStack) {
|
||||||
|
ItemListSetting itemListSetting1 = this;
|
||||||
|
Iterator iterator = itemListSetting1.getValue().iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
if (((ItemSpec)iterator.next()).L(itemStack)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void d(ItemSpec itemSpec) {
|
||||||
|
if (itemSpec != null && !this.L(itemSpec)) {
|
||||||
|
ArrayList arrayList;
|
||||||
|
(arrayList = new ArrayList<>(this.getValue())).add(itemSpec);
|
||||||
|
this.setValue(arrayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<ItemSpec> L(String... strings) {
|
||||||
|
String[] strings1 = strings;
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
String[] strings2 = strings1;
|
||||||
|
int j = strings1.length;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (int k = i = 0; k < j; k = ++i) {
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = ItemSpec.d(strings2[i])) != null && !arrayList.contains(itemSpec)) {
|
||||||
|
arrayList.add(itemSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemListSetting visibleWhen(BooleanSupplier booleanSupplier) {
|
||||||
|
super.visibleWhen(booleanSupplier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemListSetting onChange(Consumer<List<ItemSpec>> consumer) {
|
||||||
|
super.onChange(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJson() {
|
||||||
|
ItemListSetting itemListSetting1 = this;
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
Iterator iterator;
|
||||||
|
Iterator iterator1 = iterator = itemListSetting1.getValue().iterator();
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
ItemSpec itemSpec = (ItemSpec)iterator.next();
|
||||||
|
iterator1 = iterator;
|
||||||
|
jsonArray.add(new JsonPrimitive(itemSpec.L()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<ItemSpec> L(List<ItemSpec> list) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
if (list == null) {
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator iterator = list.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = (ItemSpec)iterator.next()) != null && !arrayList.contains(itemSpec)) {
|
||||||
|
arrayList.add(itemSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <O> ItemListSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
|
||||||
|
super.visibleWhen(settingValue, predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJson(JsonElement jsonElement) {
|
||||||
|
ItemListSetting itemListSetting1 = this;
|
||||||
|
if (jsonElement.isJsonArray()) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
Iterator iterator = jsonElement.getAsJsonArray().iterator();
|
||||||
|
|
||||||
|
label31:
|
||||||
|
while (true) {
|
||||||
|
for (Iterator iterator1 = iterator; iterator1.hasNext(); iterator1 = iterator) {
|
||||||
|
JsonElement jsonElement1;
|
||||||
|
if (!(jsonElement1 = (JsonElement)iterator.next()).isJsonPrimitive()) {
|
||||||
|
continue label31;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonElement1.getAsJsonPrimitive().isString()) {
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = ItemSpec.d(jsonElement1.getAsString())) != null && !arrayList.contains(itemSpec)) {
|
||||||
|
arrayList.add(itemSpec);
|
||||||
|
}
|
||||||
|
continue label31;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemListSetting1.setValue(arrayList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void L(ItemSpec itemSpec) {
|
||||||
|
if (itemSpec != null && this.L(itemSpec)) {
|
||||||
|
ArrayList arrayList;
|
||||||
|
(arrayList = new ArrayList<>(this.getValue())).remove(itemSpec);
|
||||||
|
this.setValue(arrayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean L(ItemSpec itemSpec) {
|
||||||
|
return this.getValue().contains(itemSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void D() {
|
||||||
|
this.setValue(new ArrayList<>());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,319 @@
|
|||||||
|
package openonyx.history.internal;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import openonyx.history.SettingValue;
|
||||||
|
import openonyx.utilities.ItemSpec;
|
||||||
|
|
||||||
|
public class ItemMappingSetting extends SettingValue<Map<Integer, List<ItemSpec>>> {
|
||||||
|
public static final int e = 9;
|
||||||
|
|
||||||
|
public void D() {
|
||||||
|
this.setValue(new LinkedHashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMappingSetting describe(String string) {
|
||||||
|
super.describe(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void d(int i, ItemSpec itemSpec) {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
if (itemSpec != null && itemMappingSetting1.L(i).contains(itemSpec)) {
|
||||||
|
List list;
|
||||||
|
Map map;
|
||||||
|
if ((list = (List)(map = itemMappingSetting1.L()).get(i)) != null) {
|
||||||
|
list.remove(itemSpec);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
map.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMappingSetting1.setValue(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void L(int i) {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
if (!itemMappingSetting1.L(i).isEmpty()) {
|
||||||
|
Map map;
|
||||||
|
(map = itemMappingSetting1.L()).remove(i);
|
||||||
|
itemMappingSetting1.setValue(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int L(ItemStack itemStack) {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
int i = -1;
|
||||||
|
|
||||||
|
label34:
|
||||||
|
for (int k = j = 0; k < 9; k = ++j) {
|
||||||
|
Iterator iterator = itemMappingSetting1.L(j).iterator();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Iterator iterator1 = iterator;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (!iterator1.hasNext()) {
|
||||||
|
continue label34;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = (ItemSpec)iterator.next()).L(itemStack)) {
|
||||||
|
if (itemSpec.L()) {
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator1 = iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean L(int i, ItemStack itemStack) {
|
||||||
|
Iterator iterator = this.L(i).iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
if (((ItemSpec)iterator.next()).L(itemStack)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Integer, List<ItemSpec>> L() {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||||
|
|
||||||
|
Iterator iterator;
|
||||||
|
for (Iterator iterator1 = iterator = itemMappingSetting1.getValue().entrySet().iterator(); iterator1.hasNext(); iterator1 = iterator) {
|
||||||
|
Entry entry = (Entry)iterator.next();
|
||||||
|
linkedHashMap.put((Integer)entry.getKey(), new ArrayList((Collection)entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return linkedHashMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMappingSetting onChange(Consumer<Map<Integer, List<ItemSpec>>> consumer) {
|
||||||
|
super.onChange(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<Integer, List<ItemSpec>> L(Map<Integer, List<ItemSpec>> map) {
|
||||||
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||||
|
if (map == null) {
|
||||||
|
return linkedHashMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (int j = i = 0; j < 9; j = ++i) {
|
||||||
|
List list;
|
||||||
|
if ((list = (List)map.get(i)) != null) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
Iterator iterator = list.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = (ItemSpec)iterator.next()) != null && !arrayList.contains(itemSpec)) {
|
||||||
|
arrayList.add(itemSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!arrayList.isEmpty()) {
|
||||||
|
linkedHashMap.put(i, arrayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return linkedHashMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ItemSpec> L(int i) {
|
||||||
|
List list;
|
||||||
|
return (list = this.getValue().get(i)) == null ? List.of() : list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void L(int i, ItemSpec itemSpec) {
|
||||||
|
if (itemSpec != null && i >= 0 && i < 9) {
|
||||||
|
if (!this.L(i).contains(itemSpec)) {
|
||||||
|
Map map;
|
||||||
|
(map = this.L()).computeIfAbsent(i, integer -> new ArrayList<>()).add(itemSpec);
|
||||||
|
this.setValue(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJson(JsonElement jsonElement) {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
if (jsonElement.isJsonObject()) {
|
||||||
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||||
|
Iterator iterator1 = jsonElement.getAsJsonObject().entrySet().iterator();
|
||||||
|
|
||||||
|
label65:
|
||||||
|
while (true) {
|
||||||
|
Iterator iterator3 = iterator1;
|
||||||
|
|
||||||
|
while (iterator3.hasNext()) {
|
||||||
|
Entry entry = (Entry)iterator1.next();
|
||||||
|
|
||||||
|
int i;
|
||||||
|
try {
|
||||||
|
i = Integer.parseInt((String)entry.getKey());
|
||||||
|
} catch (NumberFormatException numberFormatException) {
|
||||||
|
iterator3 = iterator1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < 0 || i >= 9) {
|
||||||
|
continue label65;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((JsonElement)entry.getValue()).isJsonArray()) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
Iterator iterator = ((JsonElement)entry.getValue()).getAsJsonArray().iterator();
|
||||||
|
|
||||||
|
label54:
|
||||||
|
while (true) {
|
||||||
|
for (Iterator iterator2 = iterator; iterator2.hasNext(); iterator2 = iterator) {
|
||||||
|
JsonElement jsonElement1;
|
||||||
|
if (!(jsonElement1 = (JsonElement)iterator.next()).isJsonPrimitive()) {
|
||||||
|
continue label54;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonElement1.getAsJsonPrimitive().isString()) {
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = ItemSpec.d(jsonElement1.getAsString())) != null && !arrayList.contains(itemSpec)) {
|
||||||
|
arrayList.add(itemSpec);
|
||||||
|
}
|
||||||
|
continue label54;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!arrayList.isEmpty()) {
|
||||||
|
linkedHashMap.put(i, arrayList);
|
||||||
|
}
|
||||||
|
continue label65;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator3 = iterator1;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMappingSetting1.setValue(linkedHashMap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean d() {
|
||||||
|
return this.getValue().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Integer, List<ItemSpec>> L(Object... objects) {
|
||||||
|
Object[] objects1 = objects;
|
||||||
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||||
|
|
||||||
|
byte b;
|
||||||
|
for (byte c = b = 0; c + 1 < objects1.length; c = b) {
|
||||||
|
int i = (Integer)objects1[b];
|
||||||
|
ItemSpec itemSpec;
|
||||||
|
if ((itemSpec = ItemSpec.d(String.valueOf(objects1[b + 1]))) != null && i >= 0 && i < 9) {
|
||||||
|
linkedHashMap.computeIfAbsent(i, integer -> new ArrayList<>()).add(itemSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
b += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return linkedHashMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMappingSetting visibleWhen(SettingValue<Boolean> settingValue) {
|
||||||
|
super.visibleWhen(settingValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <O> ItemMappingSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
|
||||||
|
super.visibleWhen(settingValue, predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMappingSetting visibleWhen(BooleanSupplier booleanSupplier) {
|
||||||
|
super.visibleWhen(booleanSupplier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMappingSetting(String string, Map<Integer, List<ItemSpec>> map) {
|
||||||
|
super(string, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJson() {
|
||||||
|
ItemMappingSetting itemMappingSetting1 = this;
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (int j = i = 0; j < 9; j = ++i) {
|
||||||
|
List list;
|
||||||
|
if (!(list = itemMappingSetting1.L(i)).isEmpty()) {
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
Iterator iterator;
|
||||||
|
Iterator iterator1 = iterator = list.iterator();
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
ItemSpec itemSpec = (ItemSpec)iterator.next();
|
||||||
|
iterator1 = iterator;
|
||||||
|
jsonArray.add(new JsonPrimitive(itemSpec.L()));
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonObject.add(String.valueOf(i), jsonArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void L(int i, int j, ItemSpec itemSpec) {
|
||||||
|
if (itemSpec != null && i != j && j >= 0 && j < 9) {
|
||||||
|
if (this.L(i).contains(itemSpec)) {
|
||||||
|
Map map;
|
||||||
|
List list;
|
||||||
|
if ((list = (List)(map = this.L()).get(i)) != null) {
|
||||||
|
list.remove(itemSpec);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
map.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List list1;
|
||||||
|
if (!(list1 = map.computeIfAbsent(j, integer -> new ArrayList())).contains(itemSpec)) {
|
||||||
|
list1.add(itemSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setValue(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package openonyx.history.internal;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import openonyx.features.ModuleState;
|
||||||
|
import openonyx.history.SettingValue;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
public class KeybindSetting extends SettingValue<Integer> {
|
||||||
|
public static final int H = 0;
|
||||||
|
private EnumSetting<ModuleState> bindMode;
|
||||||
|
|
||||||
|
public boolean matchesMouse(int i) {
|
||||||
|
return this.isBound() && this.getValue() < 0 && this.getValue() == -i - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting visibleWhen(BooleanSupplier booleanSupplier) {
|
||||||
|
super.visibleWhen(booleanSupplier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesKey(int i) {
|
||||||
|
return this.isBound() && this.getValue() == i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <O> KeybindSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
|
||||||
|
super.visibleWhen(settingValue, predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMouseButton() {
|
||||||
|
return this.isMouse() ? -this.getValue() - 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJson() {
|
||||||
|
return new JsonPrimitive(this.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting onChange(Consumer<Integer> consumer) {
|
||||||
|
super.onChange(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPressed() {
|
||||||
|
if (this.isKey()) {
|
||||||
|
return Keyboard.isKeyDown(this.getKeyCode());
|
||||||
|
} else {
|
||||||
|
return this.isMouse() ? Mouse.isButtonDown(this.getMouseButton()) : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
this.setValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKeyCode() {
|
||||||
|
return this.isKey() ? this.getValue() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting(String string, int i) {
|
||||||
|
super(string, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting withBindMode(EnumSetting<ModuleState> enumSetting) {
|
||||||
|
this.bindMode = enumSetting;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting describe(String string) {
|
||||||
|
super.describe(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumSetting<ModuleState> getBindMode() {
|
||||||
|
return this.bindMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bind(int i) {
|
||||||
|
if (i == 0) {
|
||||||
|
this.clear();
|
||||||
|
} else {
|
||||||
|
if (i > 0) {
|
||||||
|
this.setValue(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isKey() {
|
||||||
|
return this.isBound() && this.getValue() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBound() {
|
||||||
|
return this.getValue() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
KeybindSetting keybindSetting1 = this;
|
||||||
|
if (!keybindSetting1.isBound()) {
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keybindSetting1.isKey()) {
|
||||||
|
String string;
|
||||||
|
return (string = Keyboard.getKeyName(keybindSetting1.getValue())) == null ? "None" : string;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
switch (i = keybindSetting1.getMouseButton()) {
|
||||||
|
case 0:
|
||||||
|
while (false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return "LMB";
|
||||||
|
case 1:
|
||||||
|
return "RMB";
|
||||||
|
case 2:
|
||||||
|
return "MMB";
|
||||||
|
case 3:
|
||||||
|
return "Mouse 4";
|
||||||
|
case 4:
|
||||||
|
return "Mouse 5";
|
||||||
|
default:
|
||||||
|
return new StringBuilder().insert(0, "Mouse ").append(i + 1).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting(String string) {
|
||||||
|
this(string, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouse() {
|
||||||
|
return this.isBound() && this.getValue() < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJson(JsonElement jsonElement) {
|
||||||
|
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
|
||||||
|
this.setValue(jsonElement.getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeybindSetting visibleWhen(SettingValue<Boolean> settingValue) {
|
||||||
|
super.visibleWhen(settingValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindMouse(int i) {
|
||||||
|
if (i >= 0) {
|
||||||
|
this.setValue(-i - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package openonyx.history.internal;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import openonyx.history.SettingValue;
|
||||||
|
|
||||||
|
public class MultiEnumSetting<E extends Enum<E>> extends SettingValue<List<E>> {
|
||||||
|
private final Class<E> enumClass;
|
||||||
|
private final List<E> values;
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public MultiEnumSetting(String string, Class<E> class_, E... enums) {
|
||||||
|
super(string, List.of((E[])enums));
|
||||||
|
this.enumClass = class_;
|
||||||
|
this.values = List.of((E[])class_.getEnumConstants());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiEnumSetting<E> visibleWhen(SettingValue<Boolean> settingValue) {
|
||||||
|
super.visibleWhen(settingValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.getValue().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<E> getEnumClass() {
|
||||||
|
return this.enumClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJson() {
|
||||||
|
MultiEnumSetting multiEnumSetting1 = this;
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
Iterator iterator;
|
||||||
|
Iterator iterator1 = iterator = multiEnumSetting1.getValue().iterator();
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
Enum enum_ = (Enum)iterator.next();
|
||||||
|
iterator1 = iterator;
|
||||||
|
jsonArray.add(new JsonPrimitive(enum_.name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle(E enum_) {
|
||||||
|
MultiEnumSetting multiEnumSetting1 = this;
|
||||||
|
ArrayList arrayList;
|
||||||
|
if (!(arrayList = new ArrayList<>(multiEnumSetting1.getValue())).remove(enum_)) {
|
||||||
|
arrayList.add(enum_);
|
||||||
|
}
|
||||||
|
|
||||||
|
multiEnumSetting1.setValue(arrayList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(E enum_, boolean bl) {
|
||||||
|
if (this.contains((E)enum_) != bl) {
|
||||||
|
this.toggle((E)enum_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJson(JsonElement jsonElement) {
|
||||||
|
if (jsonElement.isJsonArray()) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
Iterator iterator1 = jsonElement.getAsJsonArray().iterator();
|
||||||
|
|
||||||
|
label37:
|
||||||
|
while (true) {
|
||||||
|
for (Iterator iterator2 = iterator1; iterator2.hasNext(); iterator2 = iterator1) {
|
||||||
|
JsonElement jsonElement1;
|
||||||
|
if (!(jsonElement1 = (JsonElement)iterator1.next()).isJsonPrimitive()) {
|
||||||
|
continue label37;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonElement1.getAsJsonPrimitive().isString()) {
|
||||||
|
String string = jsonElement1.getAsString();
|
||||||
|
Iterator iterator = this.values.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Enum enum_;
|
||||||
|
if ((enum_ = (Enum)iterator.next()).name().equals(string)) {
|
||||||
|
arrayList.add(enum_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue label37;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setValue(arrayList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(E enum_) {
|
||||||
|
return this.getValue().contains(enum_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<E> getValues() {
|
||||||
|
return this.values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiEnumSetting<E> visibleWhen(BooleanSupplier booleanSupplier) {
|
||||||
|
super.visibleWhen(booleanSupplier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(int i, int j) {
|
||||||
|
MultiEnumSetting multiEnumSetting1 = this;
|
||||||
|
List list = multiEnumSetting1.getValue();
|
||||||
|
if (i >= 0 && i < list.size()) {
|
||||||
|
if ((j = Math.clamp(j, 0, list.size() - 1)) != i) {
|
||||||
|
ArrayList arrayList;
|
||||||
|
Enum enum_ = (Enum)(arrayList = new ArrayList<>(list)).remove(i);
|
||||||
|
arrayList.add(j, enum_);
|
||||||
|
multiEnumSetting1.setValue(arrayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <O> MultiEnumSetting<E> visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
|
||||||
|
super.visibleWhen(settingValue, predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<E> sanitize(List<E> list) {
|
||||||
|
ArrayList arrayList = new ArrayList();
|
||||||
|
Iterator iterator = list.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Enum enum_;
|
||||||
|
if ((enum_ = (Enum)iterator.next()) != null && !arrayList.contains(enum_)) {
|
||||||
|
arrayList.add(enum_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return List.copyOf(arrayList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiEnumSetting<E> describe(String string) {
|
||||||
|
super.describe(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiEnumSetting<E> onChange(Consumer<List<E>> consumer) {
|
||||||
|
super.onChange(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package openonyx.history.internal;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import openonyx.history.SettingValue;
|
||||||
|
|
||||||
|
public class MultiSelectSetting<E extends Enum<E>> extends SettingValue<EnumSet<E>> {
|
||||||
|
private final Class<E> enumClass;
|
||||||
|
private final List<E> values;
|
||||||
|
private boolean allowEmpty = true;
|
||||||
|
|
||||||
|
public MultiSelectSetting<E> allowEmpty(boolean bl) {
|
||||||
|
this.allowEmpty = bl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJson(JsonElement jsonElement) {
|
||||||
|
if (jsonElement.isJsonArray()) {
|
||||||
|
EnumSet enumSet = EnumSet.noneOf(this.enumClass);
|
||||||
|
Iterator iterator1 = jsonElement.getAsJsonArray().iterator();
|
||||||
|
|
||||||
|
label37:
|
||||||
|
while (true) {
|
||||||
|
for (Iterator iterator2 = iterator1; iterator2.hasNext(); iterator2 = iterator1) {
|
||||||
|
JsonElement jsonElement1;
|
||||||
|
if (!(jsonElement1 = (JsonElement)iterator1.next()).isJsonPrimitive()) {
|
||||||
|
continue label37;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonElement1.getAsJsonPrimitive().isString()) {
|
||||||
|
String string = jsonElement1.getAsString();
|
||||||
|
Iterator iterator = this.values.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Enum enum_;
|
||||||
|
if ((enum_ = (Enum)iterator.next()).name().equals(string)) {
|
||||||
|
enumSet.add((E)enum_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue label37;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setValue(enumSet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(E enum_, boolean bl) {
|
||||||
|
if (this.contains((E)enum_) != bl) {
|
||||||
|
this.toggle((E)enum_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <O> MultiSelectSetting<E> visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
|
||||||
|
super.visibleWhen(settingValue, predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(E enum_) {
|
||||||
|
return this.getValue().contains(enum_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiSelectSetting<E> visibleWhen(BooleanSupplier booleanSupplier) {
|
||||||
|
super.visibleWhen(booleanSupplier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.getValue().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<E> getEnumClass() {
|
||||||
|
return this.enumClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiSelectSetting<E> onChange(Consumer<EnumSet<E>> consumer) {
|
||||||
|
super.onChange(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle(E enum_) {
|
||||||
|
MultiSelectSetting multiSelectSetting1 = this;
|
||||||
|
EnumSet enumSet;
|
||||||
|
if (!(enumSet = EnumSet.copyOf(multiSelectSetting1.getValue())).remove(enum_)) {
|
||||||
|
enumSet.add((E)enum_);
|
||||||
|
}
|
||||||
|
|
||||||
|
multiSelectSetting1.setValue(enumSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected EnumSet<E> sanitize(EnumSet<E> enumSet) {
|
||||||
|
return !this.allowEmpty && enumSet.isEmpty() && this.getValue() != null ? this.getValue() : EnumSet.copyOf(enumSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJson() {
|
||||||
|
MultiSelectSetting multiSelectSetting1 = this;
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
Iterator iterator;
|
||||||
|
Iterator iterator1 = iterator = multiSelectSetting1.getValue().iterator();
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
Enum enum_ = (Enum)iterator.next();
|
||||||
|
iterator1 = iterator;
|
||||||
|
jsonArray.add(new JsonPrimitive(enum_.name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmptyAllowed() {
|
||||||
|
return this.allowEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public MultiSelectSetting(String string, Class<E> class_, E... enums) {
|
||||||
|
super(string, enums.length == 0 ? EnumSet.noneOf(class_) : EnumSet.copyOf(List.of((E[])enums)));
|
||||||
|
this.enumClass = class_;
|
||||||
|
this.values = List.of((E[])class_.getEnumConstants());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<E> getValues() {
|
||||||
|
return this.values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiSelectSetting<E> visibleWhen(SettingValue<Boolean> settingValue) {
|
||||||
|
super.visibleWhen(settingValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiSelectSetting<E> describe(String string) {
|
||||||
|
super.describe(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user