Upload files to "src/openonyx/history"

This commit is contained in:
winterflyt committed 2026-11-30 06:00:37 +02:00
1 parent 51cb99e2b8
commit 57f447491e
5 files changed
+445

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
package openonyx.history;
import openonyx.history.internal.RangeSetting;
public class RangeRoll {
private double f;
private final boolean H;
private final RangeSetting rangeSetting;
public void L() {
this.f = this.H ? this.rangeSetting.randomInt() : this.rangeSetting.random();
}
public RangeRoll(RangeSetting rangeSetting) {
this.rangeSetting = rangeSettingx;
this.H = rangeSettingx.isInteger();
rangeSettingx.onChange(range -> this.L());
this.L();
}
public int L() {
return (int)Math.round(this.f);
}
public float L() {
return (float)this.f;
}
public double L() {
return this.f;
}
}
+88
View File
@@ -0,0 +1,88 @@
package openonyx.history;
import com.google.gson.JsonElement;
import java.util.List;
import java.util.function.BooleanSupplier;
import openonyx.core.MinecraftAccess;
import openonyx.features.Module;
public abstract class Setting implements MinecraftAccess {
private Module module;
static int nextIndex = 0;
private final String name;
private String description;
private final int index = nextIndex++;
private Setting parent;
public static final BooleanSupplier BOOLEAN_SUPPLIER = () -> false;
private BooleanSupplier visibility;
public abstract JsonElement toJson();
public void setActive(boolean bl) {
}
protected void notifyChanged() {
if (this.module != null) {
this.module.refreshSettings();
}
}
public String getDescription() {
return this.description;
}
public int getIndex() {
return this.index;
}
public Setting getParent() {
return this.parent;
}
public String getPath() {
return this.parent == null ? this.name : new StringBuilder().insert(0, this.parent.getPath()).append(".").append(this.name).toString();
}
public boolean hasVisibilityCondition() {
return this.visibility != BOOLEAN_SUPPLIER;
}
public Setting describe(String string) {
this.description = string;
return this;
}
public Setting visibleWhen(BooleanSupplier booleanSupplier) {
this.visibility = booleanSupplier;
return this;
}
public abstract void fromJson(JsonElement jsonElement);
public boolean isVisible() {
return this.visibility.getAsBoolean();
}
public void attach(Module module, Setting setting1) {
this.module = modulex;
this.parent = setting1;
}
protected Setting(String string) {
this.description = "";
this.visibility = () -> true;
this.name = string;
}
public List<Setting> getSettings() {
return List.of();
}
public Module getModule() {
return this.module;
}
public String getName() {
return this.name;
}
}
+233
View File
@@ -0,0 +1,233 @@
package openonyx.history;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.function.BooleanSupplier;
import openonyx.core.OnyxClient;
import openonyx.features.Module;
import openonyx.history.internal.BooleanSetting;
import openonyx.utilities.RotationRequester;
import org.apache.logging.log4j.Logger;
public class SettingGroup extends Setting implements RotationRequester {
private boolean active;
private final BooleanSetting enabled;
private final List<Setting> settings = new ArrayList<>();
public boolean isEnabled() {
return this.enabled == null || this.enabled.getValue();
}
protected SettingGroup(String string, boolean bl) {
super(string);
this.enabled = new BooleanSetting("Enabled", bl);
this.enabled.onChange(boolean1 -> this.notifyChanged());
}
protected SettingGroup(String string) {
super(string);
this.enabled = null;
}
protected void D() {
}
private void L(Object object, Class<?> class_) {
SettingGroup settingGroup1 = this;
Class class_x;
for (Class class_xx = class_x = object.getClass(); class_xx != null && class_x != class_xx; class_xx = class_x = class_x.getSuperclass()) {
Field[] fields;
int i = (fields = class_x.getDeclaredFields()).length;
int j;
for (int k = j = 0; k < i; k = ++j) {
Field field = fields[j];
if (Setting.class.isAssignableFrom(field.getType()) && !Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
try {
field.setAccessible(true);
Object object1;
if ((object1 = field.get(object)) != null) {
settingGroup1.settings.add((Setting)object1);
}
} catch (IllegalAccessException illegalAccessException) {
Logger logger = OnyxClient.LOGGER;
Object[] objects = new Object[2];
boolean bl = true;
objects[0] = field.getName();
objects[1] = illegalAccessException;
logger.error("Failed to read setting field '{}'", objects);
}
}
}
}
}
@Override
public void fromJson(JsonElement jsonObject) {
if (this.enabled != null && jsonObject.isJsonPrimitive() && jsonObject.getAsJsonPrimitive().isBoolean()) {
this.enabled.fromJson(jsonObject);
} else if (jsonObject.isJsonObject()) {
jsonObject = jsonObject.getAsJsonObject();
if (this.enabled != null) {
loadSetting(this.enabled, jsonObject);
}
Iterator iterator;
for (Iterator iterator1 = iterator = this.settings.iterator(); iterator1.hasNext(); iterator1 = iterator) {
loadSetting((Setting)iterator.next(), jsonObject);
}
}
}
public SettingGroup describe(String string) {
super.describe(string);
return this;
}
@Override
public void setActive(boolean bl) {
SettingGroup settingGroup1;
label27: {
bl = bl && this.isEnabled();
if (bl != this.active) {
if (this.active = bl) {
OnyxClient.EVENT_BUS.subscribe(this);
settingGroup1 = this;
this.D();
break label27;
}
OnyxClient.EVENT_BUS.unsubscribe(this);
this.d();
}
settingGroup1 = this;
}
Iterator iterator;
for (Iterator iterator1 = iterator = settingGroup1.settings.iterator(); iterator1.hasNext(); iterator1 = iterator) {
((Setting)iterator.next()).setActive(bl);
}
}
public BooleanSetting getEnabled() {
return this.enabled;
}
protected void d() {
}
public SettingGroup visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
@Override
public JsonElement toJson() {
SettingGroup settingGroup1 = this;
JsonObject jsonObject = new JsonObject();
if (settingGroup1.enabled != null) {
jsonObject.add(settingGroup1.enabled.getName(), settingGroup1.enabled.toJson());
}
Iterator iterator;
Iterator iterator1 = iterator = settingGroup1.settings.iterator();
while (iterator1.hasNext()) {
Setting setting;
if (!(setting = (Setting)iterator.next()).hasVisibilityCondition()) {
iterator1 = iterator;
} else {
jsonObject.add(setting.getName(), setting.toJson());
iterator1 = iterator;
}
}
return jsonObject;
}
@Override
public List<Setting> getSettings() {
return this.settings;
}
public List<Setting> getVisibleSettings() {
return this.settings.stream().filter(Setting::isVisible).toList();
}
public boolean isToggleable() {
return this.enabled != null;
}
@Override
public boolean isToggled() {
return this.active;
}
public static void loadSetting(Setting setting, JsonObject jsonObject) {
Setting setting1 = setting;
if (setting1.hasVisibilityCondition()) {
JsonElement jsonElement;
if ((jsonElement = jsonObject.get(setting1.getName())) != null && !jsonElement.isJsonNull()) {
try {
setting1.fromJson(jsonElement);
} catch (RuntimeException runtimeException) {
Logger logger = OnyxClient.LOGGER;
Object[] objects = new Object[2];
boolean bl = true;
objects[0] = setting1.getPath();
objects[1] = runtimeException;
logger.warn("Failed to load setting '{}'", objects);
}
} else {
if (setting1 instanceof SettingGroup) {
SettingGroup settingGroup;
if ((settingGroup = (SettingGroup)setting1).getEnabled() != null) {
loadSetting(settingGroup.getEnabled(), jsonObject);
}
for (Iterator iterator1 = iterator = settingGroup.getSettings().iterator(); iterator1.hasNext(); iterator1 = iterator) {
loadSetting((Setting)iterator.next(), jsonObject);
}
}
}
}
}
@Override
public void attach(Module module, Setting setting) {
SettingGroup settingGroup1 = this;
settingGroup1.attach(module, setting);
if (settingGroup1.enabled != null) {
settingGroup1.enabled.attach(module, settingGroup1);
}
settingGroup1.settings.clear();
settingGroup1.L(settingGroup1, SettingGroup.class);
settingGroup1.settings.sort(Comparator.comparingInt(Setting::getIndex));
HashSet hashSet = new HashSet();
Iterator iterator;
for (Iterator iterator1 = iterator = settingGroup1.settings.iterator(); iterator1.hasNext(); iterator1 = iterator) {
Setting setting1 = (Setting)iterator.next();
if (!hashSet.add(setting1.getName())) {
Logger logger = OnyxClient.LOGGER;
Object[] objects = new Object[2];
boolean bl = true;
objects[0] = setting1.getName();
objects[1] = settingGroup1.getPath();
logger.warn("Duplicate setting name '{}' in group '{}'", objects);
}
setting1.attach(module, settingGroup1);
}
}
}
+23
View File
@@ -0,0 +1,23 @@
package openonyx.history;
import java.util.function.BooleanSupplier;
public class SettingSection extends SettingGroup {
protected SettingSection(String string) {
this(string, false);
}
protected SettingSection(String string, boolean bl) {
super(string, bl);
}
public SettingSection visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
public SettingSection describe(String string) {
super.describe(string);
return this;
}
}
+69
View File
@@ -0,0 +1,69 @@
package openonyx.history;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
public abstract class SettingValue<T> extends Setting {
private final T defaultValue;
private T value;
private Consumer<T> changeListener = object1 -> {};
public SettingValue<T> onChange(Consumer<T> consumer) {
this.changeListener = consumer;
return this;
}
public void setValue(T object) {
if (!(object = this.sanitize(object)).equals(this.value)) {
Object object1 = this.value;
this.value = (T)object;
UndoManager.L(this, () -> this.setValue((T)object1), () -> this.setValue((T)object));
this.changeListener.accept((T)object);
}
}
public T getDefault() {
return this.defaultValue;
}
public T getValue() {
return this.value;
}
public SettingValue<T> describe(String string) {
super.describe(string);
return this;
}
protected SettingValue(String string, T object) {
super(string);
this.defaultValue = (T)object;
this.value = (T)object;
}
public <O> SettingValue<T> visibleWhen(SettingValue<O> settingValue1, Predicate<O> predicate) {
return this.visibleWhen(() -> predicate.test(settingValue1.getValue()));
}
public SettingValue<T> visibleWhen(SettingValue<Boolean> settingValue1) {
return this.visibleWhen(settingValue1::getValue);
}
public SettingValue<T> visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
public boolean isDefault() {
return this.value.equals(this.defaultValue);
}
protected T sanitize(T object) {
return (T)object;
}
public void reset() {
this.setValue(this.defaultValue);
}
}