NaturesAura/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java

67 lines
2.3 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.commands;
import de.ellpeck.naturesaura.NaturesAura;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.command.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
public class CommandAura extends CommandBase {
@Override
public String getName() {
return "naaura";
}
@Override
public String getUsage(ICommandSender sender) {
return "command." + NaturesAura.MOD_ID + ".aura.usage";
}
@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");
}
World world = sender.getEntityWorld();
BlockPos pos = sender.getPosition();
if ("add".equals(action)) {
2018-11-11 13:26:19 +01:00
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)) {
2018-11-11 13:26:19 +01:00
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, range, pos);
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
sender.sendMessage(new TextComponentString("Removed " + amount + " aura"));
} else {
throw new SyntaxErrorException("Invalid action " + action);
}
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, "add", "remove");
} else {
return Collections.emptyList();
}
}
}