mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
rework the aura command a bit and add a reset function
This commit is contained in:
parent
94e8dba296
commit
01af6975fd
2 changed files with 42 additions and 24 deletions
|
@ -25,40 +25,58 @@ public class CommandAura extends CommandBase {
|
|||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length != 3) {
|
||||
throw new SyntaxErrorException("Wrong number of arguments");
|
||||
}
|
||||
|
||||
String action = args[0];
|
||||
int amount;
|
||||
int range;
|
||||
try {
|
||||
amount = Integer.parseInt(args[1]);
|
||||
range = Integer.parseInt(args[2]);
|
||||
} catch (Exception e) {
|
||||
throw new NumberInvalidException("Invalid number");
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
throw new WrongUsageException(this.getUsage(sender));
|
||||
World world = sender.getEntityWorld();
|
||||
BlockPos pos = sender.getPosition();
|
||||
|
||||
if ("add".equals(action)) {
|
||||
BlockPos spot = IAuraChunk.getLowestSpot(world, pos, range, pos);
|
||||
IAuraChunk.getAuraChunk(world, spot).storeAura(spot, amount);
|
||||
sender.sendMessage(new TextComponentString("Added " + amount + " aura"));
|
||||
} else if ("remove".equals(action)) {
|
||||
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, range, pos);
|
||||
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
|
||||
sender.sendMessage(new TextComponentString("Removed " + amount + " aura"));
|
||||
String action = args[0];
|
||||
if ("store".equals(action)) {
|
||||
int amount = parse(args, 1, -1);
|
||||
int range = parse(args, 2, 35);
|
||||
while (amount > 0) {
|
||||
BlockPos spot = IAuraChunk.getLowestSpot(world, pos, range, pos);
|
||||
amount -= IAuraChunk.getAuraChunk(world, spot).storeAura(spot, amount);
|
||||
}
|
||||
sender.sendMessage(new TextComponentString("Stored Aura successfully"));
|
||||
} else if ("drain".equals(action)) {
|
||||
int amount = parse(args, 1, -1);
|
||||
int range = parse(args, 2, 35);
|
||||
while (amount > 0) {
|
||||
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, range, pos);
|
||||
amount -= IAuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
|
||||
}
|
||||
sender.sendMessage(new TextComponentString("Drained Aura successfully"));
|
||||
} else if ("reset".equals(action)) {
|
||||
int range = parse(args, 1, -1);
|
||||
IAuraChunk.getSpotsInArea(world, pos, range, (spot, amount) -> {
|
||||
IAuraChunk chunk = IAuraChunk.getAuraChunk(world, spot);
|
||||
if (amount > 0)
|
||||
chunk.drainAura(spot, amount);
|
||||
else
|
||||
chunk.storeAura(spot, -amount);
|
||||
});
|
||||
sender.sendMessage(new TextComponentString("Reset Aura successfully"));
|
||||
} else {
|
||||
throw new SyntaxErrorException("Invalid action " + action);
|
||||
}
|
||||
}
|
||||
|
||||
private static int parse(String[] args, int argNum, int def) throws NumberInvalidException {
|
||||
try {
|
||||
return Integer.parseInt(args[argNum]);
|
||||
} catch (Exception e) {
|
||||
if (def < 0)
|
||||
throw new NumberInvalidException("Invalid number " + args[argNum]);
|
||||
else
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsMatchingLastWord(args, "add", "remove");
|
||||
return getListOfStringsMatchingLastWord(args, "store", "drain", "reset");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -124,6 +124,6 @@ advancement.naturesaura.negative_imbalance.desc=Drain enough Aura to cause negat
|
|||
advancement.naturesaura.end_flower=Blue Lotus
|
||||
advancement.naturesaura.end_flower.desc=Kill the Ender Dragon to make a Rose of Oblivion grow
|
||||
|
||||
command.naturesaura.aura.usage=/naaura <action> <amount> <range>
|
||||
command.naturesaura.aura.usage=/naaura store|drain <amount> [range] OR /naaura reset <range>
|
||||
|
||||
potion.naturesaura.breathless.name=Breathless
|
Loading…
Reference in a new issue