Search in sources :

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

Example 12 with WrongUsageException

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

the class CommandModule method execute.

public void execute(ICommandSender par1ICommandSender, String[] par2String) throws CommandException {
    if (par2String.length == 1) {
        if (par2String[0].matches("copy")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getName());
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
                mod_SecurityCraft.instance.setSavedModule(player.getCurrentEquippedItem().getTagCompound());
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.saved"), EnumChatFormatting.GREEN);
            } else {
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForData"), EnumChatFormatting.RED);
            }
            return;
        } else if (par2String[0].matches("paste")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getName());
            if (mod_SecurityCraft.instance.getSavedModule() == null) {
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.nothingSaved"), EnumChatFormatting.RED);
                return;
            }
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
                player.getCurrentEquippedItem().setTagCompound(mod_SecurityCraft.instance.getSavedModule());
                mod_SecurityCraft.instance.setSavedModule(null);
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.saved"), EnumChatFormatting.GREEN);
            }
            return;
        }
    } else if (par2String.length == 2) {
        if (par2String[0].matches("add")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getName());
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
                if (player.getCurrentEquippedItem().getTagCompound() == null) {
                    player.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
                }
                for (int i = 1; i <= 10; i++) {
                    if (player.getCurrentEquippedItem().getTagCompound().hasKey("Player" + i) && player.getCurrentEquippedItem().getTagCompound().getString("Player" + i).matches(par2String[1])) {
                        PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.alreadyContained").replace("#", par2String[1]), EnumChatFormatting.RED);
                        return;
                    }
                }
                player.getCurrentEquippedItem().getTagCompound().setString("Player" + getNextSlot(player.getCurrentEquippedItem().getTagCompound()), par2String[1]);
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.added").replace("#", par2String[1]), EnumChatFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForModify"), EnumChatFormatting.RED);
                return;
            }
        } else if (par2String[0].matches("remove")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(par1ICommandSender.getName());
            if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemModule && ((ItemModule) player.getCurrentEquippedItem().getItem()).canNBTBeModified()) {
                if (player.getCurrentEquippedItem().getTagCompound() == null) {
                    player.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
                }
                for (int i = 1; i <= 10; i++) {
                    if (player.getCurrentEquippedItem().getTagCompound().hasKey("Player" + i) && player.getCurrentEquippedItem().getTagCompound().getString("Player" + i).matches(par2String[1])) {
                        player.getCurrentEquippedItem().getTagCompound().removeTag("Player" + i);
                    }
                }
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.removed").replace("#", par2String[1]), EnumChatFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("messages.module.manager"), StatCollector.translateToLocal("messages.module.notHoldingForModify"), EnumChatFormatting.RED);
                return;
            }
        }
    }
    throw new WrongUsageException(StatCollector.translateToLocal("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 13 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() != null && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                mod_SecurityCraft.instance.setSavedModule(player.inventory.getCurrentItem().getTagCompound());
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.saved"), TextFormatting.GREEN);
            } else {
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.notHoldingForData"), TextFormatting.RED);
            }
            return;
        } else if (args[0].matches("paste")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (mod_SecurityCraft.instance.getSavedModule() == null) {
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.nothingSaved"), TextFormatting.RED);
                return;
            }
            if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof ItemModule && ((ItemModule) player.inventory.getCurrentItem().getItem()).canNBTBeModified()) {
                player.inventory.getCurrentItem().setTagCompound(mod_SecurityCraft.instance.getSavedModule());
                mod_SecurityCraft.instance.setSavedModule(null);
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("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() != null && 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, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("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, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.added").replace("#", args[1]), TextFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.notHoldingForModify"), TextFormatting.RED);
                return;
            }
        } else if (args[0].matches("remove")) {
            EntityPlayer player = PlayerUtils.getPlayerFromName(sender.getName());
            if (player.inventory.getCurrentItem() != null && 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, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.removed").replace("#", args[1]), TextFormatting.GREEN);
                return;
            } else {
                PlayerUtils.sendMessageToPlayer(player, I18n.translateToLocal("messages.module.manager"), I18n.translateToLocal("messages.module.notHoldingForModify"), TextFormatting.RED);
                return;
            }
        }
    }
    throw new WrongUsageException(I18n.translateToLocal("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 14 with WrongUsageException

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

the class ClientCommandHandler method executeCommand.

/**
     * @return 1 if successfully executed, -1 if no permission or wrong usage,
     *         0 if it doesn't exist or it was canceled (it's sent to the server)
     */
@Override
public int executeCommand(ICommandSender sender, String message) {
    message = message.trim();
    if (message.startsWith("/")) {
        message = message.substring(1);
    }
    String[] temp = message.split(" ");
    String[] args = new String[temp.length - 1];
    String commandName = temp[0];
    System.arraycopy(temp, 1, args, 0, args.length);
    ICommand icommand = getCommands().get(commandName);
    try {
        if (icommand == null) {
            return 0;
        }
        if (icommand.checkPermission(this.getServer(), sender)) {
            CommandEvent event = new CommandEvent(icommand, sender, args);
            if (MinecraftForge.EVENT_BUS.post(event)) {
                if (event.getException() != null) {
                    throw event.getException();
                }
                return 0;
            }
            this.tryExecute(sender, args, icommand, message);
            return 1;
        } else {
            sender.sendMessage(format(RED, "commands.generic.permission"));
        }
    } catch (WrongUsageException wue) {
        sender.sendMessage(format(RED, "commands.generic.usage", format(RED, wue.getMessage(), wue.getErrorObjects())));
    } catch (CommandException ce) {
        sender.sendMessage(format(RED, ce.getMessage(), ce.getErrorObjects()));
    } catch (Throwable t) {
        sender.sendMessage(format(RED, "commands.generic.exception"));
        t.printStackTrace();
    }
    return -1;
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ICommand(net.minecraft.command.ICommand) CommandEvent(net.minecraftforge.event.CommandEvent) CommandException(net.minecraft.command.CommandException)

Example 15 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project watson by totemo.

the class ClientCommandManager method executeCommand.

// --------------------------------------------------------------------------
/**
   * @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
   *      java.lang.String)
   * 
   *      The JavaDocs for the interface don't currently describe the exact
   *      meaning of the return value. Looking at the code for
   *      {@link net.minecraft.src.CommandHandler} it contains a loop that
   *      applies a command for all players who match a particular name pattern.
   *      The returned value is the number of times that the command was
   *      successfully executed by that loop. Therefore in the case of this
   *      class, it returns 1 on success and 0 on error.
   */
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
    try {
        String[] tokens = getTokens(commandLine);
        String verb = tokens[0];
        ICommand command = getCommand(verb);
        if (command == null) {
            throw new CommandNotFoundException();
        }
        tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
        if (command.canCommandSenderUseCommand(sender)) {
            command.processCommand(sender, tokens);
            return 1;
        } else {
            sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
        }
    } catch (WrongUsageException ex) {
        sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
    } catch (CommandException ex) {
        sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
    } catch (Throwable throwable) {
        sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
        Log.exception(Level.WARNING, "error processing command", throwable);
    }
    return 0;
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ICommand(net.minecraft.command.ICommand) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) CommandException(net.minecraft.command.CommandException) CommandNotFoundException(net.minecraft.command.CommandNotFoundException)

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