Search in sources :

Example 51 with CommandException

use of net.minecraft.command.CommandException in project BiomeTweaker by superckl.

the class CommandReloadScript method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException {
    if (args.length != 1) {
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.usage.text").setStyle(new Style().setColor(TextFormatting.RED)));
        return;
    }
    try {
        final File operateIn = BiomeTweaker.getInstance().getConfig().getBtConfigFolder();
        final File scriptFile = new File(operateIn, args[0]);
        if (!scriptFile.exists() || !scriptFile.isFile()) {
            sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.nofile.text", scriptFile.getName()).setStyle(new Style().setColor(TextFormatting.RED)));
            return;
        }
        BiomeTweaker.getInstance().parseScript(scriptFile);
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.success.text", scriptFile.getName()).setStyle(new Style().setColor(TextFormatting.AQUA)));
    } catch (final Exception e) {
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reloadscript.failure.text", args[0]).setStyle(new Style().setColor(TextFormatting.RED)));
        LogHelper.error(String.format("Failed to reload script %s!", args[0]));
        e.printStackTrace();
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) File(java.io.File) CommandException(net.minecraft.command.CommandException)

Example 52 with CommandException

use of net.minecraft.command.CommandException in project BiomeTweaker by superckl.

the class CommandReload method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException {
    try {
        BiomeTweaker.getInstance().getConfig().loadValues();
        BiomeTweaker.getInstance().getCommandManager().reset();
        BiomeTweaker.getInstance().parseScripts();
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reload.success.text").setStyle(new Style().setColor(TextFormatting.AQUA)));
    } catch (final Exception e) {
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.reload.failure.text").setStyle(new Style().setColor(TextFormatting.RED)));
        LogHelper.error("Failed to reload scripts!");
        e.printStackTrace();
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException)

Example 53 with CommandException

use of net.minecraft.command.CommandException in project Bewitchment by Um-Mitternacht.

the class CommandIncantation method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 1)
        throw new WrongUsageException("commands.incantation.usage");
    if (sender.getCommandSenderEntity() == null)
        return;
    final String command = args[0];
    if (ModIncantations.getCommands().containsKey(command)) {
        IIncantation incantation = ModIncantations.getCommands().get(command);
        if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
            Optional<IEnergy> ienopt = EnergyHandler.getEnergy(player);
            if (ienopt.isPresent()) {
                if (ienopt.get().get() >= incantation.getCost()) {
                    EnergyHandler.addEnergy(player, -incantation.getCost());
                    incantation.cast(player, args);
                } else {
                    throw new CommandException("commands.incantation.no_energy", sender.getName());
                }
            } else {
                throw new CommandException("commands.incantation.no_energy", sender.getName());
            }
        }
    } else {
        throw new CommandException("commands.incantation.notFound", sender.getName());
    }
}
Also used : IIncantation(com.bewitchment.api.incantation.IIncantation) WrongUsageException(net.minecraft.command.WrongUsageException) IEnergy(com.bewitchment.api.capability.IEnergy) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException)

Example 54 with CommandException

use of net.minecraft.command.CommandException in project BuildCraft by BuildCraft.

the class SubCommandDeop method processSubCommand.

@Override
public void processSubCommand(ICommandSender sender, String[] args) throws CommandException {
    MinecraftServer server = sender.getServer();
    if (server == null) {
        throw new CommandException("No server!");
    } else {
        server.getPlayerList().removeOp(BuildCraftCore.gameProfile);
        CommandHelpers.sendLocalizedChatMessage(sender, "commands.deop.success", "[BuildCraft]");
    }
}
Also used : CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 55 with CommandException

use of net.minecraft.command.CommandException in project BuildCraft by BuildCraft.

the class SubCommandOp method processSubCommand.

@Override
public void processSubCommand(ICommandSender sender, String[] args) throws CommandException {
    MinecraftServer server = sender.getServer();
    if (server == null) {
        throw new CommandException("No server!");
    } else {
        server.getPlayerList().addOp(BuildCraftCore.gameProfile);
        CommandHelpers.sendLocalizedChatMessage(sender, "commands.op.success", "[BuildCraft]");
    }
}
Also used : CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

CommandException (net.minecraft.command.CommandException)82 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)33 WrongUsageException (net.minecraft.command.WrongUsageException)31 MinecraftServer (net.minecraft.server.MinecraftServer)22 TextComponentString (net.minecraft.util.text.TextComponentString)19 ICommandSender (net.minecraft.command.ICommandSender)18 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)16 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 BlockPos (net.minecraft.util.math.BlockPos)13 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 ItemStack (net.minecraft.item.ItemStack)12 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 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7