Search in sources :

Example 71 with CommandException

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

the class CommandMapStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    ResourceExpression expression = parameters.get(0).to(RCP::expression, new ResourceExpression(StructureRegistry.INSTANCE::has)).require();
    CommandVirtual virtual = parameters.get(1).to(RCP::virtualCommand, server).require();
    String[] virtualArgs = parameters.get(2).to(NaP::varargs).require();
    ResourceDirectory directory = parameters.has("nosave") ? null : parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(ResourceDirectory.ACTIVE);
    List<String> relevant = StructureRegistry.INSTANCE.ids().stream().filter(id -> expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id))).collect(Collectors.toList());
    boolean inform = relevant.size() == 1;
    int saved = 0, failed = 0, skipped = 0;
    for (String id : relevant) {
        switch(map(id, directory, commandSender, virtual, virtualArgs, inform)) {
            case SKIPPED:
                skipped++;
                break;
            case SUCCESS:
                saved++;
                break;
            default:
                failed++;
                break;
        }
    }
    if (!inform)
        commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) MCE(ivorius.mcopts.commands.parameters.expect.MCE) DelegatingSender(ivorius.mcopts.commands.DelegatingSender) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) MockWorld(ivorius.ivtoolkit.world.MockWorld) RCConfig(ivorius.reccomplex.RCConfig) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) NaP(ivorius.mcopts.commands.parameters.NaP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) PacketSaveStructureHandler(ivorius.reccomplex.network.PacketSaveStructureHandler) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) Collectors(java.util.stream.Collectors) Capability(net.minecraftforge.common.capabilities.Capability) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) RCP(ivorius.reccomplex.commands.parameters.RCP) List(java.util.List) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) CapabilitySelection(ivorius.reccomplex.capability.CapabilitySelection) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) Parameters(ivorius.mcopts.commands.parameters.Parameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Example 72 with CommandException

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

the class CommandSearchStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    List<ToDoubleFunction<String>> ranks = new ArrayList<>();
    consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
    consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
    consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
    consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
    consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
    consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
    consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
    boolean all = parameters.has("all");
    if (ranks.stream().noneMatch(Objects::nonNull))
        throw new WrongUsageException(getUsage(sender));
    postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
Also used : BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) MCE(ivorius.mcopts.commands.parameters.expect.MCE) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TextComponentBase(net.minecraft.util.text.TextComponentBase) RCConfig(ivorius.reccomplex.RCConfig) Function(java.util.function.Function) ServerTranslations(ivorius.mcopts.translation.ServerTranslations) ITextComponent(net.minecraft.util.text.ITextComponent) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) Collectors(java.util.stream.Collectors) MCP(ivorius.mcopts.commands.parameters.MCP) TextComponentString(net.minecraft.util.text.TextComponentString) ToDoubleBiFunction(java.util.function.ToDoubleBiFunction) RCP(ivorius.reccomplex.commands.parameters.RCP) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) ToDoubleFunction(java.util.function.ToDoubleFunction) Doubles(com.google.common.primitives.Doubles) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) WrongUsageException(net.minecraft.command.WrongUsageException) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) Parameter(ivorius.mcopts.commands.parameters.Parameter) MCP(ivorius.mcopts.commands.parameters.MCP) ToDoubleFunction(java.util.function.ToDoubleFunction)

Example 73 with CommandException

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

the class TrackKitMessenger method sendMessage.

protected void sendMessage(EntityMinecart cart) {
    cart.getRecursivePassengersByType(EntityPlayerMP.class).forEach(e -> {
        try {
            SPacketTitle pkt = new SPacketTitle(SPacketTitle.Type.ACTIONBAR, TextComponentUtils.processComponent(cart, getActionbar(), e));
            e.connection.sendPacket(pkt);
            pkt = new SPacketTitle(SPacketTitle.Type.SUBTITLE, TextComponentUtils.processComponent(cart, getSubtitle(), e));
            e.connection.sendPacket(pkt);
            pkt = new SPacketTitle(SPacketTitle.Type.TITLE, TextComponentUtils.processComponent(cart, getTitle(), e));
            e.connection.sendPacket(pkt);
        } catch (CommandException ignored) {
        }
    });
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) SPacketTitle(net.minecraft.network.play.server.SPacketTitle)

Example 74 with CommandException

use of net.minecraft.command.CommandException in project BloodMagic by WayofTime.

the class CommandBind method processCommand.

public void processCommand(ICommandSender iCommandSender, String[] astring) {
    EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
    ItemStack item = entityplayermp.getCurrentEquippedItem();
    EntityPlayerMP targetPlayer = getPlayer(iCommandSender, astring[0]);
    if (targetPlayer == null) {
        throw new CommandException("commands.bind.failed.noPlayer");
    }
    if (item != null && item.getItem() instanceof IBindable) {
        if (EnergyItems.getOwnerName(item).isEmpty()) {
            EnergyItems.checkAndSetItemOwner(item, targetPlayer);
            func_152373_a(iCommandSender, this, "commands.bind.success");
        } else {
            throw new CommandException("commands.bind.failed.alreadyBound");
        }
    } else if (!(item.getItem() instanceof IBindable)) {
        throw new CommandException("commands.bind.failed.notBindable");
    }
}
Also used : IBindable(WayofTime.alchemicalWizardry.api.items.interfaces.IBindable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ItemStack(net.minecraft.item.ItemStack)

Example 75 with CommandException

use of net.minecraft.command.CommandException in project BloodMagic by WayofTime.

the class CommandUnbind method processCommand.

public void processCommand(ICommandSender iCommandSender, String[] astring) {
    EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
    ItemStack item = entityplayermp.getCurrentEquippedItem();
    if (item != null && item.getItem() instanceof IBindable) {
        if (!EnergyItems.getOwnerName(item).isEmpty()) {
            item.getTagCompound().removeTag("ownerName");
            func_152373_a(iCommandSender, this, "commands.unbind.success");
        } else {
            throw new CommandException("commands.unbind.failed.notBindable");
        }
    } else if (!(item.getItem() instanceof IBindable)) {
        throw new CommandException("commands.unbind.failed.notBindable");
    }
}
Also used : IBindable(WayofTime.alchemicalWizardry.api.items.interfaces.IBindable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) ItemStack(net.minecraft.item.ItemStack)

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