use of ivorius.reccomplex.commands.parameters.RCParameters 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);
}
use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.
the class CommandWriteAll method getTabCompletions.
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
RCParameters parameters = RCParameters.of(args);
RCExpect<?> expect = RCExpect.expectRC();
// Can't chain because of compiler bug :|
expect.next(RecurrentComplex.saver.keySet());
expect.next(args1 -> parameters.get().first().tryGet().map(RecurrentComplex.saver::get).map(a -> a.getRegistry().ids()).orElse(Collections.emptySet()));
expect.named("dir").resourceDirectory();
return expect.get(server, sender, args, pos);
}
use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.
the class CommandMapStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
String id = parameters.get().first().require();
GenericStructure structure = parameters.rc().genericStructure().require();
ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
CommandVirtual virtual = parameters.rc().move(1).virtualCommand(server).require();
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(2).varargs());
} catch (MockWorld.VirtualWorldException ex) {
throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
}
structure.worldDataCompound = worldData.createTagCompound();
PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, true);
}
use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.
the class CommandSightCheck method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
World world = commandSender.getEntityWorld();
BlockPos pos = parameters.mc().pos(commandSender.getPosition(), false).require();
List<WorldStructureGenerationData.Entry> entries = WorldStructureGenerationData.get(world).entriesAt(pos).collect(Collectors.toCollection(ArrayList::new));
if (entries.size() > 0)
commandSender.sendMessage(ServerTranslations.format(new ArrayList<ITextComponent>().size() > 1 ? "commands.whatisthis.many" : "commands.whatisthis.one", ServerTranslations.join(entries.stream().map(RCTextStyle::sight).collect(Collectors.toList()))));
else
commandSender.sendMessage(ServerTranslations.format("commands.whatisthis.none"));
}
Aggregations