Search in sources :

Example 26 with CommandException

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

the class CommandHelpers method getWorld.

public static World getWorld(ICommandSender sender, IModCommand command, String[] args, int worldArgIndex) throws CommandException {
    // Handle passed in world argument
    if (worldArgIndex < args.length) {
        try {
            int dim = Integer.parseInt(args[worldArgIndex]);
            World world = sender.getServer().worldServerForDimension(dim);
            if (world != null) {
                return world;
            }
        } catch (Exception ex) {
            throwWrongUsage(sender, command);
        }
    }
    return getWorld(sender, command);
}
Also used : World(net.minecraft.world.World) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 27 with CommandException

use of net.minecraft.command.CommandException in project ImmersiveEngineering by BluSunrize.

the class CommandHandler method execute.

@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, String[] args) throws CommandException {
    List<String> argsCleaned = new ArrayList<>(args.length);
    String currentPart = null;
    for (String s : args) {
        if (s.startsWith(start)) {
            if (currentPart != null)
                throw new CommandException("String opens twice (once \"" + currentPart + "\", once \"" + s + "\")");
            currentPart = s;
        } else if (currentPart != null)
            currentPart += " " + s;
        else
            argsCleaned.add(s);
        if (s.endsWith(end)) {
            if (currentPart == null)
                throw new CommandException("String closed without being openeed first! (\"" + s + "\")");
            if (currentPart.length() >= 2)
                argsCleaned.add(currentPart.substring(1, currentPart.length() - 1));
            currentPart = null;
        }
    }
    if (currentPart != null)
        throw new CommandException("Unclosed string (" + currentPart + ")");
    super.execute(server, sender, argsCleaned.toArray(new String[0]));
}
Also used : ArrayList(java.util.ArrayList) CommandException(net.minecraft.command.CommandException)

Example 28 with CommandException

use of net.minecraft.command.CommandException in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTriggerTest method command_badInput.

@ParameterizedTest
@MethodSource("provideBadCommandInputs")
void command_badInput(String[] commandArgs, String errorMessage, boolean player) {
    final ICommandSender sender = player ? testManager.getPlayer() : testManager.getServer();
    // Validate we throw the right error
    final CommandException exception = Assertions.assertThrows(CommandException.class, () -> command.handleCommand(testManager.getServer(), sender, commandArgs));
    // validate the error contains the right message
    Assertions.assertEquals(errorMessage, exception.getMessage());
}
Also used : CommandException(net.minecraft.command.CommandException) ICommandSender(net.minecraft.command.ICommandSender) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with CommandException

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

the class CommandEditStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(commandSender);
    Parameters parameters = Parameters.of(args, expect()::declare);
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
    String structureID = parameters.get("id").optional().orElse(parameters.get(0).require());
    GenericStructure base = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
    GenericStructure from = parameters.get("from").to(p -> RCP.genericStructure(p, false)).optional().orElse(base);
    if (base != from) {
        from = from.copyAsGenericStructure();
        from.worldDataCompound = base.worldDataCompound.copy();
    }
    PacketEditStructureHandler.openEditStructure(entityPlayerMP, from, entityPlayerMP.getPosition(), structureID, directory);
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) PacketEditStructureHandler(ivorius.reccomplex.network.PacketEditStructureHandler) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 30 with CommandException

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

the class CommandLookupStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String id = parameters.get(0).require();
    GenericStructure structure = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
    Metadata metadata = structure.metadata;
    boolean hasWeblink = !metadata.weblink.trim().isEmpty();
    ITextComponent weblink = hasWeblink ? new TextComponentString(RCStrings.abbreviateFormatted(metadata.weblink, 30)) : RecurrentComplex.translations.format("commands.rclookup.reply.nolink");
    if (hasWeblink) {
        weblink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, metadata.weblink));
        weblink.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(metadata.weblink)));
    }
    ITextComponent level = new TextComponentString(StructureRegistry.INSTANCE.status(id).getLevel().toString());
    level.getStyle().setColor(TextFormatting.YELLOW);
    commandSender.sendMessage(RecurrentComplex.translations.format(StructureRegistry.INSTANCE.hasActive(id) ? "commands.rclookup.reply.generates" : "commands.rclookup.reply.silent", id, RCTextStyle.users(metadata.authors), level, weblink));
    if (!metadata.comment.trim().isEmpty())
        commandSender.sendMessage(RecurrentComplex.translations.format("commands.rclookup.reply.comment", metadata.comment));
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) TextFormatting(net.minecraft.util.text.TextFormatting) ClickEvent(net.minecraft.util.text.event.ClickEvent) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) RCStrings(ivorius.reccomplex.utils.RCStrings) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) HoverEvent(net.minecraft.util.text.event.HoverEvent) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) 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