Search in sources :

Example 1 with InProgressTemplate

use of com.archyx.aureliumskills.menu.templates.InProgressTemplate in project AureliumSkills by Archy-X.

the class LevelProgressionMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    int currentLevel = playerData.getSkillLevel(skill);
    // Fill item
    if (options.isFillEnabled()) {
        contents.fill(ClickableItem.empty(options.getFillItem()));
    }
    SkillItem skillItem = (SkillItem) options.getItem(ItemType.SKILL);
    contents.set(skillItem.getPos(), ClickableItem.empty(skillItem.getItem(skill, playerData, player, locale)));
    BackItem backItem = (BackItem) options.getItem(ItemType.BACK);
    contents.set(backItem.getPos(), ClickableItem.of(backItem.getItem(player, locale), e -> SkillsMenu.getInventory(player, plugin).open(player)));
    CloseItem closeItem = (CloseItem) options.getItem(ItemType.CLOSE);
    contents.set(closeItem.getPos(), ClickableItem.of(closeItem.getItem(player, locale), e -> player.closeInventory()));
    RankItem rankItem = (RankItem) options.getItem(ItemType.RANK);
    contents.set(rankItem.getPos(), ClickableItem.empty(rankItem.getItem(skill, player, locale)));
    Pagination pagination = contents.pagination();
    ClickableItem[] items = new ClickableItem[36 * pages];
    if (options.isFillEnabled() && options.getFillItem() != null) {
        for (int i = 0; i < items.length; i++) {
            items[i] = ClickableItem.empty(options.getFillItem());
        }
    }
    UnlockedTemplate unlocked = (UnlockedTemplate) options.getTemplate(TemplateType.UNLOCKED);
    InProgressTemplate inProgress = (InProgressTemplate) options.getTemplate(TemplateType.IN_PROGRESS);
    LockedTemplate locked = (LockedTemplate) options.getTemplate(TemplateType.LOCKED);
    for (int i = pagination.getPage() * 24; i < pagination.getPage() * 24 + 24; i++) {
        if (i + 2 <= OptionL.getMaxLevel(skill)) {
            if (i + 2 <= currentLevel) {
                items[track.get(i)] = ClickableItem.empty(unlocked.getItem(skill, i + 2, player, locale));
            } else if (i + 2 == currentLevel + 1) {
                items[track.get(i)] = ClickableItem.empty(inProgress.getItem(skill, playerData, i + 2, player, locale));
            } else {
                items[track.get(i)] = ClickableItem.empty(locked.getItem(skill, i + 2, player, locale));
            }
        } else {
            if (options.isFillEnabled() && options.getFillItem() != null) {
                items[track.get(i)] = ClickableItem.empty(options.getFillItem());
            } else {
                items[track.get(i)] = ClickableItem.empty(new ItemStack(Material.AIR));
            }
        }
    }
    pagination.setItems(items);
    pagination.setItemsPerPage(36);
    int a = 0;
    for (int i = 9; i < 45; i++) {
        int row = i / 9;
        int column = i % 9;
        contents.set(row, column, pagination.getPageItems()[a]);
        a++;
    }
    NextPageItem nextPageItem = (NextPageItem) options.getItem(ItemType.NEXT_PAGE);
    if (pagination.getPage() + 1 < pages) {
        contents.set(nextPageItem.getPos(), ClickableItem.of(nextPageItem.getItem(player, locale), e -> {
            int page = pagination.next().getPage();
            SmartInventory inventory = getInventory(player, skill, page, plugin);
            if (inventory != null) {
                inventory.open(player, page);
            }
        }));
    }
    PreviousPageItem previousPageItem = (PreviousPageItem) options.getItem(ItemType.PREVIOUS_PAGE);
    if (pagination.getPage() - 1 >= 0) {
        contents.set(previousPageItem.getPos(), ClickableItem.of(previousPageItem.getItem(player, locale), e -> {
            int previous = pagination.previous().getPage();
            SmartInventory inventory = getInventory(player, skill, previous, plugin);
            if (inventory != null) {
                inventory.open(player, previous);
            }
        }));
    }
}
Also used : TemplateType(com.archyx.aureliumskills.menu.templates.TemplateType) MenuMessage(com.archyx.aureliumskills.lang.MenuMessage) SmartInventory(fr.minuskube.inv.SmartInventory) InProgressTemplate(com.archyx.aureliumskills.menu.templates.InProgressTemplate) OptionL(com.archyx.aureliumskills.configuration.OptionL) com.archyx.aureliumskills.menu.items(com.archyx.aureliumskills.menu.items) UnlockedTemplate(com.archyx.aureliumskills.menu.templates.UnlockedTemplate) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LockedTemplate(com.archyx.aureliumskills.menu.templates.LockedTemplate) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData) Skill(com.archyx.aureliumskills.skills.Skill) Pagination(fr.minuskube.inv.content.Pagination) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) InProgressTemplate(com.archyx.aureliumskills.menu.templates.InProgressTemplate) ClickableItem(fr.minuskube.inv.ClickableItem) Pagination(fr.minuskube.inv.content.Pagination) SmartInventory(fr.minuskube.inv.SmartInventory) UnlockedTemplate(com.archyx.aureliumskills.menu.templates.UnlockedTemplate) ItemStack(org.bukkit.inventory.ItemStack) LockedTemplate(com.archyx.aureliumskills.menu.templates.LockedTemplate)

Aggregations

AureliumSkills (com.archyx.aureliumskills.AureliumSkills)1 OptionL (com.archyx.aureliumskills.configuration.OptionL)1 PlayerData (com.archyx.aureliumskills.data.PlayerData)1 Lang (com.archyx.aureliumskills.lang.Lang)1 MenuMessage (com.archyx.aureliumskills.lang.MenuMessage)1 com.archyx.aureliumskills.menu.items (com.archyx.aureliumskills.menu.items)1 InProgressTemplate (com.archyx.aureliumskills.menu.templates.InProgressTemplate)1 LockedTemplate (com.archyx.aureliumskills.menu.templates.LockedTemplate)1 TemplateType (com.archyx.aureliumskills.menu.templates.TemplateType)1 UnlockedTemplate (com.archyx.aureliumskills.menu.templates.UnlockedTemplate)1 Skill (com.archyx.aureliumskills.skills.Skill)1 ClickableItem (fr.minuskube.inv.ClickableItem)1 SmartInventory (fr.minuskube.inv.SmartInventory)1 InventoryContents (fr.minuskube.inv.content.InventoryContents)1 InventoryProvider (fr.minuskube.inv.content.InventoryProvider)1 Pagination (fr.minuskube.inv.content.Pagination)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Material (org.bukkit.Material)1