Search in sources :

Example 31 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandSanity method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    boolean sane = true;
    if (RecurrentComplex.isLite()) {
        commandSender.sendMessage(new TextComponentString("Recurrent Complex is in lightweight mode!"));
    }
    if (StructureRegistry.INSTANCE.ids().isEmpty()) {
        commandSender.sendMessage(new TextComponentString("No registered structures!"));
        sane = false;
    }
    if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
        sane = false;
    }
    for (ModContainer mod : Loader.instance().getModList()) {
        String domain = mod.getModId();
        Path path = null;
        try {
            path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
            if (path != null && !Files.isReadable(path)) {
                commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
                sane = false;
            }
        } catch (RCFiles.ResourceLocationLoadException e) {
            RecurrentComplex.logger.error(e);
            commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
            commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
            sane = false;
        } finally {
            if (path != null)
                RCFiles.closeQuietly(path.getFileSystem());
        }
    }
    if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
        sane = false;
    }
    if (!parameters.has("short")) {
        sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
        sane &= addGenericStructureLog(commandSender, (s, structure) -> !structure.metadata.authors.isEmpty(), "No author");
        sane &= addGenericStructureLog(commandSender, (s, structure) -> structure.transformer.getTransformers().stream().allMatch(t -> t.id().length() > 0), "Transformer has empty ID");
        sane &= addGenerationLog(commandSender, GenerationType.class, (structure, gen) -> gen.id().length() > 0, "Generation type has empty ID");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
        sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
        sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
    }
    if (sane && !parameters.has("silent"))
        commandSender.sendMessage(new TextComponentString("No problems identified!"));
}
Also used : Path(java.nio.file.Path) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) CommandSearchStructure(ivorius.reccomplex.commands.structure.CommandSearchStructure) ivorius.reccomplex.world.gen.feature.structure.generic.generation(ivorius.reccomplex.world.gen.feature.structure.generic.generation) Loader(net.minecraftforge.fml.common.Loader) PriorityQueue(java.util.PriorityQueue) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) RCConfig(ivorius.reccomplex.RCConfig) BiPredicate(java.util.function.BiPredicate) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RCFiles(ivorius.reccomplex.files.RCFiles) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) StructureSelector(ivorius.reccomplex.world.gen.feature.selector.StructureSelector) Path(java.nio.file.Path) DimensionManager(net.minecraftforge.common.DimensionManager) Files(java.nio.file.Files) World(net.minecraft.world.World) IRegistry(net.minecraft.util.registry.IRegistry) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) ConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.ConnectorStrategy) TextComponentString(net.minecraft.util.text.TextComponentString) Expect(ivorius.mcopts.commands.parameters.expect.Expect) Stream(java.util.stream.Stream) ICommandSender(net.minecraft.command.ICommandSender) ResourceLocation(net.minecraft.util.ResourceLocation) ModContainer(net.minecraftforge.fml.common.ModContainer) Parameters(ivorius.mcopts.commands.parameters.Parameters) Biome(net.minecraft.world.biome.Biome) Parameters(ivorius.mcopts.commands.parameters.Parameters) ModContainer(net.minecraftforge.fml.common.ModContainer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) ResourceLocation(net.minecraft.util.ResourceLocation) RCFiles(ivorius.reccomplex.files.RCFiles)

Example 32 with CommandException

use of net.minecraft.command.CommandException 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 CommandException

use of net.minecraft.command.CommandException 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)

Example 34 with CommandException

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

the class CommandSC method execute.

public void execute(ICommandSender sender, String[] par1String) throws CommandException {
    if (par1String.length == 0) {
        throw new WrongUsageException(StatCollector.translateToLocal("messages.command.sc.usage"));
    }
    if ((par1String[0].matches("connect") || par1String[0].matches("disconnect") || par1String[0].matches("contact") || par1String[0].matches("bug")) && !mod_SecurityCraft.configHandler.isIrcBotEnabled) {
        PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.botDisabled"), EnumChatFormatting.RED);
        return;
    }
    if (par1String.length == 1) {
        if (par1String[0].matches("connect")) {
            EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getName());
            p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
            try {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).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 (par1String[0].matches("disconnect")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).disconnect();
            }
            PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.disconnected"), EnumChatFormatting.RED);
        } else if (par1String[0].matches("help")) {
            getCommandSenderAsPlayer(sender).inventory.addItemStackToInventory(new ItemStack(mod_SecurityCraft.scManual));
        } else if (par1String[0].matches("bug"))
            PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
        else if (par1String[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
        else if (par1String[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
            }
        }
    } else if (par1String.length >= 2) {
        if (par1String[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", StatCollector.translateToLocal("messages.irc.notConnected"), EnumChatFormatting.RED);
            }
        } else if (par1String[0].matches("bug"))
            PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", StatCollector.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", EnumChatFormatting.GOLD);
        else if (par1String[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getName()).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)

Example 35 with CommandException

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

the class CommandSC method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        throw new WrongUsageException(I18n.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", I18n.translateToLocal("messages.irc.botDisabled"), TextFormatting.RED);
        return;
    }
    if (args.length == 1) {
        if (args[0].matches("connect")) {
            EntityPlayer p = PlayerUtils.getPlayerFromName(sender.getName());
            p.openGui(mod_SecurityCraft.instance, GuiHandler.IRC_INFORMATION, p.worldObj, p.chunkCoordX, p.chunkCoordY, p.chunkCoordZ);
            try {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).connectToChannel();
            } catch (Exception e) {
                e.printStackTrace();
                PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.error"), TextFormatting.RED);
                return;
            }
            PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.connected"), TextFormatting.GREEN);
        } else if (args[0].matches("disconnect")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).disconnect();
            }
            PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.disconnected"), TextFormatting.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", I18n.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", TextFormatting.GOLD);
        else if (args[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
        else if (args[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.notConnected"), TextFormatting.RED);
            }
        }
    } else if (args.length >= 2) {
        if (args[0].matches("contact")) {
            if (mod_SecurityCraft.instance.getIrcBot(sender.getName()) != null) {
                mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(true, sender);
            } else {
                PlayerUtils.sendMessageToPlayer(sender, "IRC", I18n.translateToLocal("messages.irc.notConnected"), TextFormatting.RED);
            }
        } else if (args[0].matches("bug"))
            PlayerUtils.sendMessageEndingWithLink(sender, "SecurityCraft", I18n.translateToLocal("messages.bugReport"), "http://goo.gl/forms/kfRpvvQzfl", TextFormatting.GOLD);
        else if (args[0].equals("resume"))
            mod_SecurityCraft.instance.getIrcBot(sender.getName()).setMessageMode(false, sender);
    } else {
        throw new WrongUsageException(I18n.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

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