Upload files to "src/openonyx/features"
This commit is contained in:
1 parent
8394a2a05a
commit
b86b04326a
4 files changed
+517
No files matched your search
@@ -0,0 +1,180 @@
|
||||
package openonyx.features;
|
||||
|
||||
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 openonyx.core.MinecraftAccess;
|
||||
import openonyx.core.OnyxClient;
|
||||
import openonyx.history.Setting;
|
||||
import openonyx.history.UndoManager;
|
||||
import openonyx.history.internal.EnumSetting;
|
||||
import openonyx.history.internal.KeybindSetting;
|
||||
import openonyx.utilities.RotationRequester;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class Module implements MinecraftAccess, RotationRequester {
|
||||
private final EnumSetting<ModuleState> bindMode;
|
||||
private final String description;
|
||||
private final KeybindSetting bind = new KeybindSetting("Bind");
|
||||
private final List<Setting> settings;
|
||||
private boolean enabled;
|
||||
private final String name;
|
||||
private final ModuleCategory moduleCategory;
|
||||
|
||||
public boolean i() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ModuleCategory getModuleCategory() {
|
||||
return this.moduleCategory;
|
||||
}
|
||||
|
||||
public boolean D() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void L(Object object, Class<?> class_) {
|
||||
Module module1 = 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) {
|
||||
module1.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EnumSetting<ModuleState> getBindMode() {
|
||||
return this.bindMode;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToggled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean bl) {
|
||||
if (this.enabled != bl) {
|
||||
this.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
public Module(String string, String string1, ModuleCategory moduleCategory) {
|
||||
this.bindMode = new EnumSetting<>("Bind Mode", ModuleState.TOGGLE);
|
||||
this.settings = new ArrayList<>();
|
||||
this.enabled = false;
|
||||
this.name = string;
|
||||
this.description = string1;
|
||||
this.moduleCategory = moduleCategoryx;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
UndoManager.L(null, this::toggle, this::toggle);
|
||||
if (this.enabled) {
|
||||
this.enabled = false;
|
||||
this.refreshSettings();
|
||||
this.onDisable();
|
||||
OnyxClient.EVENT_BUS.unsubscribe(this);
|
||||
} else {
|
||||
this.enabled = true;
|
||||
OnyxClient.EVENT_BUS.subscribe(this);
|
||||
this.onEnable();
|
||||
this.refreshSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public List<Setting> getVisibleSettings() {
|
||||
return this.settings.stream().filter(Setting::isVisible).toList();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void refreshSettings() {
|
||||
Module module1 = this;
|
||||
|
||||
for (Iterator iterator1 = iterator = module1.settings.iterator(); iterator1.hasNext(); iterator1 = iterator) {
|
||||
((Setting)iterator.next()).setActive(module1.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public KeybindSetting getBind() {
|
||||
return this.bind;
|
||||
}
|
||||
|
||||
public List<Setting> getSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
protected void onDisable() {
|
||||
}
|
||||
|
||||
public void attachSettings() {
|
||||
Module module1 = this;
|
||||
module1.bind.attach(module1, null);
|
||||
module1.bindMode.attach(module1, null);
|
||||
if (module1.i()) {
|
||||
module1.bind.withBindMode(module1.bindMode);
|
||||
}
|
||||
|
||||
module1.settings.clear();
|
||||
module1.L(module1, Module.class);
|
||||
module1.settings.sort(Comparator.comparingInt(Setting::getIndex));
|
||||
HashSet hashSet = new HashSet();
|
||||
|
||||
Iterator iterator;
|
||||
for (Iterator iterator1 = iterator = module1.settings.iterator(); iterator1.hasNext(); iterator1 = iterator) {
|
||||
Setting setting = (Setting)iterator.next();
|
||||
if (!hashSet.add(setting.getName())) {
|
||||
Logger logger = OnyxClient.LOGGER;
|
||||
Object[] objects = new Object[2];
|
||||
boolean bl = true;
|
||||
objects[0] = setting.getName();
|
||||
objects[1] = module1.name;
|
||||
logger.warn("Duplicate setting name '{}' in module '{}'", objects);
|
||||
}
|
||||
|
||||
setting.attach(module1, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onEnable() {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user