Add module file repository to only load a section if a module is enabled

This commit is contained in:
KnightMiner committed 2019-03-21 19:45:36 -05:00
1 parent 981bf8042c
commit 5b48aac8c8
2 files changed
+33

No files matched your search

@@ -0,0 +1,5 @@
package slimeknights.mantle.client.book.data;
public class SectionDataModule extends SectionData {
public String module = "";
}
@@ -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<SectionData> 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());
}
}