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);
}
Aggregations