Search in sources :

Example 31 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Galacticraft by micdoodle8.

the class CommandGCAstroMiner method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length > 2) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
    }
    if (args.length < 1) {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
    }
    int type = 0;
    int newvalue = 0;
    if (args[0].equalsIgnoreCase("show")) {
        type = 1;
    } else if (args[0].equalsIgnoreCase("reset")) {
        type = 2;
    } else if (args[0].length() > 3 && args[0].substring(0, 3).equalsIgnoreCase("set")) {
        String number = args[0].substring(3);
        try {
            newvalue = Integer.parseInt(number);
            if (newvalue > 0) {
                type = 3;
            }
        } catch (NumberFormatException ex) {
        }
    }
    // Proceed if syntax of show|reset|set<number> was correct
    if (type > 0) {
        EntityPlayerMP playerBase = null;
        try {
            if (args.length == 2) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
            } else {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
            }
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                switch(type) {
                    case 1:
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + stats.getAstroMinerCount())));
                        break;
                    case 2:
                        stats.setAstroMinerCount(0);
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + 0)));
                        break;
                    case 3:
                        stats.setAstroMinerCount(newvalue);
                        sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + newvalue)));
                        break;
                }
            } else {
                throw new Exception("Could not find player with name: " + args[1]);
            }
        } catch (final Exception e) {
            throw new CommandException(e.getMessage(), new Object[0]);
        }
        return;
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 32 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 33 with WrongUsageException

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

the class CommandSCHelp method processCommand.

public void processCommand(ICommandSender icommandsender, String[] par1String) {
    if (par1String.length == 0) {
        throw new WrongUsageException(usage);
    }
    if ((par1String[0].matches("connect") || par1String[0].matches("disconnect") || par1String[0].matches("contact") || par1String[0].matches("bug")) && !mod_SecurityCraft.instance.configHandler.isIrcBotEnabled) {
        sendMessageToPlayer("The SecurityCraft IRC bot is disabled from the config file. Please enable to it to use this feature.", icommandsender);
        return;
    }
    if (par1String[0].matches("changePasscode") && par1String.length == 6) {
        int[] positions = { Integer.parseInt(par1String[1]), Integer.parseInt(par1String[2]), Integer.parseInt(par1String[3]) };
        World world = icommandsender.getEntityWorld();
        if (world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.Keypad && ((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4])) {
            ((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).setKeypadCode(par1String[5]);
            HelpfulMethods.sendMessage(icommandsender, "Changed keypad's (at X:" + positions[0] + " Y:" + positions[1] + " Z:" + positions[2] + ") code from " + Integer.parseInt(par1String[4]) + " to " + Integer.parseInt(par1String[5]) + ".", EnumChatFormatting.GREEN);
        } else if ((world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.Keypad && !((TileEntityKeypad) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4])) || (world.getBlock(positions[0], positions[1], positions[2]) == mod_SecurityCraft.keypadChest && !((TileEntityKeypadChest) world.getTileEntity(positions[0], positions[1], positions[2])).getKeypadCode().matches(par1String[4]))) {
            HelpfulMethods.sendMessage(icommandsender, par1String[3] + " is not the passcode for this block.", EnumChatFormatting.RED);
        } else if (world.getBlock(positions[0], positions[1], positions[2]) != mod_SecurityCraft.Keypad && world.getBlock(positions[0], positions[1], positions[2]) != mod_SecurityCraft.keypadChest) {
            HelpfulMethods.sendMessage(icommandsender, "There is no accessable block at the specifed coordinates!", EnumChatFormatting.RED);
        }
        return;
    }
    if (par1String.length == 1) {
        if (par1String[0].matches("connect")) {
            mod_SecurityCraft.instance.setIrcBot(new SCIRCBot("SCUser_" + icommandsender.getCommandSenderName()));
            try {
                mod_SecurityCraft.instance.getIrcBot().connectToChannel();
            } catch (Exception e) {
                e.printStackTrace();
                sendMessageToPlayer("Error occurred when connecting to IRC. Do you have internet access, and access to the IRC server 'irc.esper.net'?", icommandsender);
                return;
            }
            sendMessageToPlayer("Bot connected successfully. You may now report bugs using '/sc bug <bug to report>' or contact me using '/sc contact <message>", icommandsender);
        } else if (par1String[0].matches("disconnect")) {
            if (mod_SecurityCraft.instance.getIrcBot() != null) {
                mod_SecurityCraft.instance.getIrcBot().disconnect();
            }
            mod_SecurityCraft.instance.setIrcBot(null);
            sendMessageToPlayer("Bot disconnected from EsperNet successfully.", icommandsender);
        }
    } else if (par1String.length >= 2) {
        if (par1String[0].matches("bug")) {
            if (mod_SecurityCraft.instance.getIrcBot() != null) {
                mod_SecurityCraft.instance.getIrcBot().sendMessage("#GeforceMods", "[SecurityCraft " + mod_SecurityCraft.getVersion() + " bug] Geforce: " + getMessageFromArray(par1String, 1));
                sendMessageToPlayer(EnumChatFormatting.GRAY + "<" + icommandsender.getCommandSenderName() + " --> IRC> " + getMessageFromArray(par1String, 1) + ".", icommandsender);
            } else {
                sendMessageToPlayer("Bot is not connected to EsperNet. Use '/sc connect' to connect to IRC.", icommandsender);
            }
        } else if (par1String[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot() != null) {
                mod_SecurityCraft.instance.getIrcBot().sendMessage("#GeforceMods", "[SecurityCraft " + mod_SecurityCraft.getVersion() + "] Geforce: " + getMessageFromArray(par1String, 1));
                sendMessageToPlayer(EnumChatFormatting.GRAY + "<" + icommandsender.getCommandSenderName() + " --> IRC> " + getMessageFromArray(par1String, 1) + ".", icommandsender);
            } else {
                sendMessageToPlayer("Bot is not connected to EsperNet. Use '/sc connect' to connect to IRC.", icommandsender);
            }
        } else if (par1String[0].matches("help")) {
            if (par1String[1] == null || par1String[1].isEmpty()) {
                throw new WrongUsageException(usage);
            }
            String par1 = getHelpInfo(par1String[1]);
            if (!par1.isEmpty()) {
                sendMessageToPlayer("[SCHelp] " + par1, icommandsender);
            }
        } else if (par1String[0].matches("recipe")) {
            String itemname = par1String[1].toLowerCase();
            if (itemname.matches("level1keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard1) {
                sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[1], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[2], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[3], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[4], icommandsender);
            } else if (itemname.matches("level2keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard2) {
                sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[1], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[2], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[3], icommandsender);
                sendMessageToPlayer(getRecipe(itemname)[4], icommandsender);
            } else if (itemname.matches("level3keycard") && !mod_SecurityCraft.configHandler.ableToCraftKeycard3) {
                sendMessageToPlayer("[Recipe currently disabled in config file] " + getRecipe(itemname)[0], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[1], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[2], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[3], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[4], icommandsender);
            } else {
                sendMessageToPlayer(getRecipe(par1String[1])[0], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[1], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[2], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[3], icommandsender);
                sendMessageToPlayer(getRecipe(par1String[1])[4], icommandsender);
            }
        }
    } else {
        throw new WrongUsageException(usage);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) TileEntityKeypadChest(org.freeforums.geforce.securitycraft.tileentity.TileEntityKeypadChest) SCIRCBot(org.freeforums.geforce.securitycraft.ircbot.SCIRCBot) World(net.minecraft.world.World) WrongUsageException(net.minecraft.command.WrongUsageException) TileEntityKeypad(org.freeforums.geforce.securitycraft.tileentity.TileEntityKeypad)

Example 34 with WrongUsageException

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

the class CommandSCLog method processCommand.

public void processCommand(ICommandSender icommandsender, String[] par1String) {
    if (par1String.length >= 1) {
        if (par1String[0].matches("clear")) {
            File file = new File("changelog.txt");
            if (file.exists()) {
                file.delete();
                File file2 = new File("changelog.txt");
                try {
                    file2.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return;
            }
        }
        try {
            String string = "";
            for (int i = 0; i < par1String.length; i++) {
                if (i >= 1) {
                    string += " " + par1String[i];
                } else {
                    string += "-" + par1String[i];
                }
            }
            File file = new File("changelog.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("changelog.txt", true)));
            out.println(string);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        throw new WrongUsageException("/log <changeToLog>");
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 35 with WrongUsageException

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

the class CommandSC method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
    }
    if ((args[0].matches("connect") || args[0].matches("disconnect") || args[0].matches("contact") || args[0].matches("bug")) && !mod_SecurityCraft.configHandler.isIrcBotEnabled) {
        PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.botDisabled"), EnumChatFormatting.RED);
        return;
    }
    if (args.length == 1) {
        if (args[0].matches("connect")) {
            EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getCommandSenderName());
            p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
            try {
                mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).connectToChannel();
            } catch (Exception e) {
                e.printStackTrace();
                PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.error"), EnumChatFormatting.RED);
                return;
            }
            PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.connected"), EnumChatFormatting.GREEN);
        } else if (args[0].matches("disconnect")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).disconnect();
            }
            PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.disconnected"), EnumChatFormatting.RED);
        } else if (args[0].matches("help")) {
            getCommandSenderAsPlayer(sender).inventory.addItemStackToInventory(new ItemStack(mod_SecurityCraft.scManual));
        } else if (args[0].matches("bug"))
            PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
        else if (args[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(false, sender);
        else if (args[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
            }
        }
    } else if (args.length >= 2) {
        if (args[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
            }
        } else if (args[0].matches("bug"))
            PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
        else if (args[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getCommandSenderName()).setMessageMode(false, sender);
    } else {
        throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)73 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)37 CommandException (net.minecraft.command.CommandException)30 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)16 ItemStack (net.minecraft.item.ItemStack)13 BlockPos (net.minecraft.util.math.BlockPos)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 TextComponentString (net.minecraft.util.text.TextComponentString)7 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 Entity (net.minecraft.entity.Entity)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 World (net.minecraft.world.World)4 WorldServer (net.minecraft.world.WorldServer)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Affinity (am2.api.spell.enums.Affinity)2 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 AttributeModifier (com.teamwizardry.wizardry.api.spell.attribute.AttributeModifier)2