From 484080aacaaa08eff1aebc07d4ee4b67fad9c45b Mon Sep 17 00:00:00 2001 From: 0x3C50 Date: Fri, 15 Apr 2022 03:03:59 +0200 Subject: [PATCH] better arguments --- .../argument/StreamlineArgumentParser.java | 34 +++++++++++++++++++ .../argument/StringArgumentParser.java | 12 ------- .../client/feature/command/impl/ApplyVel.java | 9 ++--- .../feature/command/impl/SpawnData.java | 17 +++++----- 4 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 src/main/java/net/shadow/client/feature/command/argument/StreamlineArgumentParser.java delete mode 100644 src/main/java/net/shadow/client/feature/command/argument/StringArgumentParser.java diff --git a/src/main/java/net/shadow/client/feature/command/argument/StreamlineArgumentParser.java b/src/main/java/net/shadow/client/feature/command/argument/StreamlineArgumentParser.java new file mode 100644 index 0000000..c86f668 --- /dev/null +++ b/src/main/java/net/shadow/client/feature/command/argument/StreamlineArgumentParser.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved. + */ + +package net.shadow.client.feature.command.argument; + +import net.minecraft.entity.player.PlayerEntity; +import net.shadow.client.feature.command.exception.CommandException; + +public class StreamlineArgumentParser { + String[] args; + int index = 0; + public StreamlineArgumentParser(String[] args) { + this.args = args; + } + public String consumeString() throws CommandException { + if (index >= args.length) throw new CommandException("Not enough arguments", null); + String el = args[index]; + index++; + return el; + } + public int consumeInt() throws CommandException { + return new IntegerArgumentParser().parse(consumeString()); + } + public double consumeDouble() throws CommandException { + return new DoubleArgumentParser().parse(consumeString()); + } + public PlayerEntity consumePlayerEntityFromName(boolean ignoreCase) throws CommandException { + return new PlayerFromNameArgumentParser(ignoreCase).parse(consumeString()); + } + public PlayerEntity consumePlayerEntityFromUuid() throws CommandException { + return new PlayerFromUuidArgumentParser().parse(consumeString()); + } +} diff --git a/src/main/java/net/shadow/client/feature/command/argument/StringArgumentParser.java b/src/main/java/net/shadow/client/feature/command/argument/StringArgumentParser.java deleted file mode 100644 index b15a11d..0000000 --- a/src/main/java/net/shadow/client/feature/command/argument/StringArgumentParser.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved. - */ - -package net.shadow.client.feature.command.argument; - -public class StringArgumentParser implements ArgumentParser { - @Override - public String parse(String argument) { - return argument; - } -} diff --git a/src/main/java/net/shadow/client/feature/command/impl/ApplyVel.java b/src/main/java/net/shadow/client/feature/command/impl/ApplyVel.java index 80d40a3..3c8933d 100644 --- a/src/main/java/net/shadow/client/feature/command/impl/ApplyVel.java +++ b/src/main/java/net/shadow/client/feature/command/impl/ApplyVel.java @@ -7,6 +7,7 @@ package net.shadow.client.feature.command.impl; import net.shadow.client.ShadowMain; import net.shadow.client.feature.command.Command; import net.shadow.client.feature.command.argument.DoubleArgumentParser; +import net.shadow.client.feature.command.argument.StreamlineArgumentParser; import net.shadow.client.feature.command.coloring.ArgumentType; import net.shadow.client.feature.command.coloring.StaticArgumentServer; import net.shadow.client.feature.command.exception.CommandException; @@ -39,10 +40,10 @@ public class ApplyVel extends Command { public void onExecute(String[] args) throws CommandException { validateArgumentsLength(args, 3, "Provide X, Y and Z velocity"); - DoubleArgumentParser dap = new DoubleArgumentParser(); - Double vx = dap.parse(args[0]); - Double vy = dap.parse(args[1]); - Double vz = dap.parse(args[2]); + StreamlineArgumentParser dap = new StreamlineArgumentParser(args); + double vx = dap.consumeDouble(); + double vy = dap.consumeDouble(); + double vz = dap.consumeDouble(); ShadowMain.client.player.addVelocity(vx, vy, vz); } diff --git a/src/main/java/net/shadow/client/feature/command/impl/SpawnData.java b/src/main/java/net/shadow/client/feature/command/impl/SpawnData.java index c7967b1..860edfb 100644 --- a/src/main/java/net/shadow/client/feature/command/impl/SpawnData.java +++ b/src/main/java/net/shadow/client/feature/command/impl/SpawnData.java @@ -11,6 +11,7 @@ import net.minecraft.util.math.Vec3d; import net.shadow.client.ShadowMain; import net.shadow.client.feature.command.Command; import net.shadow.client.feature.command.argument.DoubleArgumentParser; +import net.shadow.client.feature.command.argument.StreamlineArgumentParser; import net.shadow.client.feature.command.coloring.ArgumentType; import net.shadow.client.feature.command.exception.CommandException; import net.shadow.client.helper.nbt.NbtGroup; @@ -57,8 +58,8 @@ public class SpawnData extends Command { @Override public void onExecute(String[] args) throws CommandException { validateArgumentsLength(args, 1, "Provide data point"); - DoubleArgumentParser dap = new DoubleArgumentParser(); - switch (args[0].toLowerCase()) { + StreamlineArgumentParser parser = new StreamlineArgumentParser(args); + switch (parser.consumeString().toLowerCase()) { case "position" -> { validateArgumentsLength(args, 4, "Provide X, Y and Z coordinates"); ItemStack stack = ShadowMain.client.player.getInventory().getMainHandStack(); @@ -68,9 +69,9 @@ public class SpawnData extends Command { NbtGroup ng = new NbtGroup( new NbtObject("EntityTag", new NbtList("Pos", - new NbtProperty(dap.parse(args[1])), - new NbtProperty(dap.parse(args[2])), - new NbtProperty(dap.parse(args[3])) + new NbtProperty(parser.consumeDouble()), + new NbtProperty(parser.consumeDouble()), + new NbtProperty(parser.consumeDouble()) ) ) ); @@ -87,9 +88,9 @@ public class SpawnData extends Command { NbtGroup ng = new NbtGroup( new NbtObject("EntityTag", new NbtList("Motion", - new NbtProperty(dap.parse(args[1])), - new NbtProperty(dap.parse(args[2])), - new NbtProperty(dap.parse(args[3])) + new NbtProperty(parser.consumeDouble()), + new NbtProperty(parser.consumeDouble()), + new NbtProperty(parser.consumeDouble()) ) ) );