mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: implement Module base class with toggle and event system support
This commit is contained in:
1 parent
1d3554b021
commit
767ed60b1f
2 files changed
+85
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@Getter
|
||||
public class Module {
|
||||
protected static final Minecraft mc = Minecraft.getMinecraft();
|
||||
protected final String name;
|
||||
protected final String description;
|
||||
protected final ModuleCategory category;
|
||||
protected int key = Keyboard.KEY_NONE;
|
||||
protected boolean enabled = false;
|
||||
|
||||
|
||||
|
||||
public Module(String name, String description, ModuleCategory category) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Module(String name, String description, ModuleCategory category, int key) {
|
||||
this(name, description, category);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
protected void onEnable() {
|
||||
System.out.println("[OrangeX] Enable " + name);
|
||||
}
|
||||
|
||||
protected void onDisable() {
|
||||
System.out.println("[OrangeX] Disable " + name);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean setEnabled) {
|
||||
if (this.enabled == setEnabled) return;
|
||||
|
||||
this.enabled = setEnabled;
|
||||
|
||||
if (this.enabled) {
|
||||
if (OrangeX.getInstance().getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getInstance().getEventBus().register(this); } catch (Exception ignored) {}
|
||||
onEnable();
|
||||
} else {
|
||||
if (!OrangeX.getInstance().getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getInstance().getEventBus().unregister(this); } catch (Exception ignored) {}
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
setEnabled(!this.enabled);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ModuleCategory {
|
||||
RENDER("Render"),
|
||||
COMBAT("Combat"),
|
||||
WORLD("World"),
|
||||
MOVEMENT("Movement"),
|
||||
PLAYER("Player"),
|
||||
MISC("Misc"),
|
||||
FUN("Fun"),
|
||||
MINIGAME("Minigame");
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
ModuleCategory(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user