Skip to content

Commit

Permalink
Fix level progression menu bugs with non-default items_per_page
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Jul 14, 2023
1 parent ab76560 commit 80d2b27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public Set<Integer> getDefinedContexts(Player player, ActiveMenu activeMenu) {
Set<Integer> levels = new HashSet<>();
int position = (level + 1) % itemsPerPage; // Calculate the first-page equivalent next level
if (position == 0) { // Account for next skill level 24
position = 24;
position = itemsPerPage;
} else if (position == 1) { // Account for next skill level 25
position = 25;
position = itemsPerPage + 1;
}
levels.add(position);
return levels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public LevelProgressionOpener(AureliumSkills plugin) {
}

public void open(Player player, PlayerData playerData, Skill skill) {
int page = getPage(skill, playerData);
Map<String, Object> properties = new HashMap<>();
properties.put("skill", skill);
// Get items per page from options, default to 24
int itemsPerPage = 24;
ConfigurableMenu levelProgressionMenu = plugin.getSlate().getMenuManager().getMenu("level_progression");
Expand All @@ -31,14 +28,17 @@ public void open(Player player, PlayerData playerData, Skill skill) {
itemsPerPage = (int) itemsPerPageObj;
}
}
int page = getPage(skill, playerData, itemsPerPage);
Map<String, Object> properties = new HashMap<>();
properties.put("skill", skill);
properties.put("items_per_page", itemsPerPage);
properties.put("previous_menu", "skills");
plugin.getMenuManager().openMenu(player, "level_progression", properties, page);
}

protected int getPage(Skill skill, PlayerData playerData) {
int page = (playerData.getSkillLevel(skill) - 1) / 24;
int maxLevelPage = (OptionL.getMaxLevel(skill) - 2) / 24;
protected int getPage(Skill skill, PlayerData playerData, int itemsPerPage) {
int page = (playerData.getSkillLevel(skill) - 1) / itemsPerPage;
int maxLevelPage = (OptionL.getMaxLevel(skill) - 2) / itemsPerPage;
if (page > maxLevelPage) {
page = maxLevelPage;
}
Expand Down

0 comments on commit 80d2b27

Please sign in to comment.