Search in sources :

Example 11 with RCP

use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.

the class CommandDelete method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String adapterID = parameters.get(0).require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw RecurrentComplex.translations.commandException("commands.rcsave.noregistry");
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).require();
    Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
    Collection<String> ids = Lists.newArrayList(adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet()));
    ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get(1).rest(NaP::join).require());
    for (String id : ids) {
        if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
            continue;
        RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(directory.toPath(), adapterID, id), commandSender, adapterID, id, directory);
        // Could also predict changes and just reload those for the file but eh.
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
    }
}
Also used : ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Collection(java.util.Collection) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) NaP(ivorius.mcopts.commands.parameters.NaP) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Lists(com.google.common.collect.Lists) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Collections(java.util.Collections) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) NaP(ivorius.mcopts.commands.parameters.NaP) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Example 12 with RCP

use of ivorius.reccomplex.commands.parameters.RCP 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)

Aggregations

RCP (ivorius.reccomplex.commands.parameters.RCP)12 Parameters (ivorius.mcopts.commands.parameters.Parameters)8 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)7 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)6 Expect (ivorius.mcopts.commands.parameters.expect.Expect)6 RCConfig (ivorius.reccomplex.RCConfig)6 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)6 CommandException (net.minecraft.command.CommandException)6 ICommandSender (net.minecraft.command.ICommandSender)6 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 NaP (ivorius.mcopts.commands.parameters.NaP)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 BlockPos (net.minecraft.util.math.BlockPos)4 MockWorld (ivorius.ivtoolkit.world.MockWorld)3 MCE (ivorius.mcopts.commands.parameters.expect.MCE)3 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)3 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)3 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)3