better arguments

This commit is contained in:
0x3C50 2022-04-15 03:03:59 +02:00
parent b92d1e1247
commit 484080aaca
4 changed files with 48 additions and 24 deletions

View file

@ -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());
}
}

View file

@ -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<String> {
@Override
public String parse(String argument) {
return argument;
}
}

View file

@ -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);
}

View file

@ -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())
)
)
);