Search in sources :

Example 6 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project ArsMagica2 by Mithion.

the class GiveSkillPoints method processCommand.

@Override
public void processCommand(ICommandSender var1, String[] var2) {
    if (var2.length != 4 && var2.length != 3) {
        throw new WrongUsageException(this.getCommandUsage(var1), new Object[0]);
    }
    EntityPlayer player = null;
    int target_blue = parseIntBounded(var1, var2[0], 0, 50);
    int target_green = parseIntBounded(var1, var2[1], 0, 50);
    int target_red = parseIntBounded(var1, var2[2], 0, 50);
    if (var2.length == 4) {
        if (var2[3].equals("@a")) {
            EntityPlayerMP[] players = PlayerSelector.matchPlayers(var1, var2[3]);
            if (players != null) {
                for (EntityPlayerMP p : players) {
                    doGiveSkillPoints(var1, p, target_blue, target_green, target_red);
                }
            }
        } else {
            player = getPlayer(var1, var2[3]);
        }
    } else {
        player = getCommandSenderAsPlayer(var1);
    }
    doGiveSkillPoints(var1, player, target_blue, target_green, target_red);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 7 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project ArsMagica2 by Mithion.

the class SetSkillKnown method processCommand.

@Override
public void processCommand(ICommandSender var1, String[] var2) {
    if (var2.length != 2 && var2.length != 1) {
        throw new WrongUsageException(this.getCommandUsage(var1), new Object[0]);
    }
    EntityPlayer player = null;
    String skill = "";
    if (var2.length == 2) {
        player = getPlayer(var1, var2[0]);
        skill = var2[1];
    } else {
        player = getCommandSenderAsPlayer(var1);
        skill = var2[0];
    }
    if (player == null)
        return;
    ISkillTreeEntry entry = SkillManager.instance.getSkill(skill);
    SkillData.For(player).learn(entry);
    func_152373_a(var1, this, "Unlocking " + skill + " for " + player.getCommandSenderName(), new Object[0]);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 8 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Railcraft by Railcraft.

the class CommandHelpers method executeChildCommand.

public static void executeChildCommand(MinecraftServer server, ICommandSender sender, SubCommand child, String[] args) throws CommandException {
    if (!sender.canCommandSenderUseCommand(child.getPermissionLevel(), child.getFullCommandString()))
        throw new WrongUsageException(LocalizationPlugin.translate("command.railcraft.noperms"));
    String[] newArgs = new String[args.length - 1];
    System.arraycopy(args, 1, newArgs, 0, newArgs.length);
    child.execute(server, sender, newArgs);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project ICBM-Classic by BuiltBrokenModding.

the class CommandICBM method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) {
    try {
        EntityPlayer entityPlayer = (EntityPlayer) sender;
        int dimension = entityPlayer.worldObj.provider.dimensionId;
        if (args == null || args.length == 0 || args[0].equalsIgnoreCase("help")) {
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc help"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc lag <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc remove <All/Missile/Explosion> <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc emp <radius>"));
            return;
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("lag")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(entityPlayer.posX - radius, entityPlayer.posY - radius, entityPlayer.posZ - radius, entityPlayer.posX + radius, entityPlayer.posY + radius, entityPlayer.posZ + radius);
                List<Entity> entitiesNearby = entityPlayer.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if (entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if (entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if (entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM lag sources within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 3 && args[0].equalsIgnoreCase("remove")) {
            int radius = parseInt(sender, args[2]);
            boolean all = args[1].equalsIgnoreCase("all");
            boolean missile = args[1].equalsIgnoreCase("missiles");
            boolean explosion = args[1].equalsIgnoreCase("explosion");
            String str = "entities";
            if (missile) {
                str = "missiles";
            }
            if (explosion) {
                str = "explosions";
            }
            if (radius > 0) {
                EntityPlayer player = (EntityPlayer) sender;
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(player.posX - radius, player.posY - radius, player.posZ - radius, player.posX + radius, player.posY + radius, player.posZ + radius);
                List<Entity> entitiesNearby = player.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if ((all || explosion) && entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if ((all || missile) && entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if ((all || explosion) && entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM " + str + " within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("emp")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                new BlastEMP(entityPlayer.worldObj, null, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, radius).setEffectBlocks().setEffectEntities().doExplode();
                switch(entityPlayer.worldObj.rand.nextInt(20)) {
                    case 0:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Did you pay the power bill?"));
                        return;
                    case 1:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("See them power their toys now!"));
                        return;
                    case 2:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Hey who turned the lights out."));
                        return;
                    case 3:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Ha! I run on steam power!"));
                        return;
                    case 4:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("The power of lighting at my finger tips!"));
                        return;
                    default:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Zap!"));
                        return;
                }
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        }
    } catch (Exception e) {
    }
    throw new WrongUsageException(this.getCommandUsage(sender));
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityMissile(icbm.classic.content.entity.EntityMissile) BlastEMP(icbm.classic.content.explosive.blast.BlastEMP) WrongUsageException(net.minecraft.command.WrongUsageException) WrongUsageException(net.minecraft.command.WrongUsageException) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 10 with WrongUsageException

use of net.minecraft.command.WrongUsageException 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)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)19 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 CommandException (net.minecraft.command.CommandException)6 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ItemModule (net.geforcemods.securitycraft.items.ItemModule)3 ChatComponentText (net.minecraft.util.ChatComponentText)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)3 Affinity (am2.api.spell.enums.Affinity)2 List (java.util.List)2 ICommand (net.minecraft.command.ICommand)2 ChunkPosition (net.minecraft.world.ChunkPosition)2 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 EntityMissile (icbm.classic.content.entity.EntityMissile)1 BlastEMP (icbm.classic.content.explosive.blast.BlastEMP)1 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 BlockStates (ivorius.ivtoolkit.blocks.BlockStates)1