chore: renamed ModManager, created static instance, made main class fields nonstatic
This commit is contained in:
parent
2e26856016
commit
5076e2b37c
11 changed files with 53 additions and 53 deletions
|
@ -27,26 +27,26 @@ import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Mod("bscv")
|
@Mod(Boscovicino.MOD_ID)
|
||||||
public class Boscovicino implements ICommons {
|
public class Boscovicino implements ICommons {
|
||||||
public static String MOD_ID = "bscv";
|
public static final String MOD_ID = "bscv";
|
||||||
|
|
||||||
public static final Logger LOGGER = LogManager.getLogger();
|
public static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static ModManager modManager; //todo rename
|
|
||||||
|
|
||||||
private final CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
|
private final CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
|
||||||
|
|
||||||
public static ForgeConfigSpec spec;
|
private static Boscovicino INSTANCE;
|
||||||
|
public static Boscovicino getInstance() { return INSTANCE; }
|
||||||
|
|
||||||
private static Friends friends;
|
public final ForgeConfigSpec spec;
|
||||||
public static Friends friends() { return Boscovicino.friends; }
|
|
||||||
|
|
||||||
@SuppressWarnings("unused") // it just needs to exist to be used by player
|
public final Modules modules;
|
||||||
private static Ruler ruler;
|
public final Friends friends;
|
||||||
|
public final Bindings bindings;
|
||||||
|
public final Macros macros;
|
||||||
|
|
||||||
public static Bindings bindings;
|
@SuppressWarnings({"unused", "FieldCanBeLocal"}) // it just needs to exist to be used by player
|
||||||
public static Macros macros;
|
private final Ruler ruler; //TODO remove
|
||||||
|
|
||||||
public Boscovicino() throws IOException {
|
public Boscovicino() throws IOException {
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetupComplete);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetupComplete);
|
||||||
|
@ -54,29 +54,31 @@ public class Boscovicino implements ICommons {
|
||||||
ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder();
|
ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder();
|
||||||
CommandDispatcher<CommandSource> dp = this.dispatcher;
|
CommandDispatcher<CommandSource> dp = this.dispatcher;
|
||||||
|
|
||||||
Boscovicino.modManager = new ModManager(cfg, dp);
|
this.modules = new Modules(cfg, dp);
|
||||||
Boscovicino.modManager.load();
|
this.modules.load();
|
||||||
|
|
||||||
Boscovicino.modManager.finish();
|
this.modules.finish();
|
||||||
|
|
||||||
Boscovicino.ruler = new Ruler();
|
this.ruler = new Ruler(); //TODO remove
|
||||||
|
|
||||||
ForgeConfigSpec.Builder bindingSpec = new ForgeConfigSpec.Builder();
|
ForgeConfigSpec.Builder bindingSpec = new ForgeConfigSpec.Builder();
|
||||||
Boscovicino.bindings = new Bindings(bindingSpec);
|
this.bindings = new Bindings(bindingSpec);
|
||||||
Boscovicino.macros = new Macros();
|
this.macros = new Macros(this);
|
||||||
|
|
||||||
Boscovicino.spec = cfg.build();
|
|
||||||
|
|
||||||
ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder();
|
ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder();
|
||||||
Boscovicino.friends = new Friends(friendSpec, dp);
|
this.friends = new Friends(friendSpec, dp);
|
||||||
|
|
||||||
// register config handler
|
// register config handlers
|
||||||
ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml");
|
this.spec = cfg.build();
|
||||||
|
ModLoadingContext.get().registerConfig(Type.CLIENT, this.spec, "bscv.toml");
|
||||||
ModLoadingContext.get().registerConfig(Type.CLIENT, friendSpec.build(), "friends.toml");
|
ModLoadingContext.get().registerConfig(Type.CLIENT, friendSpec.build(), "friends.toml");
|
||||||
ModLoadingContext.get().registerConfig(Type.CLIENT, bindingSpec.build(), "bindings.toml");
|
ModLoadingContext.get().registerConfig(Type.CLIENT, bindingSpec.build(), "bindings.toml");
|
||||||
|
|
||||||
// Register ourselves for server and other game events we are interested in
|
// register ourselves for server and other game events we are interested in
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
|
||||||
|
// create instance
|
||||||
|
INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(String message, Object... args) {
|
public static void log(String message, Object... args) {
|
||||||
|
@ -93,7 +95,7 @@ public class Boscovicino implements ICommons {
|
||||||
private void onSetupComplete(final FMLLoadCompleteEvent event) {
|
private void onSetupComplete(final FMLLoadCompleteEvent event) {
|
||||||
LOGGER.info("Initializing modules");
|
LOGGER.info("Initializing modules");
|
||||||
|
|
||||||
for (IModule m : modManager.mods) {
|
for (IModule m : modules.mods) {
|
||||||
if (m.isEnabled()) {
|
if (m.isEnabled()) {
|
||||||
m.enable(); // re-run enable() to register on the event bus and run enabled callbacks
|
m.enable(); // re-run enable() to register on the event bus and run enabled callbacks
|
||||||
}
|
}
|
||||||
|
@ -109,8 +111,8 @@ public class Boscovicino implements ICommons {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onClientChatEvent(ClientChatEvent event) {
|
public void onClientChatEvent(ClientChatEvent event) {
|
||||||
if (event.getMessage().startsWith("/")) {
|
if (MC.player != null && event.getMessage().startsWith("/")) {
|
||||||
CommandSource source = MC.player.createCommandSourceStack(); // TODO player could be NULL
|
CommandSource source = MC.player.createCommandSourceStack();
|
||||||
try {
|
try {
|
||||||
LOGGER.info(String.format("Running command %s", event.getMessage()));
|
LOGGER.info(String.format("Running command %s", event.getMessage()));
|
||||||
this.dispatcher.execute(event.getMessage().substring(1), source);
|
this.dispatcher.execute(event.getMessage().substring(1), source);
|
||||||
|
@ -123,14 +125,15 @@ public class Boscovicino implements ICommons {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
// TODO de-jank this, maybe by extending IngameMenuScreen
|
||||||
public void onPauseMenu(InitGuiEvent.Post event) {
|
public void onPauseMenu(InitGuiEvent.Post event) {
|
||||||
if (event.getGui() instanceof IngameMenuScreen) { // TODO de-jank this, maybe by extending IngameMenuScreen
|
if (event.getGui() instanceof IngameMenuScreen) {
|
||||||
IngameMenuScreen screen = (IngameMenuScreen) event.getGui();
|
IngameMenuScreen screen = (IngameMenuScreen) event.getGui();
|
||||||
screen.buttons.remove(3);
|
screen.buttons.remove(3);
|
||||||
screen.buttons.remove(3);
|
screen.buttons.remove(3);
|
||||||
screen.children.remove(3);
|
screen.children.remove(3);
|
||||||
screen.children.remove(3);
|
screen.children.remove(3);
|
||||||
Button mods_btn = new Button(
|
Button modsBtn = new Button(
|
||||||
screen.width / 2 + 4,
|
screen.width / 2 + 4,
|
||||||
screen.height / 4 + 72 + -16, 98, 20,
|
screen.height / 4 + 72 + -16, 98, 20,
|
||||||
new TranslationTextComponent("fml.menu.mods"),
|
new TranslationTextComponent("fml.menu.mods"),
|
||||||
|
@ -139,10 +142,10 @@ public class Boscovicino implements ICommons {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// need to add it twice for it to work once...
|
// need to add it twice for it to work once...
|
||||||
screen.buttons.add(3, mods_btn);
|
screen.buttons.add(3, modsBtn);
|
||||||
screen.buttons.add(3, mods_btn);
|
screen.buttons.add(3, modsBtn);
|
||||||
screen.children.add(3, mods_btn);
|
screen.children.add(3, modsBtn);
|
||||||
screen.children.add(3, mods_btn);
|
screen.children.add(3, modsBtn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public abstract class AbstractCommand implements ICommand, ICommons {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandDispatcher<CommandSource> getDispatcher() {
|
public CommandDispatcher<CommandSource> getDispatcher() {
|
||||||
return Boscovicino.modManager.getDispatcher();
|
return Boscovicino.getInstance().modules.getDispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LiteralArgumentBuilder<CommandSource>> subcommands() {
|
public List<LiteralArgumentBuilder<CommandSource>> subcommands() {
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class ModCommands extends AbstractCommand {
|
||||||
.then(
|
.then(
|
||||||
Commands.literal("off")
|
Commands.literal("off")
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
for (IModule mod : Boscovicino.modManager.mods) {
|
for (IModule mod : Boscovicino.getInstance().modules.mods) {
|
||||||
if (mod.isEnabled()) {
|
if (mod.isEnabled()) {
|
||||||
mod.disable();
|
mod.disable();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class ModCommands extends AbstractCommand {
|
||||||
.then(
|
.then(
|
||||||
Commands.literal("re-enable") // this is to fix some jankyness in event subscriptions
|
Commands.literal("re-enable") // this is to fix some jankyness in event subscriptions
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
for (IModule mod : Boscovicino.modManager.mods) {
|
for (IModule mod : Boscovicino.getInstance().modules.mods) {
|
||||||
if (mod.isEnabled()) {
|
if (mod.isEnabled()) {
|
||||||
mod.disable();
|
mod.disable();
|
||||||
mod.enable();
|
mod.enable();
|
||||||
|
@ -43,7 +43,7 @@ public class ModCommands extends AbstractCommand {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
String mods = Boscovicino.modManager.mods.stream()
|
String mods = Boscovicino.getInstance().modules.mods.stream()
|
||||||
.map(x -> x.getName())
|
.map(x -> x.getName())
|
||||||
.collect(Collectors.joining(","));
|
.collect(Collectors.joining(","));
|
||||||
Boscovicino.log("[ %s ]", mods);
|
Boscovicino.log("[ %s ]", mods);
|
||||||
|
|
|
@ -27,12 +27,12 @@ public abstract class AbstractModule implements IModule, ICommons {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForgeConfigSpec.Builder getConfigBuilder() {
|
public ForgeConfigSpec.Builder getConfigBuilder() {
|
||||||
return Boscovicino.modManager.getCfgBuilder();
|
return Boscovicino.getInstance().modules.getCfgBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandDispatcher<CommandSource> getDispatcher() {
|
public CommandDispatcher<CommandSource> getDispatcher() {
|
||||||
return Boscovicino.modManager.getDispatcher();
|
return Boscovicino.getInstance().modules.getDispatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractModule() {
|
public AbstractModule() {
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class Aura extends QuickModule {
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
super.enable();
|
super.enable();
|
||||||
this.autotool = (AutoTool) Boscovicino.modManager.get(AutoTool.class);
|
this.autotool = (AutoTool) Boscovicino.getInstance().modules.get(AutoTool.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookAtHidden(EntityAnchorArgument.Type anchor, Vector3d target) {
|
private void lookAtHidden(EntityAnchorArgument.Type anchor, Vector3d target) {
|
||||||
|
@ -139,7 +139,7 @@ public class Aura extends QuickModule {
|
||||||
if (!this.neutral.get() && e.getClassification(false).isFriendly()) continue;
|
if (!this.neutral.get() && e.getClassification(false).isFriendly()) continue;
|
||||||
if (e instanceof PlayerEntity) {
|
if (e instanceof PlayerEntity) {
|
||||||
PlayerEntity player = (PlayerEntity) e;
|
PlayerEntity player = (PlayerEntity) e;
|
||||||
if (Boscovicino.friends().isFriend(player.getGameProfile().getId())) {
|
if (Boscovicino.getInstance().friends.isFriend(player.getGameProfile().getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class ActiveModules extends HudModule {
|
||||||
if (event.getType() != ElementType.TEXT) return;
|
if (event.getType() != ElementType.TEXT) return;
|
||||||
if (this.shouldHide()) return;
|
if (this.shouldHide()) return;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (IModule m : Boscovicino.modManager.mods) {
|
for (IModule m : Boscovicino.getInstance().modules.mods) {
|
||||||
if (m.isEnabled() && !m.getGroup().equalsIgnoreCase("HUD")) {
|
if (m.isEnabled() && !m.getGroup().equalsIgnoreCase("HUD")) {
|
||||||
TextBuilder()
|
TextBuilder()
|
||||||
.txt(this.affixed(m.getName()))
|
.txt(this.affixed(m.getName()))
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class GuiMove extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
this.autoWalk_mod = (AutoWalk) Boscovicino.modManager.get(AutoWalk.class);
|
this.autoWalk_mod = (AutoWalk) Boscovicino.getInstance().modules.get(AutoWalk.class);
|
||||||
super.enable();
|
super.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Bindings {
|
public class Bindings {
|
||||||
public static final int UNBOUND = InputMappings.UNKNOWN.getValue();
|
public static final int UNBOUND = InputMappings.UNKNOWN.getValue();
|
||||||
|
@ -43,7 +40,7 @@ public class Bindings {
|
||||||
public KeyBinding registerBinding(String name, int key, String macroFileName) {
|
public KeyBinding registerBinding(String name, int key, String macroFileName) {
|
||||||
KeyBinding kb = this.createBinding(name, key);
|
KeyBinding kb = this.createBinding(name, key);
|
||||||
this.executorMap.put(kb, () -> {
|
this.executorMap.put(kb, () -> {
|
||||||
Boscovicino.macros.execute(macroFileName);
|
Boscovicino.getInstance().macros.execute(macroFileName);
|
||||||
});
|
});
|
||||||
return kb;
|
return kb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,10 @@ public class Friends implements ICommons {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForgeConfigSpec.ConfigValue<List<? extends String>> store;
|
public final ForgeConfigSpec.ConfigValue<List<? extends String>> store;
|
||||||
|
|
||||||
public Friends(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
|
public Friends(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
|
||||||
this.store = builder.comment("actual friend list").defineList("data", () -> new ArrayList<String>(), u -> {
|
this.store = builder.comment("actual friend list").defineList("data", ArrayList::new, u -> {
|
||||||
try{
|
try{
|
||||||
UUID.fromString(u.toString());
|
UUID.fromString(u.toString());
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -15,9 +15,9 @@ public class Macros {
|
||||||
private final Lua lua;
|
private final Lua lua;
|
||||||
private final HashMap<String, String> macroCache;
|
private final HashMap<String, String> macroCache;
|
||||||
|
|
||||||
public Macros() throws IOException {
|
public Macros(Boscovicino bscv) throws IOException {
|
||||||
this.lua = new LuaJit();
|
this.lua = new LuaJit();
|
||||||
this.lua.pushJavaClass(Boscovicino.class); //TODO use instance
|
this.lua.pushJavaObject(bscv); //TODO use instance
|
||||||
this.lua.setGlobal("BSCV");
|
this.lua.setGlobal("BSCV");
|
||||||
this.macroCache = new HashMap<>();
|
this.macroCache = new HashMap<>();
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class Macros {
|
||||||
if(name.endsWith(".lua")) {
|
if(name.endsWith(".lua")) {
|
||||||
String code = String.join("\n", Files.readAllLines(macro));
|
String code = String.join("\n", Files.readAllLines(macro));
|
||||||
this.macroCache.put(name, code);
|
this.macroCache.put(name, code);
|
||||||
Boscovicino.bindings.registerBinding(name, Bindings.UNBOUND, name);
|
Boscovicino.getInstance().bindings.registerBinding(name, Bindings.UNBOUND, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.HashSet;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ModManager {
|
public class Modules {
|
||||||
private Builder cfgBuilder;
|
private Builder cfgBuilder;
|
||||||
private CommandDispatcher<CommandSource> dispatcher;
|
private CommandDispatcher<CommandSource> dispatcher;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class ModManager {
|
||||||
public final Set<IModule> mods;
|
public final Set<IModule> mods;
|
||||||
public final Set<String> categories;
|
public final Set<String> categories;
|
||||||
|
|
||||||
public ModManager(Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) {
|
public Modules(Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) {
|
||||||
this.cfgBuilder = cfgBuilder;
|
this.cfgBuilder = cfgBuilder;
|
||||||
this.dispatcher = dispatcher;
|
this.dispatcher = dispatcher;
|
||||||
this.mods = new HashSet<>();
|
this.mods = new HashSet<>();
|
Loading…
Reference in a new issue