use of ivorius.mcopts.commands.parameters.expect.Expect 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);
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandFill method execute.
@Override
public void execute(MockWorld world, ICommandSender sender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
Block dstBlock = parameters.get(0).to(MCP::block, sender).require();
int[] dstMeta = parameters.get("metadata").to(RCP::metadatas).optional().orElse(new int[1]);
List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
RCP.Shape shape = parameters.get("shape").to(RCP::shape).optional().orElse(RCP.Shape.cube);
PositionedBlockExpression matcher = parameters.get(1).rest(NaP::join).orElse("").to(RCP::expression, new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(sender, null, true);
RCCommands.assertSize(sender, selectionOwner);
if (parameters.has("flood")) {
List<EnumFacing> directions = parameters.get("flood").orElse("").to(RCP::directions).require();
List<BlockPos> dirty = new ArrayList<>();
Set<BlockPos> visited = Sets.newHashSet(dirty);
runShape(shape, selectionOwner.getSelection(), dirty::add);
while (!dirty.isEmpty()) {
BlockPos pos = dirty.remove(dirty.size() - 1);
for (EnumFacing facing : directions) {
BlockPos offset = pos.offset(facing);
if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, offset)) && visited.add(offset))
dirty.add(offset);
}
if (visited.size() > MAX_FLOOD)
throw new CommandException("Area too big to flood!");
}
visited.forEach(p -> setFrom(world, dst, p));
} else {
// TODO Can't freeze because the lighting update won't get sent
// HeightMapFreezer freezer = HeightMapFreezer.freeze(BlockAreas.toBoundingBox(selectionOwner.getSelection()), sender.getEntityWorld());
runShape(shape, selectionOwner.getSelection(), pos -> {
if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, pos))) {
setFrom(world, dst, pos);
// freezer.markBlock(pos, state);
}
});
// freezer.melt();
}
}
use of ivorius.mcopts.commands.parameters.expect.Expect 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);
}
}
use of ivorius.mcopts.commands.parameters.expect.Expect 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);
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandSearchStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
List<ToDoubleFunction<String>> ranks = new ArrayList<>();
consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
boolean all = parameters.has("all");
if (ranks.stream().noneMatch(Objects::nonNull))
throw new WrongUsageException(getUsage(sender));
postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
Aggregations