2020-01-21 21:04:44 +01:00
|
|
|
/* TODO commands
|
2018-10-25 18:49:42 +02:00
|
|
|
package de.ellpeck.naturesaura.commands;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
import com.mojang.brigadier.Command;
|
2018-10-25 18:49:42 +02:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2018-10-25 18:49:42 +02:00
|
|
|
import net.minecraft.command.*;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.util.text.StringTextComponent;
|
2018-10-25 18:49:42 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
public class CommandAura extends Command {
|
2018-10-25 18:49:42 +02:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "naaura";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public String getUsage(ICommandSource sender) {
|
2018-10-25 18:49:42 +02:00
|
|
|
return "command." + NaturesAura.MOD_ID + ".aura.usage";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void execute(MinecraftServer server, ICommandSource sender, String[] args) throws CommandException {
|
2018-12-25 18:16:32 +01:00
|
|
|
if (args.length < 2)
|
|
|
|
throw new WrongUsageException(this.getUsage(sender));
|
2018-10-25 18:49:42 +02:00
|
|
|
World world = sender.getEntityWorld();
|
|
|
|
BlockPos pos = sender.getPosition();
|
|
|
|
|
2018-12-25 18:16:32 +01:00
|
|
|
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);
|
|
|
|
}
|
2019-10-20 22:30:49 +02:00
|
|
|
sender.sendMessage(new StringTextComponent("Stored Aura successfully"));
|
2018-12-25 18:16:32 +01:00
|
|
|
} 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);
|
|
|
|
}
|
2019-10-20 22:30:49 +02:00
|
|
|
sender.sendMessage(new StringTextComponent("Drained Aura successfully"));
|
2018-12-25 18:16:32 +01:00
|
|
|
} 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);
|
|
|
|
});
|
2019-10-20 22:30:49 +02:00
|
|
|
sender.sendMessage(new StringTextComponent("Reset Aura successfully"));
|
2018-10-25 18:49:42 +02:00
|
|
|
} else {
|
|
|
|
throw new SyntaxErrorException("Invalid action " + action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 18:16:32 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 18:49:42 +02:00
|
|
|
@Override
|
|
|
|
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
|
|
|
|
if (args.length == 1) {
|
2018-12-25 18:16:32 +01:00
|
|
|
return getListOfStringsMatchingLastWord(args, "store", "drain", "reset");
|
2018-10-25 18:49:42 +02:00
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 21:04:44 +01:00
|
|
|
*/
|