feat(Modules): tiny rework for module system
This commit is contained in:
@@ -18,22 +18,19 @@ import org.joml.Vector2f;
|
||||
public class Module extends Feature implements Jsonable {
|
||||
private final String description;
|
||||
private final Category category;
|
||||
public Setting<Boolean> enabled = bool("Enabled", false);
|
||||
public Setting<Boolean> drawn = bool("Drawn", true);
|
||||
public Setting<Bind> bind = key("Keybind", new Bind(-1));
|
||||
public Setting<String> displayName;
|
||||
public boolean hasListener;
|
||||
public boolean alwaysListening;
|
||||
|
||||
public final Setting<Boolean> enabled = bool("Enabled", false);
|
||||
public final Setting<Boolean> drawn = bool("Drawn", true);
|
||||
public final Setting<Bind> bind = key("Keybind", new Bind(-1));
|
||||
public final Setting<String> displayName;
|
||||
|
||||
public boolean hidden;
|
||||
|
||||
public Module(String name, String description, Category category, boolean hasListener, boolean hidden, boolean alwaysListening) {
|
||||
public Module(String name, String description, Category category) {
|
||||
super(name);
|
||||
this.displayName = str("DisplayName", name);
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.hasListener = hasListener;
|
||||
this.hidden = hidden;
|
||||
this.alwaysListening = alwaysListening;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
@@ -67,14 +64,6 @@ public class Module extends Feature implements Jsonable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOn() {
|
||||
return this.enabled.getValue();
|
||||
}
|
||||
|
||||
public boolean isOff() {
|
||||
return !this.enabled.getValue();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled) {
|
||||
this.enable();
|
||||
@@ -85,17 +74,13 @@ public class Module extends Feature implements Jsonable {
|
||||
|
||||
public void enable() {
|
||||
this.enabled.setValue(true);
|
||||
EVENT_BUS.register(this);
|
||||
this.onToggle();
|
||||
this.onEnable();
|
||||
if (this.isOn() && this.hasListener && !this.alwaysListening) {
|
||||
EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
if (this.hasListener && !this.alwaysListening) {
|
||||
EVENT_BUS.unregister(this);
|
||||
}
|
||||
EVENT_BUS.unregister(this);
|
||||
this.enabled.setValue(false);
|
||||
this.onToggle();
|
||||
this.onDisable();
|
||||
@@ -126,7 +111,7 @@ public class Module extends Feature implements Jsonable {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return isOn();
|
||||
return enabled.getValue();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
@@ -157,10 +142,6 @@ public class Module extends Feature implements Jsonable {
|
||||
this.bind.setValue(new Bind(key));
|
||||
}
|
||||
|
||||
public boolean listening() {
|
||||
return this.hasListener && this.isOn() || this.alwaysListening;
|
||||
}
|
||||
|
||||
public String getFullArrayString() {
|
||||
return this.getDisplayName() + Formatting.GRAY + (this.getDisplayInfo() != null ? " [" + Formatting.WHITE + this.getDisplayInfo() + Formatting.GRAY + "]" : "");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ClickGui
|
||||
public Setting<Float> rainbowSaturation = num("Saturation", 150.0f, 1.0f, 255.0f);
|
||||
|
||||
public ClickGui() {
|
||||
super("ClickGui", "Opens the ClickGui", Module.Category.CLIENT, true, false, false);
|
||||
super("ClickGui", "Opens the ClickGui", Module.Category.CLIENT);
|
||||
setBind(GLFW.GLFW_KEY_RIGHT_SHIFT);
|
||||
rainbowHue.setVisibility(v -> rainbow.getValue());
|
||||
rainbowBrightness.setVisibility(v -> rainbow.getValue());
|
||||
|
||||
@@ -8,7 +8,7 @@ import me.alpha432.oyvey.features.modules.Module;
|
||||
|
||||
public class HudEditor extends Module {
|
||||
public HudEditor() {
|
||||
super("HudEditor", "Edit HUD element positions", Category.CLIENT, true, false, false);
|
||||
super("HudEditor", "Edit HUD element positions", Category.CLIENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public abstract class HudModule extends Module {
|
||||
private boolean dragging, button;
|
||||
|
||||
public HudModule(String name, String description, float width, float height) {
|
||||
super(name, description, Category.HUD, true, false, false);
|
||||
super(name, description, Category.HUD);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
|
||||
public class Criticals extends Module {
|
||||
public Criticals() {
|
||||
super("Criticals", "Makes you do critical hits", Category.COMBAT, true, false, false);
|
||||
super("Criticals", "Makes you do critical hits", Category.COMBAT);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -11,7 +11,7 @@ public class MCF extends Module {
|
||||
private boolean pressed;
|
||||
|
||||
public MCF() {
|
||||
super("MCF", "Middle click friend", Category.MISC, true, false, false);
|
||||
super("MCF", "Middle click friend", Category.MISC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import me.alpha432.oyvey.features.modules.Module;
|
||||
|
||||
public class ReverseStep extends Module {
|
||||
public ReverseStep() {
|
||||
super("ReverseStep", "step but reversed..", Category.MOVEMENT, true, false, false);
|
||||
super("ReverseStep", "step but reversed..", Category.MOVEMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,7 @@ public class Step extends Module {
|
||||
private final Setting<Float> height = num("Height", 2f, 1f, 3f);
|
||||
|
||||
public Step() {
|
||||
super("Step", "step..", Category.MOVEMENT, true, false, false);
|
||||
super("Step", "step..", Category.MOVEMENT);
|
||||
}
|
||||
|
||||
private float prev;
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.item.Items;
|
||||
|
||||
public class FastPlace extends Module {
|
||||
public FastPlace() {
|
||||
super("FastPlace", "Makes you throw exp faster", Category.PLAYER, true, false, false);
|
||||
super("FastPlace", "Makes you throw exp faster", Category.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
|
||||
public class NoFall extends Module {
|
||||
public NoFall() {
|
||||
super("NoFall", "Removes fall damage", Category.PLAYER, true, false, false);
|
||||
super("NoFall", "Removes fall damage", Category.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
|
||||
|
||||
public class Velocity extends Module {
|
||||
public Velocity() {
|
||||
super("Velocity", "Removes velocity from explosions and entities", Category.PLAYER, true, false, false);
|
||||
super("Velocity", "Removes velocity from explosions and entities", Category.PLAYER);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -16,7 +16,7 @@ public class BlockHighlight extends Module {
|
||||
public Setting<Float> lineWidth = num("LineWidth", 1.0f, 0.1f, 5.0f);
|
||||
|
||||
public BlockHighlight() {
|
||||
super("BlockHighlight", "Draws box at the block that you are looking at", Category.RENDER, true, false, false);
|
||||
super("BlockHighlight", "Draws box at the block that you are looking at", Category.RENDER);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -20,121 +20,31 @@ import me.alpha432.oyvey.features.modules.render.BlockHighlight;
|
||||
import me.alpha432.oyvey.util.traits.Jsonable;
|
||||
import me.alpha432.oyvey.util.traits.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ModuleManager implements Jsonable, Util {
|
||||
public List<Module> modules = new ArrayList<>();
|
||||
public List<Module> sortedModules = new ArrayList<>();
|
||||
public List<String> sortedModulesABC = new ArrayList<>();
|
||||
private final Map<Class<? extends Module>, Module> fastRegistry = new HashMap<>();
|
||||
private final List<Module> modules = new ArrayList<>();
|
||||
|
||||
public void init() {
|
||||
modules.add(new Watermark());
|
||||
modules.add(new Coordinates());
|
||||
modules.add(new HudEditor());
|
||||
modules.add(new ClickGui());
|
||||
modules.add(new Criticals());
|
||||
modules.add(new MCF());
|
||||
modules.add(new Step());
|
||||
modules.add(new ReverseStep());
|
||||
modules.add(new FastPlace());
|
||||
modules.add(new Velocity());
|
||||
modules.add(new BlockHighlight());
|
||||
modules.add(new NoFall());
|
||||
register(new Watermark());
|
||||
register(new Coordinates());
|
||||
register(new HudEditor());
|
||||
register(new ClickGui());
|
||||
register(new Criticals());
|
||||
register(new MCF());
|
||||
register(new Step());
|
||||
register(new ReverseStep());
|
||||
register(new FastPlace());
|
||||
register(new Velocity());
|
||||
register(new BlockHighlight());
|
||||
register(new NoFall());
|
||||
}
|
||||
|
||||
public Module getModuleByName(String name) {
|
||||
for (Module module : this.modules) {
|
||||
if (!module.getName().equalsIgnoreCase(name)) continue;
|
||||
return module;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends Module> T getModuleByClass(Class<T> clazz) {
|
||||
for (Module module : this.modules) {
|
||||
if (!clazz.isInstance(module)) continue;
|
||||
return (T) module;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void enableModule(Class<Module> clazz) {
|
||||
Module module = this.getModuleByClass(clazz);
|
||||
if (module != null) {
|
||||
module.enable();
|
||||
}
|
||||
}
|
||||
|
||||
public void disableModule(Class<Module> clazz) {
|
||||
Module module = this.getModuleByClass(clazz);
|
||||
if (module != null) {
|
||||
module.disable();
|
||||
}
|
||||
}
|
||||
|
||||
public void enableModule(String name) {
|
||||
Module module = this.getModuleByName(name);
|
||||
if (module != null) {
|
||||
module.enable();
|
||||
}
|
||||
}
|
||||
|
||||
public void disableModule(String name) {
|
||||
Module module = this.getModuleByName(name);
|
||||
if (module != null) {
|
||||
module.disable();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModuleEnabled(String name) {
|
||||
Module module = this.getModuleByName(name);
|
||||
return module != null && module.isOn();
|
||||
}
|
||||
|
||||
public boolean isModuleEnabled(Class<Module> clazz) {
|
||||
Module module = this.getModuleByClass(clazz);
|
||||
return module != null && module.isOn();
|
||||
}
|
||||
|
||||
public Module getModuleByDisplayName(String displayName) {
|
||||
for (Module module : this.modules) {
|
||||
if (!module.getDisplayName().equalsIgnoreCase(displayName)) continue;
|
||||
return module;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Module> getEnabledModules() {
|
||||
ArrayList<Module> enabledModules = new ArrayList<>();
|
||||
for (Module module : this.modules) {
|
||||
if (!module.isEnabled()) continue;
|
||||
enabledModules.add(module);
|
||||
}
|
||||
return enabledModules;
|
||||
}
|
||||
|
||||
public ArrayList<String> getEnabledModulesName() {
|
||||
ArrayList<String> enabledModules = new ArrayList<>();
|
||||
for (Module module : this.modules) {
|
||||
if (!module.isEnabled() || !module.isDrawn()) continue;
|
||||
enabledModules.add(module.getFullArrayString());
|
||||
}
|
||||
return enabledModules;
|
||||
}
|
||||
|
||||
public ArrayList<Module> getModulesByCategory(Module.Category category) {
|
||||
ArrayList<Module> modulesCategory = new ArrayList<Module>();
|
||||
this.modules.forEach(module -> {
|
||||
if (module.getCategory() == category) {
|
||||
modulesCategory.add(module);
|
||||
}
|
||||
});
|
||||
return modulesCategory;
|
||||
public void register(Module module) {
|
||||
getModules().add(module);
|
||||
fastRegistry.put(module.getClass(), module);
|
||||
}
|
||||
|
||||
public List<Module> getModules() {
|
||||
@@ -145,66 +55,60 @@ public class ModuleManager implements Jsonable, Util {
|
||||
return getModules().stream();
|
||||
}
|
||||
|
||||
public <T extends Module> T getModuleByClass(Class<T> clazz) {
|
||||
return (T) fastRegistry.get(clazz);
|
||||
}
|
||||
|
||||
public Module getModuleByName(String name) {
|
||||
return stream().filter(m -> m.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public Module getModuleByDisplayName(String display) {
|
||||
return stream().filter(m -> m.getDisplayName().equalsIgnoreCase(display)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public List<Module> getModulesByCategory(Module.Category category) {
|
||||
return stream().filter(m -> m.getCategory() == category).toList();
|
||||
}
|
||||
|
||||
public List<Module.Category> getCategories() {
|
||||
return Arrays.asList(Module.Category.values());
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
this.modules.stream().filter(Module::listening).forEach(EVENT_BUS::register);
|
||||
this.modules.forEach(Module::onLoad);
|
||||
getModules().forEach(Module::onLoad);
|
||||
}
|
||||
|
||||
public void onUpdate() {
|
||||
this.modules.stream().filter(Feature::isEnabled).forEach(Module::onUpdate);
|
||||
stream().filter(Feature::isEnabled).forEach(Module::onUpdate);
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
this.modules.stream().filter(Feature::isEnabled).forEach(Module::onTick);
|
||||
stream().filter(Feature::isEnabled).forEach(Module::onTick);
|
||||
}
|
||||
|
||||
public void onRender2D(Render2DEvent event) {
|
||||
this.modules.stream().filter(Feature::isEnabled).forEach(module -> module.onRender2D(event));
|
||||
stream().filter(Feature::isEnabled).forEach(module -> module.onRender2D(event));
|
||||
}
|
||||
|
||||
public void onRender3D(Render3DEvent event) {
|
||||
this.modules.stream().filter(Feature::isEnabled).forEach(module -> module.onRender3D(event));
|
||||
}
|
||||
|
||||
public void sortModules(boolean reverse) {
|
||||
this.sortedModules = this.getEnabledModules().stream().filter(Module::isDrawn)
|
||||
.sorted(Comparator.comparing(module -> mc.textRenderer.getWidth(module.getFullArrayString()) * (reverse ? -1 : 1)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void sortModulesABC() {
|
||||
this.sortedModulesABC = new ArrayList<>(this.getEnabledModulesName());
|
||||
this.sortedModulesABC.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
stream().filter(Feature::isEnabled).forEach(module -> module.onRender3D(event));
|
||||
}
|
||||
|
||||
public void onUnload() {
|
||||
this.modules.forEach(EVENT_BUS::unregister);
|
||||
this.modules.forEach(Module::onUnload);
|
||||
getModules().forEach(EVENT_BUS::unregister);
|
||||
getModules().forEach(Module::onUnload);
|
||||
}
|
||||
|
||||
public void onUnloadPost() {
|
||||
for (Module module : this.modules) {
|
||||
module.enabled.setValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onKeyPressed(int eventKey) {
|
||||
if (eventKey <= 0 || mc.currentScreen != null) return;
|
||||
this.modules.forEach(module -> {
|
||||
if (module.getBind().getKey() == eventKey) {
|
||||
module.toggle();
|
||||
}
|
||||
});
|
||||
public void onKeyPressed(int key) {
|
||||
if (key <= 0 || mc.currentScreen != null) return;
|
||||
stream().filter(module -> module.getBind().getKey() == key).forEach(Module::toggle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
for (Module module : modules) {
|
||||
for (Module module : getModules()) {
|
||||
object.add(module.getName(), module.toJson());
|
||||
}
|
||||
return object;
|
||||
@@ -212,7 +116,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
|
||||
@Override
|
||||
public void fromJson(JsonElement element) {
|
||||
for (Module module : modules) {
|
||||
for (Module module : getModules()) {
|
||||
module.fromJson(element.getAsJsonObject().get(module.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user