Feature/aliases to close #358 (#376)

* Add Aliases

* Add aliases cmd and cmds to CommandsCommand

* undo build.gradle changes

* shorten check in commandmanager

* add more aliases

Co-authored-by: d1gress <55198830+d1gress@users.noreply.github.com>
Co-authored-by: Qther <dtaclanlegion@gmail.com>
This commit is contained in:
Bella Who 2020-01-14 08:53:29 -05:00 committed by GitHub
parent a8f824ba5c
commit ccc6db61ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 37 additions and 13 deletions

View File

@ -10,6 +10,8 @@ import net.minecraft.launchwrapper.LogWrapper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentBase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -18,6 +20,7 @@ public abstract class Command {
protected String label;
protected String syntax;
protected String description;
protected ArrayList<String> aliases;
public final Minecraft mc = Minecraft.getMinecraft();
@ -26,10 +29,18 @@ public abstract class Command {
public static Setting<String> commandPrefix = Settings.s("commandPrefix", ".");
public static final char SECTION_SIGN = '\u00A7';
public Command(String label, SyntaxChunk[] syntaxChunks) {
public Command(String label, SyntaxChunk[] syntaxChunks, ArrayList<String> aliases) {
this.label = label;
this.syntaxChunks = syntaxChunks;
this.description = "Descriptionless";
this.aliases = aliases;
}
public Command(String label, SyntaxChunk[] syntaxChunks, String... aliases) {
this.label = label;
this.syntaxChunks = syntaxChunks;
this.description = "Descriptionless";
this.aliases = new ArrayList<String>(Arrays.asList(aliases));
}
public static void sendChatMessage(String message) {
@ -81,6 +92,10 @@ public abstract class Command {
return label;
}
public ArrayList<String> getAliases() {
return aliases;
}
public abstract void call(String[] args);
public SyntaxChunk[] getSyntaxChunks() {

View File

@ -44,12 +44,21 @@ public class CommandManager {
for (Command c : commands) {
if (c.getLabel().equalsIgnoreCase(label)) {
if (!c.getAliases().isEmpty()) {
Command.sendChatMessage("This command has aliases!\n" + String.join(", ", c.getAliases()));
}
c.call(parts);
return;
}
else for (int i = 0; i < c.getAliases().size(); i++) {
if (c.getAliases().get(i).equalsIgnoreCase(label)) {
c.call(parts);
return;
}
}
}
Command.sendChatMessage("Unknown command. try 'commands' for a list of commands.");
Command.sendChatMessage("Unknown command. try 'cmds' for a list of commands.");
}
public static String[] removeElement(String[] input, int indexToDelete) {

View File

@ -12,7 +12,7 @@ import java.util.Comparator;
public class CommandsCommand extends Command {
public CommandsCommand() {
super("commands", SyntaxChunk.EMPTY);
super("commands", SyntaxChunk.EMPTY, "cmd", "cmds");
setDescription("Gives you this list of commands");
}

View File

@ -22,7 +22,7 @@ public class ConfigCommand extends Command {
super("config", new ChunkBuilder()
.append("mode", true, new EnumParser(new String[]{"reload", "save", "path"}))
.append("path", true, new DependantParser(0, new DependantParser.Dependency(new String[][]{{"path", "path"}}, "")))
.build());
.build(), "cfg");
setDescription("Change where your config is saved or manually save and reload your config");
}

View File

@ -9,7 +9,7 @@ import me.zeroeightsix.kami.command.Command;
public class CreditsCommand extends Command {
public CreditsCommand() {
super("credits", null);
super("credits", null, "creds");
setDescription("Prints KAMI Blue's authors and contributors");
}

View File

@ -15,7 +15,7 @@ import java.math.RoundingMode;
public class EntityStatsCommand extends Command {
public EntityStatsCommand() {
super("entitystats", null);
super("entitystats", null, "estats", "horestats", "hstats", "vehiclestats");
setDescription("Print the statistics of the entity you're currently riding");
}

View File

@ -26,7 +26,7 @@ public class FriendCommand extends Command {
super("friend", new ChunkBuilder()
.append("mode", true, new EnumParser(new String[]{"add", "del"}))
.append("name")
.build());
.build(), "friends", "f");
setDescription("Add someone as your friend!");
}

View File

@ -34,7 +34,7 @@ public class HelpCommand extends Command {
}
public HelpCommand() {
super("help", new SyntaxChunk[]{});
super("help", new SyntaxChunk[]{}, "?");
setDescription("Delivers help on certain subjects. Use &b" + Command.getCommandPrefix() + "help subjects&8 for a list.");
}

View File

@ -10,7 +10,7 @@ import net.minecraft.pathfinding.PathPoint;
*/
public class PathCommand extends Command {
public PathCommand() {
super("path", new ChunkBuilder().append("x").append("y").append("z").build());
super("path", new ChunkBuilder().append("x").append("y").append("z").build(), "pathfind");
setDescription("Pathfinding for AutoWalk");
}

View File

@ -22,7 +22,7 @@ import io.netty.buffer.Unpooled;
public class SignBookCommand extends Command {
public SignBookCommand() {
super("signbook", new ChunkBuilder().append("name").build());
super("signbook", new ChunkBuilder().append("name").build(), "book", "sign");
setDescription("Colored book names. #n for a new line and & for color codes");
}

View File

@ -26,7 +26,7 @@ public class TeleportCommand extends Command {
.append("y", true)
.append("z", true)
.append("blocks per tp", false)
.build());
.build(), "tp");
setDescription("Potentia teleport exploit");
}

View File

@ -14,7 +14,7 @@ public class ToggleCommand extends Command {
public ToggleCommand() {
super("toggle", new ChunkBuilder()
.append("module", true, new ModuleParser())
.build());
.build(), "t");
setDescription("Quickly toggle a module on and off");
}

View File

@ -14,7 +14,7 @@ public class VanishCommand extends Command {
Minecraft mc = Minecraft.getMinecraft();
public VanishCommand() {
super("vanish", null);
super("vanish", null, "entitydesync", "edesync", "entityvanish", "evanish", "ev", "van");
setDescription("Allows you to vanish using an entity");
}