Skip to content

Commit

Permalink
Reworked some of the Command system.
Browse files Browse the repository at this point in the history
Added Autofill for command parameters.
Cleaned up some code and variable names.
  • Loading branch information
coltonk9043 committed Jun 22, 2023
1 parent 51d2e8f commit de8f1ba
Show file tree
Hide file tree
Showing 29 changed files with 404 additions and 137 deletions.
31 changes: 27 additions & 4 deletions src/main/java/net/aoba/cmd/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@
*/
package net.aoba.cmd;

import java.util.Objects;

import net.aoba.AobaClient;
import net.minecraft.client.MinecraftClient;

public abstract class Command {
protected String description;
protected final String name;
protected final String description;

protected static final MinecraftClient mc = AobaClient.MC;

public Command(String name, String description) {
this.name = Objects.requireNonNull(name);
this.description = Objects.requireNonNull(description);
}

/**
* Runs the intended action of the command.
* @param parameters The parameters being passed.
* Gets the name of the command.
* @return The name of the command.
*/
public abstract void command(String[] parameters);
public String getName() {
return this.name;
}

/**
* Gets the description of the command.
Expand All @@ -41,4 +52,16 @@ public abstract class Command {
public String getDescription() {
return this.description;
}

/**
* Runs the intended action of the command.
* @param parameters The parameters being passed.
*/
public abstract void runCommand(String[] parameters);

/**
* Gets the next Autocorrect suggestions given the last typed parameter.
* @param previousParameter
*/
public abstract String[] getAutocorrect(String previousParameter);
}
77 changes: 48 additions & 29 deletions src/main/java/net/aoba/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,62 @@
*/
package net.aoba.cmd;

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

import net.aoba.Aoba;
import net.aoba.cmd.commands.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;

public class CommandManager {
private HashMap<String, Command> commands = new HashMap<String, Command>();

public final CmdAimbot aimbot = new CmdAimbot();
public final CmdAutoEat autoeat = new CmdAutoEat();
public final CmdChestESP chestesp = new CmdChestESP();
public final CmdEntityESP entityesp = new CmdEntityESP();
public final CmdFastBreak fastbreak = new CmdFastBreak();
public final CmdFly fly = new CmdFly();
public final CmdFreecam freecam = new CmdFreecam();
public final CmdFullbright fullbright = new CmdFullbright();
public final CmdHelp help = new CmdHelp();
public final CmdHud hud = new CmdHud();
public final CmdItemESP itemesp = new CmdItemESP();
public final CmdNoclip noclip = new CmdNoclip();
public final CmdNoFall nofall = new CmdNoFall();
public final CmdNoSlowdown noslowdown = new CmdNoSlowdown();
public final CmdNuker nuker = new CmdNuker();
public final CmdPlayerESP playeresp = new CmdPlayerESP();
public final CmdPOV pov = new CmdPOV();
public final CmdReach reach = new CmdReach();
public final CmdSpam spam = new CmdSpam();
public final CmdSprint sprint = new CmdSprint();
public final CmdStep step = new CmdStep();
public final CmdTileBreaker tilebreaker = new CmdTileBreaker();
public final CmdTimer timer = new CmdTimer();
public final CmdTP tp = new CmdTP();
public final CmdTracer tracer = new CmdTracer();
public final CmdXRay xray = new CmdXRay();

/**
* Constructor for Command Manager. Initializes all commands.
*/
public CommandManager() {
commands.put("aimbot", new CmdAimbot());
commands.put("autoeat", new CmdAutoEat());
commands.put("chestesp", new CmdChestESP());
commands.put("entityesp", new CmdEntityESP());
commands.put("fastbreak", new CmdFastBreak());
commands.put("fly", new CmdFly());
commands.put("freecam", new CmdFreecam());
commands.put("fullbright", new CmdFullbright());
commands.put("help", new CmdHelp());
commands.put("hud", new CmdHud());
commands.put("itemesp", new CmdItemESP());
commands.put("noclip", new CmdNoclip());
commands.put("nofall", new CmdNoFall());
commands.put("noslowdown", new CmdNoSlowdown());
commands.put("nuker", new CmdNuker());
commands.put("playeresp", new CmdPlayerESP());
commands.put("pov", new CmdPOV());
commands.put("reach", new CmdReach());
commands.put("spam", new CmdSpam());
commands.put("sprint", new CmdSprint());
commands.put("step", new CmdStep());
commands.put("tilebreaker", new CmdTileBreaker());
commands.put("timer", new CmdTimer());
commands.put("tp", new CmdTP());
commands.put("tracer", new CmdTracer());
commands.put("xray", new CmdXRay());
try
{
for(Field field : CommandManager.class.getDeclaredFields())
{
if (!Command.class.isAssignableFrom(field.getType()))
continue;
Command cmd = (Command)field.get(this);
commands.put(cmd.getName(), cmd);
}
}catch(Exception e)
{
System.out.println("Error initializing Aoba commands.");
System.out.println(e.getStackTrace().toString());
}
}

/**
Expand Down Expand Up @@ -94,6 +112,7 @@ public int getNumOfCommands() {
*/
public void command(String[] commandIn) {
try {

// Get the command from the user's message. (Index 0 is Username)
Command command = commands.get(commandIn[1]);

Expand All @@ -110,10 +129,10 @@ public void command(String[] commandIn) {
}

// Runs the command.
command.command(parameterList);
command.runCommand(parameterList);
}
} catch (Exception e) {
sendChatMessage("Error occured whilst running command. Please try again.");
System.out.println("Error occured whilst running command. Please try again.");
e.printStackTrace();
}
}
Expand All @@ -124,6 +143,6 @@ public void command(String[] commandIn) {
*/
public static void sendChatMessage(String message) {
MinecraftClient mc = MinecraftClient.getInstance();
mc.inGameHud.getChatHud().addMessage(Text.of("§5[Aoba] §f" + message));
mc.inGameHud.getChatHud().addMessage(Text.of("§5[Aoba]§f " + message));
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdAimbot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdAimbot extends Command {

public CmdAimbot() {
this.description = "Allows the player to see chest locations through ESP";
super("aimbot", "Allows the player to see chest locations through ESP");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
Aimbot module = (Aimbot) Aoba.getInstance().moduleManager.aimbot;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand All @@ -54,4 +54,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba aimbot [toggle/mode] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdAutoEat.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdAutoEat extends Command {

public CmdAutoEat() {
this.description = "Allows the player to see chest locations through ESP";
super("autoeat", "Automatically eats when the player is hungry.");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
AutoEat module = (AutoEat) Aoba.getInstance().moduleManager.autoeat;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand Down Expand Up @@ -63,4 +63,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba autoeat [toggle/set] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdChestESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdChestESP extends Command {

public CmdChestESP() {
this.description = "Allows the player to see chest locations through ESP";
super("chestesp", "Allows the player to see chest locations through ESP");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
ChestESP module = (ChestESP) Aoba.getInstance().moduleManager.chestesp;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand All @@ -54,4 +54,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba chestesp [toggle] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdEntityESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdEntityESP extends Command {

public CmdEntityESP() {
this.description = "Allows the player to see mobs through ESP.";
super("entityesp", "Allows the player to see mobs through ESP.");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
EntityESP module = (EntityESP) Aoba.getInstance().moduleManager.entityesp;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand All @@ -54,4 +54,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba entityesp [toggle] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdFastBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdFastBreak extends Command {

public CmdFastBreak() {
this.description = "Decreases the time it takes to break blocks";
super("fastbreak", "Decreases the time it takes to break blocks");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
FastBreak module = (FastBreak) Aoba.getInstance().moduleManager.fastbreak;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand Down Expand Up @@ -65,4 +65,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba fastbreak [multiplier, toggle] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
21 changes: 15 additions & 6 deletions src/main/java/net/aoba/cmd/commands/CmdFly.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@
public class CmdFly extends Command {

public CmdFly() {
this.description = "Allows the player to fly";
super("fly", "Allows the player to fly");
}

@Override
public void command(String[] parameters) {
for(int i = 0; i < parameters.length; i++) {
System.out.println(parameters[i]);
}
Fly module = (Fly) Aoba.getInstance().moduleManager.fly;
public void runCommand(String[] parameters) {
if (parameters.length == 2) {
Fly module = (Fly) Aoba.getInstance().moduleManager.fly;
switch (parameters[0]) {
case "speed":
try {
Expand Down Expand Up @@ -67,4 +64,16 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba fly [speed, toggle] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
switch(previousParameter) {
case "toggle":
return new String[] {"on", "off"};
case "speed":
return new String[] {"0.0", "1.0", "5.0", "10.0"};
default:
return new String[] {"speed", "toggle"};
}
}
}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdFreecam.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdFreecam extends Command {

public CmdFreecam() {
this.description = "Disables fall damage for the player";
super("freecam", "Disables fall damage for the player");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
Freecam module = (Freecam) Aoba.getInstance().moduleManager.freecam;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand All @@ -55,4 +55,10 @@ public void command(String[] parameters) {
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}

}
10 changes: 8 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdFullbright.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public class CmdFullbright extends Command {

public CmdFullbright() {
this.description = "Brightens up the world!";
super("fullbright", "Brightens up the world!");
}

@Override
public void command(String[] parameters) {
public void runCommand(String[] parameters) {
Fullbright module = (Fullbright) Aoba.getInstance().moduleManager.fullbright;
if (parameters.length == 2) {
switch (parameters[0]) {
Expand All @@ -54,4 +54,10 @@ public void command(String[] parameters) {
CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba fullbright [toggle] [value]");
}
}

@Override
public String[] getAutocorrect(String previousParameter) {
// TODO Auto-generated method stub
return null;
}
}
Loading

0 comments on commit de8f1ba

Please sign in to comment.