From 5b48aac8c84052c45eb392cfb68fadc03f68b9e3 Mon Sep 17 00:00:00 2001 From: KnightMiner Date: Thu, 21 Mar 2019 19:45:36 -0500 Subject: [PATCH] Add module file repository to only load a section if a module is enabled --- .../client/book/data/SectionDataModule.java | 5 ++++ .../book/repository/ModuleFileRepository.java | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/slimeknights/mantle/client/book/data/SectionDataModule.java create mode 100644 src/main/java/slimeknights/mantle/client/book/repository/ModuleFileRepository.java diff --git a/src/main/java/slimeknights/mantle/client/book/data/SectionDataModule.java b/src/main/java/slimeknights/mantle/client/book/data/SectionDataModule.java new file mode 100644 index 0000000..20e3687 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/SectionDataModule.java @@ -0,0 +1,5 @@ +package slimeknights.mantle.client.book.data; + +public class SectionDataModule extends SectionData { + public String module = ""; +} diff --git a/src/main/java/slimeknights/mantle/client/book/repository/ModuleFileRepository.java b/src/main/java/slimeknights/mantle/client/book/repository/ModuleFileRepository.java new file mode 100644 index 0000000..113734d --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/repository/ModuleFileRepository.java @@ -0,0 +1,28 @@ +package slimeknights.mantle.client.book.repository; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.data.SectionData; +import slimeknights.mantle.client.book.data.SectionDataModule; +import slimeknights.mantle.client.book.repository.FileRepository; +import slimeknights.mantle.pulsar.control.PulseManager; + +public class ModuleFileRepository extends FileRepository { + + private PulseManager manager; + public ModuleFileRepository(PulseManager manager, String location) { + super(location); + this.manager = manager; + } + + @Override + public List getSections() { + // same as super, except we remove any where the related module is not loaded + return Arrays.stream(BookLoader.GSON.fromJson(resourceToString(getResource(getResourceLocation("index.json"))), SectionDataModule[].class)) + .filter((section)->section.module.isEmpty() || manager.isPulseLoaded(section.module)) + .collect(Collectors.toList()); + } +}