Search in sources :

Example 1 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandSelectFill method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc().move(1).metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    String shape = parameters.get("shape").first().optional().orElse("cube");
    BlockArea area = selectionOwner.getSelection();
    BlockPos p1 = area.getPoint1();
    BlockPos p2 = area.getPoint2();
    switch(shape) {
        case "cube":
            for (BlockPos pos : area) {
                IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                world.setBlockState(pos, state, 2);
            }
            break;
        case "sphere":
            {
                double[] spheroidOrigin = new double[] { (p1.getX() + p2.getX()) * 0.5, (p1.getY() + p2.getY()) * 0.5, (p1.getZ() + p2.getZ()) * 0.5 };
                int[] areaSize = area.areaSize();
                double[] spheroidSize = new double[] { areaSize[0] * 0.5, areaSize[1] * 0.5, areaSize[2] * 0.5 };
                for (BlockPos coord : area) {
                    double[] coordPoint = new double[] { coord.getX(), coord.getY(), coord.getZ() };
                    if (IvShapeHelper.isPointInSpheroid(coordPoint, spheroidOrigin, spheroidSize)) {
                        IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                        world.setBlockState(coord, state, 2);
                    }
                }
                break;
            }
        default:
            throw new WrongUsageException(getUsage(commandSender));
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IntStream(java.util.stream.IntStream) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) IvShapeHelper(ivorius.ivtoolkit.math.IvShapeHelper) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) WrongUsageException(net.minecraft.command.WrongUsageException) IBlockState(net.minecraft.block.state.IBlockState) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandSelectReplace method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc("metadata").metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    PositionedBlockExpression matcher = parameters.rc().move(1).expression(new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos coord : selectionOwner.getSelection()) {
        if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, coord))) {
            IBlockState state = dst.get(world.rand().nextInt(dst.size()));
            world.setBlockState(coord, state, 3);
        }
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IntStream(java.util.stream.IntStream) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IBlockState(net.minecraft.block.state.IBlockState) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with CommandException

use of net.minecraft.command.CommandException in project SpongeCommon by SpongePowered.

the class MixinCommandTP method execute.

/**
 * @author blood - May 31st, 2016
 * @author gabizou - May 31st, 2016 - Update to 1.9.4
 * @author Aaron1011 - August 15, 2016 - Update to 1.10.2
 * @reason to fix LVT errors with SpongeForge
 *
 * @param sender The command source
 * @param args The command arguments
 */
@Override
@Overwrite
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 1) {
        throw new WrongUsageException("commands.tp.usage", new Object[0]);
    } else {
        int i = 0;
        Entity entity;
        if (args.length != 2 && args.length != 4 && args.length != 6) {
            entity = getCommandSenderAsPlayer(sender);
        } else {
            entity = getEntity(server, sender, args[0]);
            i = 1;
        }
        if (args.length != 1 && args.length != 2) {
            if (args.length < i + 3) {
                throw new WrongUsageException("commands.tp.usage", new Object[0]);
            } else if (entity.world != null) {
                // int j = 4096;
                int lvt_6_2_ = i + 1;
                CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(entity.posX, args[i], true);
                CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(entity.posY, args[lvt_6_2_++], -4096, 4096, false);
                CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(entity.posZ, args[lvt_6_2_++], true);
                CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate((double) entity.rotationYaw, args.length > lvt_6_2_ ? args[lvt_6_2_++] : "~", false);
                CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate((double) entity.rotationPitch, args.length > lvt_6_2_ ? args[lvt_6_2_] : "~", false);
                // Sponge start - check shouldNotifyCommandListener before calling 'notifyCommandListener'
                // Guard against any possible re-entrance
                boolean shouldNotify = shouldNotifyCommandListener;
                teleportEntityToCoordinates(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
                if (shouldNotifyCommandListener) {
                    notifyCommandListener(sender, this, "commands.tp.success.coordinates", new Object[] { entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult()) });
                }
                shouldNotifyCommandListener = shouldNotify;
            // Sponge end
            }
        } else {
            Entity entity1 = getEntity(server, sender, args[args.length - 1]);
            if (entity1.world != entity.world) {
                throw new CommandException("commands.tp.notSameDimension", new Object[0]);
            } else {
                entity.dismountRidingEntity();
                if (entity instanceof EntityPlayerMP) {
                    // Sponge start
                    EntityPlayerMP player = (EntityPlayerMP) entity;
                    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        frame.addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.COMMAND);
                        MoveEntityEvent.Teleport event = EntityUtil.handleDisplaceEntityTeleportEvent(entity, entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
                        if (event.isCancelled()) {
                            return;
                        }
                        Vector3d position = event.getToTransform().getPosition();
                        player.connection.setPlayerLocation(position.getX(), position.getY(), position.getZ(), (float) event.getToTransform().getYaw(), (float) event.getToTransform().getPitch());
                    }
                // Sponge end
                } else {
                    // Sponge Start - Events
                    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        frame.addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.COMMAND);
                        MoveEntityEvent.Teleport event = EntityUtil.handleDisplaceEntityTeleportEvent(entity, entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
                        if (event.isCancelled()) {
                            return;
                        }
                        Vector3d position = event.getToTransform().getPosition();
                        entity.setLocationAndAngles(position.getX(), position.getY(), position.getZ(), (float) event.getToTransform().getYaw(), (float) event.getToTransform().getPitch());
                    }
                // Sponge End
                }
                notifyCommandListener(sender, this, "commands.tp.success", new Object[] { entity.getName(), entity1.getName() });
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) WrongUsageException(net.minecraft.command.WrongUsageException) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with CommandException

use of net.minecraft.command.CommandException in project HorsePower by GoryMoon.

the class HorsePowerCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 1) {
        if ("entity".equals(args[0])) {
            if (sender instanceof EntityPlayerSP) {
                RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
                if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
                    Entity entity = result.entityHit;
                    sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.has", entity.getClass().getName()));
                    try {
                        StringSelection selection = new StringSelection(entity.getClass().getName());
                        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
                    } catch (Exception ignored) {
                    }
                } else
                    sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.no"));
            } else
                throw new CommandException("commands.horsepower.entity.invalid");
            return;
        }
        if ("reload".equals(args[0])) {
            sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload").setStyle(new Style().setColor(TextFormatting.YELLOW).setBold(true)));
            HPEventHandler.reloadConfig();
            boolean hasErrors = HPRecipes.ERRORS.size() > 0;
            Utils.sendSavedErrors();
            if (hasErrors)
                sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.error").setStyle(new Style().setColor(TextFormatting.DARK_RED).setBold(true)));
            else
                sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.noerror").setStyle(new Style().setColor(TextFormatting.GREEN).setBold(true)));
            return;
        }
    }
    throw new WrongUsageException(getUsage(sender));
}
Also used : Entity(net.minecraft.entity.Entity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WrongUsageException(net.minecraft.command.WrongUsageException) RayTraceResult(net.minecraft.util.math.RayTraceResult) Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) StringSelection(java.awt.datatransfer.StringSelection)

Example 5 with CommandException

use of net.minecraft.command.CommandException in project Minestuck by mraof.

the class ServerEditHandler method onCommandEvent.

@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = false)
public void onCommandEvent(CommandEvent event) {
    if (list.isEmpty())
        return;
    try {
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        if (commands.contains(event.getCommand().getName())) {
            String c = event.getCommand().getName();
            EntityPlayer target;
            if (c.equals("kill") || (c.equals("clear") || c.equals("spawnpoint")) && event.getParameters().length == 0 || c.equals("tp") && event.getParameters().length != 2 && event.getParameters().length != 4 || c.equals("setworldspawn") && (event.getParameters().length == 0 || event.getParameters().length == 3))
                target = CommandBase.getCommandSenderAsPlayer(event.getSender());
            else if (c.equals("defaultgamemode") && server.getForceGamemode()) {
                for (EditData data : (EditData[]) list.toArray()) reset(data);
                return;
            } else if (c.equals("spreadplayers")) {
                ArrayList<EntityPlayer> targets = new ArrayList<EntityPlayer>();
                for (int i = 5; i < event.getParameters().length; i++) {
                    String s = event.getParameters()[i];
                    if (EntitySelector.isSelector(s)) {
                        Entity[] list = (Entity[]) EntitySelector.matchEntities(event.getSender(), s, Entity.class).toArray();
                        if (list.length == 0)
                            return;
                        for (Entity e : list) if (e instanceof EntityPlayer)
                            targets.add((EntityPlayer) e);
                    } else {
                        EntityPlayer player = server.getPlayerList().getPlayerByUsername(s);
                        if (player == null)
                            return;
                        targets.add(player);
                    }
                }
                for (EntityPlayer player : targets) if (getData(player) != null) {
                    reset(getData(player));
                }
                return;
            } else if (c.equals("gamemode") || c.equals("xp"))
                target = event.getParameters().length >= 2 ? CommandBase.getPlayer(server, event.getSender(), event.getParameters()[1]) : CommandBase.getCommandSenderAsPlayer(event.getSender());
            else
                target = CommandBase.getPlayer(server, event.getSender(), event.getParameters()[0]);
            if (target != null && getData(target) != null)
                reset(getData(target));
        }
    } catch (CommandException e) {
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CommandException (net.minecraft.command.CommandException)71 WrongUsageException (net.minecraft.command.WrongUsageException)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)19 ICommandSender (net.minecraft.command.ICommandSender)18 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)15 TextComponentString (net.minecraft.util.text.TextComponentString)15 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 BlockPos (net.minecraft.util.math.BlockPos)11 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 RCCommands (ivorius.reccomplex.commands.RCCommands)9 RCP (ivorius.reccomplex.commands.parameters.RCP)8 List (java.util.List)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7 Parameters (ivorius.mcopts.commands.parameters.Parameters)6