use of ivorius.reccomplex.commands.CommandVirtual 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.commands.CommandVirtual 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);
}
Aggregations