use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.
the class PacketSaveStructureHandler method write.
public static boolean write(ICommandSender sender, GenericStructure structure, String id, ResourceDirectory saveDir, boolean deleteOther, boolean inform) {
StructureRegistry.INSTANCE.register(id, "", structure, saveDir.isActive(), saveDir.getLevel());
ResourceDirectory delDir = saveDir.opposite();
boolean saveResult = RecurrentComplex.saver.trySave(saveDir.toPath(), RCFileSaver.STRUCTURE, id);
if (!inform || RCCommands.informSaveResult(saveResult, sender, saveDir, RCFileSaver.STRUCTURE, id)) {
if (deleteOther) {
Pair<Set<Path>, Set<Path>> deleteResult = RecurrentComplex.saver.tryDeleteWithID(delDir.toPath(), RCFileSaver.STRUCTURE, id);
if (inform)
RCCommands.informDeleteResult(deleteResult, sender, RCFileSaver.STRUCTURE, id, delDir);
}
}
return saveResult;
}
use of ivorius.reccomplex.files.loading.ResourceDirectory 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.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.
the class PacketSaveStructureHandler method processServer.
@Override
public void processServer(PacketSaveStructure message, MessageContext ctx, WorldServer server) {
NetHandlerPlayServer netHandlerPlayServer = ctx.getServerHandler();
EntityPlayerMP player = netHandlerPlayServer.player;
if (RecurrentComplex.checkPerms(player))
return;
RCEntityInfo entityInfo = RCEntityInfo.get(player, null);
GenericStructure genericStructureInfo = message.getStructureInfo();
if (entityInfo != null)
genericStructureInfo.worldDataCompound = entityInfo.getCachedExportStructureBlockDataNBT();
SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
String id = message.getStructureID();
ResourceDirectory saveDir = saveDirectoryDataResult.directory;
write(player, genericStructureInfo, id, saveDir, saveDirectoryDataResult.deleteOther, true);
}
use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.
the class PacketSaveLootTableHandler method processServer.
@Override
public void processServer(PacketSaveLootTable message, MessageContext ctx, WorldServer server) {
NetHandlerPlayServer playServer = ctx.getServerHandler();
EntityPlayerMP player = playServer.player;
if (RecurrentComplex.checkPerms(player))
return;
SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
String id = message.getKey();
ResourceDirectory saveDir = saveDirectoryDataResult.directory;
ResourceDirectory delDir = saveDir.opposite();
GenericItemCollectionRegistry.INSTANCE.register(id, "", message.getComponent(), saveDir.isActive(), saveDir.getLevel());
if (RCCommands.informSaveResult((message.getComponent() != null && id != null) && RecurrentComplex.saver.trySave(saveDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, saveDir, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id)) {
if (saveDirectoryDataResult.deleteOther)
RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(delDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id, delDir);
ItemStack heldItem = playServer.player.getHeldItem(EnumHand.MAIN_HAND);
if (heldItem != null && heldItem.getItem() instanceof ItemLootTableComponentTag)
ItemLootTableComponentTag.setComponentKey(heldItem, id);
player.openContainer.detectAndSendChanges();
}
}
use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.
the class CommandConvertSchematic method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
if (args.length < 1)
throw RecurrentComplex.translations.wrongUsageException("commands.rcconvertschematic.usage");
ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
String schematicName = parameters.get(0).require();
String structureID = parameters.get("id").optional().orElse(schematicName);
SchematicFile schematicFile = CommandImportSchematic.parseSchematic(schematicName);
GenericStructure from = parameters.get("from").to(RCP::structureFromBlueprint, commandSender).require();
from.worldDataCompound = CommandExportSchematic.toWorldData(schematicFile).createTagCompound();
PacketEditStructureHandler.openEditStructure(player, from, player.getPosition(), structureID, directory);
}
Aggregations