Skip to content

Commit

Permalink
fix: Fixed addon system module + command loading
Browse files Browse the repository at this point in the history
  • Loading branch information
cvs0 committed Jul 7, 2024
1 parent 162ba2c commit df8bcf1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
51 changes: 24 additions & 27 deletions src/main/java/net/aoba/AobaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class AobaClient {
Expand Down Expand Up @@ -76,15 +78,35 @@ public void loadAssets() {
System.out.println("[Aoba] Starting Client");

eventManager = new EventManager();

LogUtils.getLogger().info("[Aoba] Starting addon initialization");
List<IAddon> addons = new ArrayList<>();

for (EntrypointContainer<IAddon> entrypoint : FabricLoader.getInstance().getEntrypointContainers("aoba", IAddon.class)) {
IAddon addon = entrypoint.getEntrypoint();

try {
LogUtils.getLogger().info("[Aoba] Initializing addon: " + addon.getClass().getName());
addon.onIntialize();
LogUtils.getLogger().info("[Aoba] Addon initialized: " + addon.getClass().getName());
} catch (Throwable e) {
LogUtils.getLogger().error("Error initializing addon: " + addon.getClass().getName(), e);
}

addons.add(addon);
}

LogUtils.getLogger().info("[Aoba] Addon initialization completed");

renderUtils = new RenderUtils();
System.out.println("[Aoba] Reading Settings");
settingManager = new SettingManager();
System.out.println("[Aoba] Reading Friends List");
friendsList = new FriendsList();
System.out.println("[Aoba] Initializing Modules");
moduleManager = new ModuleManager();
moduleManager = new ModuleManager(addons);
System.out.println("[Aoba] Initializing Commands");
commandManager = new CommandManager();
commandManager = new CommandManager(addons);
System.out.println("[Aoba] Initializing Font Manager");
fontManager = new FontManager();
fontManager.Initialize();
Expand All @@ -99,31 +121,6 @@ public void loadAssets() {
SettingManager.loadSettings(settingManager.modulesContainer);
SettingManager.loadSettings(settingManager.hiddenContainer);

LogUtils.getLogger().info("[Aoba] Starting addon initialization");

for (EntrypointContainer<IAddon> entrypoint : FabricLoader.getInstance().getEntrypointContainers("aoba", IAddon.class)) {
IAddon addon = entrypoint.getEntrypoint();

try {
LogUtils.getLogger().info("[Aoba] Initializing addon: " + addon.getClass().getName());
addon.onIntialize();
} catch (Exception e) {
LogUtils.getLogger().error("Error initializing addon: " + addon.getClass().getName(), e);
}

addon.modules().stream().filter(Objects::nonNull).forEach(module -> {
try {
moduleManager.modules.add(module);
LogUtils.getLogger().info("[Aoba] Successfully registered module: " + module.getClass().getName());
} catch (Exception e) {
LogUtils.getLogger().error("Error registering module: " + module.getClass().getName() + " for addon: " + addon.getClass().getName(), e);
}
});
}

LogUtils.getLogger().info("[Aoba] Addon initialization completed");


globalChat = new

GlobalChat();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/net/aoba/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import net.aoba.Aoba;
import net.aoba.api.IAddon;
import net.aoba.cmd.commands.*;
import net.aoba.settings.SettingManager;
import net.aoba.settings.types.StringSetting;
Expand Down Expand Up @@ -69,7 +73,7 @@ public class CommandManager {
/**
* Constructor for Command Manager. Initializes all commands.
*/
public CommandManager() {
public CommandManager(List<IAddon> addons) {

PREFIX = new StringSetting("Prefix", "Prefix", ".aoba");

Expand All @@ -84,6 +88,16 @@ public CommandManager() {
Command cmd = (Command)field.get(this);
commands.put(cmd.getName(), cmd);
}

addons.stream().filter(Objects::nonNull).forEach(addon -> {
addon.commands().forEach(command -> {
if (commands.containsKey(command.getName())) {
System.out.println("Warning: Duplicate command name \"" + command.getName() + "\" from addon. This command will not be registered.");
} else {
commands.put(command.getName(), command);
}
});
});
}catch(Exception e)
{
System.out.println("Error initializing Aoba commands.");
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/net/aoba/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
package net.aoba.module;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.mojang.logging.LogUtils;
import net.aoba.Aoba;
import net.aoba.api.IAddon;
import net.aoba.event.events.KeyDownEvent;
import net.aoba.event.events.RenderEvent;
import net.aoba.event.listeners.KeyDownListener;
Expand Down Expand Up @@ -105,8 +110,7 @@ public class ModuleManager implements KeyDownListener {
public Module xray = new XRay();
public Module zoom = new Zoom();

public ModuleManager() {
// Look at all these modules!
public ModuleManager(List<IAddon> addons) {
addModule(aimbot);
addModule(anticactus);
addModule(antiinvis);
Expand Down Expand Up @@ -166,6 +170,21 @@ public ModuleManager() {
addModule(trajectory);
addModule(xray);
addModule(zoom);

addons.stream().filter(Objects::nonNull).forEach(addon -> {
try {
addon.modules().forEach(module -> {
try {
addModule(module);
LogUtils.getLogger().info("[Aoba] Successfully added module: " + module.getClass().getName() + " from addon: " + addon.getClass().getName());
} catch (Exception e) {
LogUtils.getLogger().error("Error adding module: " + module.getClass().getName() + " from addon: " + addon.getClass().getName(), e);
}
});
} catch (Exception e) {
LogUtils.getLogger().error("Error processing modules from addon: " + addon.getClass().getName(), e);
}
});

for(Module module : modules) {
for(Setting<?> setting : module.getSettings()) {
Expand Down

0 comments on commit df8bcf1

Please sign in to comment.