Search in sources :

Example 11 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.

the class CommandWrite 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).optional().orElse(ResourceDirectory.ACTIVE);
    Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
    Set<String> ids = 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());
    int saved = 0, failed = 0;
    for (String id : ids) {
        if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
            continue;
        boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
        if (success)
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcsaveall.result", saved, RCTextStyle.path(directory), failed));
    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) Set(java.util.Set) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) 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) 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) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) NaP(ivorius.mcopts.commands.parameters.NaP) RCP(ivorius.reccomplex.commands.parameters.RCP) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression)

Example 12 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory 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 13 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory 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

ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)13 RCP (ivorius.reccomplex.commands.parameters.RCP)7 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 Parameters (ivorius.mcopts.commands.parameters.Parameters)5 RCConfig (ivorius.reccomplex.RCConfig)5 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)5 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)5 CommandException (net.minecraft.command.CommandException)5 ICommandSender (net.minecraft.command.ICommandSender)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)4 Expect (ivorius.mcopts.commands.parameters.expect.Expect)4 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)4 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)4 NaP (ivorius.mcopts.commands.parameters.NaP)3 FileSaverAdapter (ivorius.reccomplex.files.saving.FileSaverAdapter)3 SaveDirectoryData (ivorius.reccomplex.utils.SaveDirectoryData)3