public SectionData findSection(String name, GuiBook.AdvancementCache advancementCache) { for(SectionData section : sections) { section.update(advancementCache); if(section.name.equals(name.toLowerCase())) { return section.isUnlocked(advancementCache) ? section : null; } } return null; }
public int getPageCount(@Nullable GuiBook.AdvancementCache advancementCache) { int pages = 0; for(SectionData section : sections) { section.update(advancementCache); pages += section.isUnlocked(advancementCache) ? section.getPageCount() : 0; } return pages; }
public int findPageNumber(String location, @Nullable GuiBook.AdvancementCache advancementCache) { location = location.toLowerCase(); int pages = 0; if(!location.contains(".")) { return -1; } String sectionName = location.substring(0, location.indexOf('.')); String pageName = location.substring(location.indexOf('.') + 1); for(SectionData section : sections) { section.update(advancementCache); if(!section.isUnlocked(advancementCache)) { continue; } if(!sectionName.equals(section.name)) { pages += section.getPageCount(); continue; } for(PageData page : section.pages) { if(!pageName.equals(page.name)) { pages++; continue; } return pages + 1; } } return -1; }
public int getFirstPageNumber(SectionData section, @Nullable GuiBook.AdvancementCache advancementCache) { int pages = 0; for(SectionData sect : sections) { sect.update(advancementCache); if(section == sect) { return section.isUnlocked(advancementCache) ? pages + 1 : -1; } if(!sect.isUnlocked(advancementCache)) { continue; } pages += sect.getPageCount(); } return -1; }
public PageData findPage(int number, @Nullable GuiBook.AdvancementCache advancementCache) { if(number < 0) { return null; } int pages = 0; for(SectionData section : sections) { section.update(advancementCache); if(!section.isUnlocked(advancementCache)) { continue; } if(pages + section.getPageCount() > number) { return section.pages.get(number - pages); } else { pages += section.getPageCount(); } } return null; }