use of ivorius.reccomplex.utils.expression.ResourceExpression in project RecurrentComplex by Ivorforce.
the class CommandMapAllStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
ResourceExpression expression = new ResourceExpression(StructureRegistry.INSTANCE::has);
IvOptional.ifAbsent(parameters.rc("exp").expression(expression).optional(), () -> expression.setExpression(""));
ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
CommandVirtual virtual = parameters.rc().virtualCommand(server).require();
int saved = 0, failed = 0, skipped = 0;
for (String id : StructureRegistry.INSTANCE.ids()) {
if (!expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id)))
continue;
Structure<?> info = StructureRegistry.INSTANCE.get(id);
if (!(info instanceof GenericStructure)) {
skipped++;
continue;
}
GenericStructure structure = (GenericStructure) info;
IvWorldData worldData = structure.constructWorldData();
MockWorld world = new MockWorld.WorldData(worldData);
try {
virtual.execute(world, new CommandSelecting.SelectingSender(commandSender, BlockPos.ORIGIN, worldData.blockCollection.area().getHigherCorner()), parameters.get().move(1).varargs());
} catch (MockWorld.VirtualWorldException ex) {
throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
}
structure.worldDataCompound = worldData.createTagCompound();
if (PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, false))
saved++;
else
failed++;
}
commandSender.sendMessage(ServerTranslations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
use of ivorius.reccomplex.utils.expression.ResourceExpression 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