fix: settings getting corrupted on load
bear with me: issue likely was that all mods were enabled and saved concurrently while being loaded, messing up with config. Ok, must run callbacks and register mod but not touch config file. Solved by removing onEnabled/onDisabled callbacks, making mods directly override enable/disable. Made the implementations in AbstractModule check this.enabled before acting on config.
This commit is contained in:
parent
1a189e9c8a
commit
7a6102dfbf
8 changed files with 44 additions and 32 deletions
|
@ -77,7 +77,9 @@ public class Boscovicino implements ICommons {
|
|||
LOGGER.info("Initializing modules");
|
||||
|
||||
for (IModule m : modManager.mods) {
|
||||
if (m.isEnabled()) m.enable();
|
||||
if (m.isEnabled()) {
|
||||
m.enable(); // re-run enable() to register on the event bus and run enabled callbacks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,14 @@ public interface IModule extends ICommand {
|
|||
|
||||
ForgeConfigSpec.Builder getConfigBuilder();
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
default void toggle() {
|
||||
if (this.isEnabled())
|
||||
if (this.isEnabled()) {
|
||||
this.disable();
|
||||
else this.enable();
|
||||
} else {
|
||||
this.enable();
|
||||
}
|
||||
}
|
||||
|
||||
default void enable() {
|
||||
|
@ -19,8 +23,6 @@ public interface IModule extends ICommand {
|
|||
}
|
||||
|
||||
default void disable() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
boolean isEnabled();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import ftbsc.bscv.api.IModule;
|
|||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import static ftbsc.bscv.Boscovicino.log;
|
||||
|
||||
|
@ -70,23 +69,22 @@ public abstract class AbstractModule implements IModule {
|
|||
);
|
||||
}
|
||||
|
||||
protected void onEnabled() {}
|
||||
protected void onDisabled() {}
|
||||
|
||||
public final void enable() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
this.enabled.set(true);
|
||||
this.enabled.save();
|
||||
this.onEnabled();
|
||||
log(String.format("%s ON", this.getName()));
|
||||
public void enable() {
|
||||
IModule.super.enable();
|
||||
if (!this.enabled.get()) {
|
||||
this.enabled.set(true);
|
||||
this.enabled.save();
|
||||
log(String.format("%s ON", this.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public final void disable() {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
this.enabled.set(false);
|
||||
this.enabled.save();
|
||||
this.onDisabled();
|
||||
log(String.format("%s OFF", this.getName()));
|
||||
public void disable() {
|
||||
IModule.super.disable();
|
||||
if (this.enabled.get()) {
|
||||
this.enabled.set(false);
|
||||
this.enabled.save();
|
||||
log(String.format("%s OFF", this.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -104,7 +104,8 @@ public class Aura extends QuickModule implements ICommons {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onEnabled() {
|
||||
public void enable() {
|
||||
super.enable();
|
||||
this.autotool = (AutoTool) Boscovicino.modManager.get(AutoTool.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ public class Highlighter extends AbstractModule {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onEnabled() {
|
||||
public void enable() {
|
||||
super.enable();
|
||||
this.pattern = Pattern.compile(this.query.get());
|
||||
}
|
||||
|
||||
|
|
|
@ -97,17 +97,18 @@ public class VanillaFlight extends QuickModule implements ICommons {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onEnabled() {
|
||||
public void enable() {
|
||||
super.enable();
|
||||
this.tick = 0;
|
||||
if (MC.player != null) {
|
||||
this.couldFlyBefore = MC.player.abilities.mayfly;
|
||||
this.flyingSpeedBefore = MC.player.abilities.getFlyingSpeed();
|
||||
Boscovicino.log(String.format("Flying speed before = %f", this.flyingSpeedBefore));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisabled() {
|
||||
public void disable() {
|
||||
super.disable();
|
||||
ClientPlayerEntity player = MC.player;
|
||||
if (player != null) {
|
||||
player.abilities.mayfly = this.couldFlyBefore;
|
||||
|
|
|
@ -77,7 +77,8 @@ public class Freecam extends QuickModule implements ICommons {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onEnabled() {
|
||||
public void enable() {
|
||||
super.enable();
|
||||
if (MC.player == null) {
|
||||
Boscovicino.log("[!] Can only enable freecam while in-game");
|
||||
this.disable();
|
||||
|
@ -102,7 +103,8 @@ public class Freecam extends QuickModule implements ICommons {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onDisabled() {
|
||||
public void disable() {
|
||||
super.disable();
|
||||
if (MC.player == null) return;
|
||||
MC.gameMode.setLocalMode(this.prev_gamemode);
|
||||
MC.player.noCulling = false;
|
||||
|
|
|
@ -13,6 +13,10 @@ import java.awt.event.KeyEvent;
|
|||
|
||||
@AutoService(ILoadable.class)
|
||||
public class Fullbright extends QuickModule implements ICommons {
|
||||
|
||||
private final static int NIGHT_VISION_ID = 16;
|
||||
private final static int FOUR_MINUTES_TWENTY_SECONDS = 5204;
|
||||
|
||||
@Override
|
||||
protected int getDefaultKey() {
|
||||
return KeyEvent.VK_V;
|
||||
|
@ -22,11 +26,12 @@ public class Fullbright extends QuickModule implements ICommons {
|
|||
public void onTick(TickEvent.ClientTickEvent event) {
|
||||
if (MC == null) return;
|
||||
if (MC.player == null) return;
|
||||
MC.player.addEffect(new EffectInstance(Effect.byId(16), 5204));
|
||||
MC.player.addEffect(new EffectInstance(Effect.byId(NIGHT_VISION_ID), FOUR_MINUTES_TWENTY_SECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisabled() {
|
||||
MC.player.removeEffect(Effect.byId(16));
|
||||
public void disable() {
|
||||
super.disable();
|
||||
MC.player.removeEffect(Effect.byId(NIGHT_VISION_ID));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue