Search in sources :

Example 1 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 2 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 3 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.

the class CommandModule method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 1) {
        if (args[0].matches("copy")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (!player.inventory.getCurrentItem().isEmpty() && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                SecurityCraft.instance.setSavedModule(player.inventory.getCurrentItem().getTagCompound());
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.saved"), TextFormatting.GREEN);
            } else
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.notHoldingForData"), TextFormatting.RED);
            return;
        } else if (args[0].matches("paste")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (SecurityCraft.instance.getSavedModule() == null) {
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.nothingSaved"), TextFormatting.RED);
                return;
            }
            if (!player.inventory.getCurrentItem().isEmpty() && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                player.inventory.getCurrentItem().setTagCompound(SecurityCraft.instance.getSavedModule());
                SecurityCraft.instance.setSavedModule(null);
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.saved"), TextFormatting.GREEN);
            }
            return;
        }
    } else if (args.length == 2)
        if (args[0].matches("add")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (!player.inventory.getCurrentItem().isEmpty() && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                if (player.inventory.getCurrentItem().getTagCompound() == null)
                    player.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
                for (int i = 1; i <= 10; i++) if (player.inventory.getCurrentItem().getTagCompound().hasKey("Player" + i) && player.inventory.getCurrentItem().getTagCompound().getString("Player" + i).matches(args[1])) {
                    PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.alreadyContained").replace("#", args[1]), TextFormatting.RED);
                    return;
                }
                player.inventory.getCurrentItem().getTagCompound().setString("Player" + getNextSlot(player.inventory.getCurrentItem().getTagCompound()), args[1]);
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.added").replace("#", args[1]), TextFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.notHoldingForModify"), TextFormatting.RED);
                return;
            }
        } else if (args[0].matches("remove")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (!player.inventory.getCurrentItem().isEmpty() && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                if (player.inventory.getCurrentItem().getTagCompound() == null)
                    player.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
                for (int i = 1; i <= 10; i++) if (player.inventory.getCurrentItem().getTagCompound().hasKey("Player" + i) && player.inventory.getCurrentItem().getTagCompound().getString("Player" + i).matches(args[1]))
                    player.inventory.getCurrentItem().getTagCompound().removeTag("Player" + i);
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.removed").replace("#", args[1]), TextFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, ClientUtils.localize("messages.module.manager"), ClientUtils.localize("messages.module.notHoldingForModify"), TextFormatting.RED);
                return;
            }
        }
    throw new WrongUsageException(ClientUtils.localize("messages.command.module.usage"));
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemModule(net.geforcemods.securitycraft.items.ItemModule)

Example 4 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)

Example 5 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project SecurityCraft by Geforce132.

the class CommandModule method processCommand.

public void processCommand(ICommandSender par1ICommandSender, String[] par2String) {
    if (par2String.length == 1) {
        if (par2String[0].matches("copy")) {
            EntityPlayer player = HelpfulMethods.getPlayerFromName(par1ICommandSender.getCommandSenderName());
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canBeModified()) {
                mod_SecurityCraft.instance.setSavedModule(player.getCurrentEquippedItem().stackTagCompound);
                HelpfulMethods.sendMessageToPlayer(player, "Module data saved.", EnumChatFormatting.GREEN);
            } else {
                HelpfulMethods.sendMessageToPlayer(player, "You must be holding the module you wish to save data from.", EnumChatFormatting.RED);
            }
            return;
        } else if (par2String[0].matches("paste")) {
            EntityPlayer player = HelpfulMethods.getPlayerFromName(par1ICommandSender.getCommandSenderName());
            if (mod_SecurityCraft.instance.getSavedModule() == null) {
                HelpfulMethods.sendMessageToPlayer(player, "There is no module data saved.", EnumChatFormatting.RED);
                return;
            }
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canBeModified()) {
                player.getCurrentEquippedItem().stackTagCompound = mod_SecurityCraft.instance.getSavedModule();
                mod_SecurityCraft.instance.setSavedModule(null);
                HelpfulMethods.sendMessageToPlayer(player, "Saved data to module.", EnumChatFormatting.GREEN);
            }
            return;
        }
    } else if (par2String.length == 2) {
        if (par2String[0].matches("add")) {
            EntityPlayer player = HelpfulMethods.getPlayerFromName(par1ICommandSender.getCommandSenderName());
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canBeModified()) {
                if (player.getCurrentEquippedItem().stackTagCompound == null) {
                    player.getCurrentEquippedItem().stackTagCompound = new NBTTagCompound();
                }
                player.getCurrentEquippedItem().stackTagCompound.setString("Player" + getNextSlot(player.getCurrentEquippedItem().stackTagCompound), par2String[1]);
                return;
            } else {
                HelpfulMethods.sendMessageToPlayer(player, "You must be holding the module you wish to modify!", EnumChatFormatting.RED);
                return;
            }
        }
    }
    throw new WrongUsageException(usage);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemModule(org.freeforums.geforce.securitycraft.items.ItemModule)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)28 CommandException (net.minecraft.command.CommandException)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)11 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 BlockPos (net.minecraft.util.math.BlockPos)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 Entity (net.minecraft.entity.Entity)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 World (net.minecraft.world.World)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Affinity (am2.api.spell.enums.Affinity)2 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 Color (java.awt.Color)2 File (java.io.File)2 List (java.util.List)2 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2