Search in sources :

Example 16 with CommandException

use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.

the class QuestCommandDelete method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    if (args[1].equalsIgnoreCase("all")) {
        QuestDatabase.INSTANCE.reset();
        QuestLineDatabase.INSTANCE.reset();
        PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
        PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.all"));
    } else {
        try {
            int id = Integer.parseInt(args[1].trim());
            IQuest quest = QuestDatabase.INSTANCE.getValue(id);
            QuestDatabase.INSTANCE.removeKey(id);
            PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.single", new TextComponentTranslation(quest.getUnlocalisedName())));
        } catch (Exception e) {
            throw getException(command);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IQuest(betterquesting.api.questing.IQuest) CommandException(net.minecraft.command.CommandException)

Example 17 with CommandException

use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.

the class QuestCommandReset method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    String action = args[1];
    UUID uuid = null;
    if (args.length == 3) {
        uuid = this.findPlayerID(server, sender, args[2]);
        if (uuid == null) {
            throw this.getException(command);
        }
    }
    String pName = uuid == null ? "NULL" : NameCache.INSTANCE.getName(uuid);
    if (action.equalsIgnoreCase("all")) {
        for (IQuest quest : QuestDatabase.INSTANCE.getAllValues()) {
            if (uuid != null) {
                // Clear progress and state
                quest.resetUser(uuid, true);
            } else {
                quest.resetAll(true);
            }
        }
        if (uuid != null) {
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_all", pName));
        } else {
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_all"));
        }
    } else {
        try {
            int id = Integer.parseInt(action.trim());
            IQuest quest = QuestDatabase.INSTANCE.getValue(id);
            if (uuid != null) {
                // Clear progress and state
                quest.resetUser(uuid, true);
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_single", new TextComponentTranslation(quest.getUnlocalisedName()), pName));
            } else {
                quest.resetAll(true);
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_single", new TextComponentTranslation(quest.getUnlocalisedName())));
            }
        } catch (Exception e) {
            throw getException(command);
        }
    }
    PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IQuest(betterquesting.api.questing.IQuest) UUID(java.util.UUID) CommandException(net.minecraft.command.CommandException)

Example 18 with CommandException

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

the class CommandRain method processCommand.

@Override
public void processCommand(final ICommandSender sender, final String[] parms) {
    try {
        final EntityPlayerMP player = getCommandSenderAsPlayer(sender);
        final World world = player.worldObj;
        final DimensionEffectData data = DimensionEffectData.get(world);
        if (parms.length == 1) {
            if ("status".compareToIgnoreCase(parms[0]) == 0) {
                // Dump out some diagnostics for the currentAurora dimension
                player.addChatMessage(new ChatComponentText(statusOutput(world, data)));
            } else if ("reset".compareToIgnoreCase(parms[0]) == 0) {
                world.provider.resetRainAndThunder();
                player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("msg.RainReset")));
            } else if ("reload".compareToIgnoreCase(parms[0]) == 0) {
                BiomeRegistry.initialize();
                BlockRegistry.initialize();
                player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("msg.BiomeReload")));
            } else {
                final double d = parseDouble(parms[0], 0.0D, 100.0D) / 100.0D;
                data.setRainIntensity((float) d);
                player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.RainIntensitySet", FORMATTER.format(data.getRainIntensity() * 100))));
            }
        } else if (parms.length == 2) {
            if ("setmin".compareToIgnoreCase(parms[0]) == 0) {
                final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
                data.setMinRainIntensity((float) d);
                player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.MinRainIntensitySet", FORMATTER.format(data.getMinRainIntensity() * 100))));
            } else if ("setmax".compareToIgnoreCase(parms[0]) == 0) {
                final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
                data.setMaxRainIntensity((float) d);
                player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("msg.MaxRainIntensitySet", FORMATTER.format(data.getMaxRainIntensity() * 100))));
            } else {
                throw new CommandException(getCommandUsage(sender));
            }
        } else {
            player.addChatMessage(new ChatComponentText(getCommandUsage(sender)));
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
}
Also used : DimensionEffectData(org.blockartistry.mod.DynSurround.data.DimensionEffectData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) World(net.minecraft.world.World) ChatComponentText(net.minecraft.util.ChatComponentText) CommandException(net.minecraft.command.CommandException)

Example 19 with CommandException

use of net.minecraft.command.CommandException in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CommandLevelUp method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
        if (args.length == 0 || args.length > 2)
            TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
        else if (args.length == 1) {
            int level = 1;
            try {
                if (Integer.parseInt(args[0]) < 1 || Integer.parseInt(args[0]) > 100) {
                    TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                    return;
                } else
                    level = Integer.parseInt(args[0]);
            } catch (Exception e) {
                TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                return;
            }
            PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
            STATS.setLevel(1);
            STATS.setExperience(0);
            if (STATS.getChoice1().equals(Strings.Choice_Sword))
                STATS.setStrength(3);
            else
                STATS.setStrength(1);
            if (STATS.getChoice1().equals(Strings.Choice_Shield))
                STATS.setDefense(3);
            else
                STATS.setDefense(1);
            if (STATS.getChoice1().equals(Strings.Choice_Staff))
                STATS.setMagic(3);
            else
                STATS.setMagic(1);
            STATS.setHP(20);
            player.setHealth(20);
            while (STATS.getLevel() < level) STATS.addExperience(player, STATS.getExpNeeded(level - 1, STATS.getExperience()));
            player.heal(STATS.getHP());
            TextHelper.sendFormattedChatMessage("Your level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
            PacketDispatcher.sendTo(new SyncLevelData(player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) player);
        } else if (args.length == 2) {
            int level = 1;
            try {
                if (Integer.parseInt(args[0]) < 1 || Integer.parseInt(args[0]) > 100) {
                    TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                    return;
                } else
                    level = Integer.parseInt(args[0]);
            } catch (Exception e) {
                TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 100", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                return;
            }
            EntityPlayerMP entityplayermp = args.length == 2 ? (EntityPlayerMP) getPlayerFromUsername(args[1]) : getCommandSenderAsPlayer(sender);
            PlayerStatsCapability.IPlayerStats STATS = entityplayermp.getCapability(ModCapabilities.PLAYER_STATS, null);
            STATS.setLevel(1);
            STATS.setExperience(0);
            if (STATS.getChoice1().equals(Strings.Choice_Sword))
                STATS.setStrength(3);
            else
                STATS.setStrength(1);
            if (STATS.getChoice1().equals(Strings.Choice_Shield))
                STATS.setDefense(3);
            else
                STATS.setDefense(1);
            if (STATS.getChoice1().equals(Strings.Choice_Staff))
                STATS.setMagic(3);
            else
                STATS.setMagic(1);
            STATS.setHP(20);
            entityplayermp.setHealth(20);
            while (STATS.getLevel() < level) STATS.addExperience(entityplayermp, STATS.getExpNeeded(level - 1, STATS.getExperience()));
            entityplayermp.heal(STATS.getHP());
            TextHelper.sendFormattedChatMessage(args[1] + "'s level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
            TextHelper.sendFormattedChatMessage("Your level is now " + args[0], TextFormatting.YELLOW, (EntityPlayer) entityplayermp);
            PacketDispatcher.sendTo(new SyncLevelData(entityplayermp.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) entityplayermp);
        } else
            TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
    }
}
Also used : SyncLevelData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData) PlayerStatsCapability(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerNotFoundException(net.minecraft.command.PlayerNotFoundException) CommandException(net.minecraft.command.CommandException)

Example 20 with CommandException

use of net.minecraft.command.CommandException in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CommandDriveLevel method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
        if (args.length == 0 || args.length > 3)
            TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
        else if (args.length >= 2 && args.length <= 3) {
            if (args.length == 3) {
                if (getPlayerFromUsername(args[2]) != null) {
                    player = getPlayerFromUsername(args[2]);
                }
            }
            int level = 1;
            try {
                // Parse the given level
                if (Integer.parseInt(args[1]) < 1 || Integer.parseInt(args[1]) > 7) {
                    TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 7", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                    return;
                } else
                    level = Integer.parseInt(args[1]);
            } catch (Exception e) {
                TextHelper.sendFormattedChatMessage("Invalid level, it must be a number between 1 - 7", TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
                return;
            }
            IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);
            String form = null;
            int oldLevel = DRIVE.getDriveLevel("form." + args[0].toLowerCase());
            int newLevel = Integer.parseInt(args[1].toString());
            switch(args[0].toLowerCase()) {
                case "valor":
                    DRIVE.setDriveLevel(Strings.Form_Valor, newLevel);
                    form = Utils.translateToLocal(Strings.Form_Valor);
                    break;
                case "wisdom":
                    DRIVE.setDriveLevel(Strings.Form_Wisdom, Integer.parseInt(args[1].toString()));
                    form = Utils.translateToLocal(Strings.Form_Wisdom);
                    break;
                case "limit":
                    DRIVE.setDriveLevel(Strings.Form_Limit, Integer.parseInt(args[1].toString()));
                    form = Utils.translateToLocal(Strings.Form_Limit);
                    break;
                case "master":
                    DRIVE.setDriveLevel(Strings.Form_Master, Integer.parseInt(args[1].toString()));
                    form = Utils.translateToLocal(Strings.Form_Master);
                    break;
                case "final":
                    DRIVE.setDriveLevel(Strings.Form_Final, Integer.parseInt(args[1].toString()));
                    form = Utils.translateToLocal(Strings.Form_Final);
                    break;
            }
            DRIVE.displayLevelUpMessage(player, "form." + args[0].toLowerCase());
            if (oldLevel != 7 && newLevel == 7) {
                // Increase
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() + 1);
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
                PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
            } else if (oldLevel == 7 && newLevel != 7) {
                // Decrease
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() - 1);
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
                PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
            }
            if (form != null) {
                if (args.length == 3)
                    TextHelper.sendFormattedChatMessage("Succesfully leveled up " + form + " to level " + args[1] + " for player " + args[2], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
                else
                    TextHelper.sendFormattedChatMessage("Succesfully leveled up " + form + " to level " + args[1], TextFormatting.YELLOW, (EntityPlayer) sender.getCommandSenderEntity());
            } else {
                TextHelper.sendFormattedChatMessage("Unknown form " + args[0], TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
            }
        } else {
            TextHelper.sendFormattedChatMessage("Invalid arguments, usage: " + getUsage(sender), TextFormatting.RED, (EntityPlayer) sender.getCommandSenderEntity());
        }
    }
}
Also used : SyncDriveData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerNotFoundException(net.minecraft.command.PlayerNotFoundException) CommandException(net.minecraft.command.CommandException) IDriveState(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability.IDriveState)

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