Search in sources :

Example 1 with FileSaverAdapter

use of ivorius.reccomplex.files.saving.FileSaverAdapter in project RecurrentComplex by Ivorforce.

the class CommandWriteAll method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String adapterID = parameters.get().first().require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw ServerTranslations.commandException("commands.rcsaveall.noregistry");
    ResourceDirectory directory = parameters.rc("dir").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().at(1).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(ServerTranslations.format("commands.rcsaveall.result", saved, directory, failed));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Set(java.util.Set) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCConfig(ivorius.reccomplex.RCConfig) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Aggregations

RCConfig (ivorius.reccomplex.RCConfig)1 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)1 RCCommands (ivorius.reccomplex.commands.RCCommands)1 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)1 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)1 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)1 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)1 FileSaverAdapter (ivorius.reccomplex.files.saving.FileSaverAdapter)1 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)1 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)1 ExpressionCache (ivorius.reccomplex.utils.algebra.ExpressionCache)1 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 CommandBase (net.minecraft.command.CommandBase)1 CommandException (net.minecraft.command.CommandException)1 ICommandSender (net.minecraft.command.ICommandSender)1