Skip to content

Commit

Permalink
Implemented event system to simplify module classes and creation.
Browse files Browse the repository at this point in the history
The system is not perfect, but it has worked well so far.
  • Loading branch information
coltonk9043 committed Aug 26, 2023
1 parent 80b3e50 commit eb7e926
Show file tree
Hide file tree
Showing 72 changed files with 801 additions and 1,238 deletions.
10 changes: 9 additions & 1 deletion src/main/java/net/aoba/AobaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
*/
package net.aoba;

import java.util.EventListener;

import net.aoba.altmanager.AltManager;
import net.aoba.cmd.CommandManager;
import net.aoba.core.settings.SettingManager;
import net.aoba.event.EventManager;
import net.aoba.gui.HudManager;
import net.aoba.interfaces.IMinecraftClient;
import net.aoba.misc.RenderUtils;
Expand All @@ -48,6 +51,8 @@ public class AobaClient {
public SettingManager settingManager;
public RenderUtils renderUtils;

public EventManager eventManager;

private boolean ghostMode;

/**
Expand All @@ -73,7 +78,10 @@ public void Initialize() {
System.out.println("[Aoba] Loading Alts");
altManager = new AltManager();
System.out.println("[Aoba] Aoba-chan initialized and ready to play!");


eventManager = new EventManager();


SettingManager.loadSettings("config_category", settingManager.config_category);
SettingManager.loadSettings("modules_category", settingManager.modules_category);
SettingManager.loadSettings("hidden_category", settingManager.hidden_category);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/net/aoba/core/settings/Setting.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
Starts with an O as to not be confused with the legacy setting
Partially skidded from balkan hack
*/

package net.aoba.core.settings;

import java.util.function.Consumer;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/aoba/core/settings/SettingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Setting get_setting_in_category (String p_setting_id, List<Setting

public static void prepare(String name) {
try {
configFolder = new File(MinecraftClient.getInstance().runDirectory + File.separator + "Aoba");
configFolder = new File(MinecraftClient.getInstance().runDirectory + File.separator + "aoba");
configFile = new File(configFolder + File.separator + name + ".xml");
if (!configFolder.exists()) configFolder.mkdirs();
if (!configFile.exists()) configFile.createNewFile();
Expand Down Expand Up @@ -104,7 +104,6 @@ public static void loadSettings(String name, List<Setting> setting_list) {
String value_x = config.getProperty(setting.ID + "_x", null);
String value_y = config.getProperty(setting.ID + "_y", null);
if (value_x == null || value_y == null) break;
/* if (DEBUG_STUFF) */ System.out.println(setting.displayName + " " + ((Vector2)setting.value).x + " " + ((Vector2)setting.value).y + " " + value_x + " " + value_y);
setting.setValue(new Vector2(Float.parseFloat(value_x), Float.parseFloat(value_y)));
}
}
Expand All @@ -113,7 +112,7 @@ public static void loadSettings(String name, List<Setting> setting_list) {
}

public enum SettingCategories {
CONFGI,
CONFIG,
MODULES,
HIDDEN
}
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/net/aoba/event/EventManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.aoba.event;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import net.aoba.event.events.AbstractEvent;
import net.aoba.event.listeners.AbstractListener;

public class EventManager {

private final HashMap<Class<AbstractListener>, ArrayList<AbstractListener>> listeners;

public EventManager() {
listeners = new HashMap<Class<AbstractListener>, ArrayList<AbstractListener>>();
}

@SuppressWarnings("unchecked")
public <T extends AbstractListener> void AddListener(Class<T> object, AbstractListener listener) {
try {
ArrayList<AbstractListener> listOfListeners = listeners.get(object);
if(listOfListeners == null)
{
listOfListeners = new ArrayList<>(Arrays.asList(listener));
listeners.put((Class<AbstractListener>) object, listOfListeners);
}
listOfListeners.add(listener);
}catch(Exception e) {
System.out.println("Issue adding listener: " + object.getTypeName() + "...");
e.printStackTrace();
}
}

public <T extends AbstractListener> void RemoveListener(Class<T> object, AbstractListener listener) {
try {
ArrayList<AbstractListener> listOfListeners = listeners.get(object);
if(listOfListeners != null)
{
listOfListeners.remove(listener);
}
}catch(Exception e) {
System.out.println("Issue removing listener: " + object.getTypeName() + "...");
e.printStackTrace();
}
}

public void Fire(AbstractEvent event) {
ArrayList<? extends AbstractListener> listOfListeners = listeners.get(event.GetListenerClassType());

if(listOfListeners == null) {
return;
}

event.Fire(listOfListeners);
}
}
20 changes: 20 additions & 0 deletions src/main/java/net/aoba/event/events/AbstractEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.aoba.event.events;

import java.util.ArrayList;

import net.aoba.event.listeners.AbstractListener;

public abstract class AbstractEvent {
boolean isCancelled;

public AbstractEvent() {
isCancelled = false;
}

public boolean IsCancelled() {
return isCancelled;
}

public abstract void Fire(ArrayList<? extends AbstractListener> listeners);
public abstract <T extends AbstractListener> Class<T> GetListenerClassType();
}
39 changes: 39 additions & 0 deletions src/main/java/net/aoba/event/events/MouseScrollEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.aoba.event.events;

import java.util.ArrayList;

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.MouseScrollListener;

public class MouseScrollEvent extends AbstractEvent{
private float horizontal;
private float vertical;

public MouseScrollEvent(float horizontal, float vertical) {
super();
this.horizontal = horizontal;
this.vertical = vertical;
}

public float GetVertical() {
return vertical;
}

public float GetHorizontal() {
return horizontal;
}

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
MouseScrollListener mouseScrollListener = (MouseScrollListener) listener;
mouseScrollListener.OnMouseScroll(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<MouseScrollListener> GetListenerClassType() {
return MouseScrollListener.class;
}
}
33 changes: 33 additions & 0 deletions src/main/java/net/aoba/event/events/ReceivePacketEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.aoba.event.events;

import java.util.ArrayList;
import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.ReceivePacketListener;
import net.minecraft.network.packet.Packet;

public class ReceivePacketEvent extends AbstractEvent {

private Packet<?> packet;

public Packet<?> GetPacket(){
return packet;
}

public ReceivePacketEvent(Packet<?> packet) {
this.packet = packet;
}

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
ReceivePacketListener readPacketListener = (ReceivePacketListener) listener;
readPacketListener.OnReceivePacket(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<ReceivePacketListener> GetListenerClassType() {
return ReceivePacketListener.class;
}
}
38 changes: 38 additions & 0 deletions src/main/java/net/aoba/event/events/RenderEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.aoba.event.events;

import java.util.ArrayList;

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.RenderListener;
import net.minecraft.client.util.math.MatrixStack;

public class RenderEvent extends AbstractEvent {
MatrixStack matrixStack;
float partialTicks;

public MatrixStack GetMatrixStack() {
return matrixStack;
}
public float GetPartialTicks() {
return partialTicks;
}

public RenderEvent(MatrixStack matrixStack, float partialTicks) {
this.matrixStack = matrixStack;
this.partialTicks = partialTicks;
}

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
RenderListener renderListener = (RenderListener) listener;
renderListener.OnRender(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<RenderListener> GetListenerClassType() {
return RenderListener.class;
}
}
34 changes: 34 additions & 0 deletions src/main/java/net/aoba/event/events/SendPacketEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.aoba.event.events;

import java.util.ArrayList;

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.SendPacketListener;
import net.minecraft.network.packet.Packet;

public class SendPacketEvent extends AbstractEvent {

private Packet<?> packet;

public SendPacketEvent(Packet<?> packet) {
this.packet = packet;
}

public Packet<?> GetPacket(){
return packet;
}

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
SendPacketListener sendPacketListener = (SendPacketListener) listener;
sendPacketListener.OnSendPacket(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<SendPacketListener> GetListenerClassType() {
return SendPacketListener.class;
}
}
22 changes: 22 additions & 0 deletions src/main/java/net/aoba/event/events/TickEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.aoba.event.events;

import java.util.ArrayList;

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.TickListener;

public class TickEvent extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
TickListener tickListener = (TickListener) listener;
tickListener.OnUpdate(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<TickListener> GetListenerClassType() {
return TickListener.class;
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/aoba/event/listeners/AbstractListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.aoba.event.listeners;

public interface AbstractListener {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.event.listeners;

import net.aoba.event.events.MouseScrollEvent;

public interface MouseScrollListener extends AbstractListener {
public abstract void OnMouseScroll(MouseScrollEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.event.listeners;

import net.aoba.event.events.ReceivePacketEvent;

public interface ReceivePacketListener extends AbstractListener {
public abstract void OnReceivePacket(ReceivePacketEvent readPacketEvent);
}
7 changes: 7 additions & 0 deletions src/main/java/net/aoba/event/listeners/RenderListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.event.listeners;

import net.aoba.event.events.RenderEvent;

public interface RenderListener extends AbstractListener {
public abstract void OnRender(RenderEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.event.listeners;

import net.aoba.event.events.SendPacketEvent;

public interface SendPacketListener extends AbstractListener {
public abstract void OnSendPacket(SendPacketEvent event);
}
7 changes: 7 additions & 0 deletions src/main/java/net/aoba/event/listeners/TickListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.event.listeners;

import net.aoba.event.events.TickEvent;

public interface TickListener extends AbstractListener {
public abstract void OnUpdate(TickEvent event);
}
5 changes: 5 additions & 0 deletions src/main/java/net/aoba/gui/tabs/AuthCrackerTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ public class AuthCrackerTab extends ClickGuiTab {

public AuthCrackerTab(String title, int x, int y){
super(title, x, y, false);
this.width = 360.0f;



this.information = new StringComponent("This panel can be used to break Auth passwords used in cracked servers.", this);
this.addChild(information);



this.delaySlider = new SliderComponent(this, delay);
this.addChild(delaySlider);

Expand Down
Loading

0 comments on commit eb7e926

Please sign in to comment.