feat: added onEnabled/onDisabled callbacks

This commit is contained in:
əlemi 2023-01-29 00:03:15 +01:00
parent 6a9df35f40
commit 27c30423de
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -41,18 +41,23 @@ public abstract class Module {
); );
} }
public void toggle() { protected void onEnabled() {}
protected void onDisabled() {}
public final void toggle() {
if (this.enabled.get()) this.disable(); if (this.enabled.get()) this.disable();
else this.enable(); else this.enable();
} }
public void enable() { public final void enable() {
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
this.enabled.set(true); this.enabled.set(true);
this.onEnabled();
} }
public void disable() { public final void disable() {
MinecraftForge.EVENT_BUS.unregister(this); MinecraftForge.EVENT_BUS.unregister(this);
this.enabled.set(false); this.enabled.set(false);
this.onDisabled();
} }
} }