Search in sources :

Example 21 with CommandException

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

the class CommandSpaceStationAddOwner method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    String var3 = null;
    EntityPlayerMP playerBase = null;
    if (args.length > 0) {
        var3 = args[0];
        try {
            playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                if (stats.getSpaceStationDimensionData().isEmpty()) {
                    throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
                } else {
                    for (Map.Entry<Integer, Integer> ownedStations : stats.getSpaceStationDimensionData().entrySet()) {
                        final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.worldObj, ownedStations.getValue(), playerBase);
                        if (var3.equalsIgnoreCase("+all")) {
                            data.setAllowedAll(true);
                            playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_true")));
                            return;
                        }
                        if (var3.equalsIgnoreCase("-all")) {
                            data.setAllowedAll(false);
                            playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_false", var3)));
                            return;
                        }
                        if (!data.getAllowedPlayers().contains(var3)) {
                            data.getAllowedPlayers().add(var3);
                            data.markDirty();
                        }
                    }
                }
                final EntityPlayerMP playerToAdd = PlayerUtil.getPlayerBaseServerFromPlayerUsername(var3, true);
                if (playerToAdd != null) {
                    playerToAdd.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.added", PlayerUtil.getName(playerBase))));
                }
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(sender)), new Object[0]);
    }
    if (playerBase != null) {
        playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.addsuccess", var3)));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) Map(java.util.Map) ChatComponentText(net.minecraft.util.ChatComponentText) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 22 with CommandException

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

the class CommandGCKit method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP playerBase = null;
    if (args.length < 2) {
        try {
            if (args.length == 1) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
            } else {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
            }
            if (playerBase != null) {
                ItemHandlerHelper.giveItemToPlayer(playerBase, new ItemStack(GCItems.emergencyKit), 0);
                CommandBase.notifyOperators(sender, this, "commands.emergencykit", new Object[] { String.valueOf(EnumColor.GREY + "[" + playerBase.getName()), "]" });
            } else {
                throw new Exception("Could not find player with name: " + args[0]);
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getCommandUsage(sender)), new Object[0]);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ItemStack(net.minecraft.item.ItemStack) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 23 with CommandException

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

the class CommandGCInv method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if (CommandGCInv.firstuse) {
        CommandGCInv.firstuse = false;
        CommandGCInv.initialise();
    }
    if (args.length == 2) {
        try {
            EntityPlayerMP thePlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
            if (thePlayer != null && !thePlayer.isDead && thePlayer.worldObj != null) {
                GCPlayerStats stats = GCPlayerStats.get(thePlayer);
                if (args[0].equalsIgnoreCase("drop")) {
                    InventoryExtended gcInventory = stats.getExtendedInventory();
                    gcInventory.dropExtendedItems(thePlayer);
                } else if (args[0].equalsIgnoreCase("save")) {
                    InventoryExtended gcInventory = stats.getExtendedInventory();
                    ItemStack[] saveinv = new ItemStack[gcInventory.getSizeInventory()];
                    for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
                        saveinv[i] = gcInventory.getStackInSlot(i);
                        gcInventory.setInventorySlotContents(i, null);
                    }
                    CommandGCInv.savedata.put(args[1].toLowerCase(), saveinv);
                    CommandGCInv.dontload.add(args[1].toLowerCase());
                    CommandGCInv.writefile();
                    System.out.println("[GCInv] Saving and clearing GC inventory slots of " + PlayerUtil.getName(thePlayer));
                } else if (args[0].equalsIgnoreCase("restore")) {
                    ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
                    CommandGCInv.dontload.remove(args[1].toLowerCase());
                    if (saveinv == null) {
                        System.out.println("[GCInv] Tried to restore but player " + PlayerUtil.getName(thePlayer) + " had no saved GC inventory items.");
                        return;
                    }
                    CommandGCInv.doLoad(thePlayer);
                } else if (args[0].equalsIgnoreCase("clear")) {
                    InventoryExtended gcInventory = stats.getExtendedInventory();
                    for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
                        gcInventory.setInventorySlotContents(i, null);
                    }
                } else {
                    throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
                }
            } else {
                // inventory already)
                if (args[0].equalsIgnoreCase("restore")) {
                    ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
                    if (saveinv != null) {
                        System.out.println("[GCInv] Restore command for offline player " + args[1] + ", setting to restore GCInv on next login.");
                        CommandGCInv.dontload.remove(args[1].toLowerCase());
                        // Now it can autoload on next player logon
                        return;
                    }
                }
                // No player found, and not a 'restore' command
                if (args[0].equalsIgnoreCase("clear") || args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("drop")) {
                    System.out.println("GCInv command: player " + args[1] + " not found.");
                } else {
                    throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
                }
            }
        } catch (final Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    } else {
        throw new WrongUsageException("Not enough command arguments! Usage: " + this.getCommandUsage(sender), new Object[0]);
    }
}
Also used : InventoryExtended(micdoodle8.mods.galacticraft.core.inventory.InventoryExtended) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 24 with CommandException

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

the class CommandSpaceStationRemoveOwner method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    String var3 = null;
    EntityPlayerMP playerBase = null;
    if (args.length > 0) {
        var3 = args[0];
        try {
            playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
            if (playerBase != null) {
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                if (stats.getSpaceStationDimensionData().isEmpty()) {
                    throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
                } else {
                    for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
                        final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.worldObj, e.getValue(), playerBase);
                        String str = null;
                        for (String name : data.getAllowedPlayers()) {
                            if (name.equalsIgnoreCase(var3)) {
                                str = name;
                                break;
                            }
                        }
                        if (str != null) {
                            data.getAllowedPlayers().remove(str);
                            data.markDirty();
                        } else {
                            throw new CommandException(GCCoreUtil.translateWithFormat("commands.ssuninvite.no_player", "\"" + var3 + "\""), new Object[0]);
                        }
                    }
                }
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(sender)), new Object[0]);
    }
    if (playerBase != null) {
        playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.removesuccess", var3)));
    }
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ChatComponentText(net.minecraft.util.ChatComponentText) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 25 with CommandException

use of net.minecraft.command.CommandException in project DynamicSurroundings by OreCruncher.

the class CommandCalc method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] parms) throws CommandException {
    try {
        boolean showHelp = false;
        if (parms.length == 0) {
            showHelp = true;
        } else if (COMMAND_OPTION_HELP.compareToIgnoreCase(parms[0]) == 0) {
            showHelp = true;
        } else if (COMMAND_OPTION_FUNCS.compareToIgnoreCase(parms[0]) == 0) {
            final Expression exp = new Expression("0");
            for (final String line : exp.getDeclaredFunctions()) sender.sendMessage(new TextComponentString(line));
        } else if (COMMAND_OPTION_VARS.compareToIgnoreCase(parms[0]) == 0) {
            final Expression exp = new Expression("0");
            for (final String line : exp.getDeclaredVariables()) sender.sendMessage(new TextComponentString(line));
        } else if (COMMAND_OPTION_OPS.compareToIgnoreCase(parms[0]) == 0) {
            final Expression exp = new Expression("0");
            for (final String line : exp.getDeclaredOperators()) sender.sendMessage(new TextComponentString(line));
        } else {
            try {
                final Expression exp = new Expression(buildString(parms, 0));
                final Variant result = exp.eval();
                sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "-> " + result.asString()));
            } catch (final ExpressionException t) {
                sender.sendMessage(new TextComponentString(TextFormatting.RED + t.getMessage()));
            } catch (final Throwable t) {
                sender.sendMessage(new TextComponentString(TextFormatting.RED + "Internal error"));
                showHelp = true;
            }
        }
        if (showHelp) {
            for (final String line : HELP) sender.sendMessage(new TextComponentString(line));
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Variant(org.blockartistry.lib.expression.Variant) Expression(org.blockartistry.lib.expression.Expression) TextComponentString(net.minecraft.util.text.TextComponentString) ExpressionException(org.blockartistry.lib.expression.ExpressionException) CommandException(net.minecraft.command.CommandException) ExpressionException(org.blockartistry.lib.expression.ExpressionException) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

CommandException (net.minecraft.command.CommandException)70 WrongUsageException (net.minecraft.command.WrongUsageException)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 ICommandSender (net.minecraft.command.ICommandSender)18 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)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 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)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