From 61ff68d34a9a292b7eee2a5025066ee4efe2e502 Mon Sep 17 00:00:00 2001 From: a <69326411+Mooy1@users.noreply.github.com> Date: Mon, 26 Apr 2021 18:15:07 -0500 Subject: [PATCH] fix --- .../slimefun4/core/guide/GuideHistory.java | 25 ++++++++++++++++++- .../guide/SurvivalSlimefunGuide.java | 5 ++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java index 7c1088ee8..a31d22aa3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.core.guide; import java.util.Deque; import java.util.LinkedList; +import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -28,6 +29,7 @@ public class GuideHistory { private final PlayerProfile profile; private final Deque> queue = new LinkedList<>(); + private int mainMenuPage = 1; /** * This creates a new {@link GuideHistory} for the given {@link PlayerProfile} @@ -47,6 +49,27 @@ public class GuideHistory { queue.clear(); } + /** + * This method sets the page of the main menu of this {@link GuideHistory} + * + * @param page + * The current page of the main menu that should be stored + */ + public void setMainMenuPage(int page) { + Validate.isTrue(page >= 1, "page must be greater than 0!"); + + mainMenuPage = page; + } + + /** + * This returns the current main menu page of this {@link GuideHistory} + * + * @return The main menu page of this {@link GuideHistory} + */ + public int getMainMenuPage() { + return mainMenuPage; + } + /** * This method adds a {@link Category} to this {@link GuideHistory}. * Should the {@link Category} already be the last element in this {@link GuideHistory}, @@ -165,7 +188,7 @@ public class GuideHistory { private void open(@Nonnull SlimefunGuideImplementation guide, @Nullable GuideEntry entry) { if (entry == null) { - guide.openMainMenu(profile, 1); + guide.openMainMenu(profile, mainMenuPage); } else if (entry.getIndexedObject() instanceof Category) { guide.openCategory(profile, (Category) entry.getIndexedObject(), entry.getPage()); } else if (entry.getIndexedObject() instanceof SlimefunItem) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index a986df51d..e36fd3454 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -146,6 +146,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation { if (isSurvivalMode()) { profile.getGuideHistory().clear(); } + profile.getGuideHistory().setMainMenuPage(page); ChestMenu menu = create(p); List categories = getVisibleCategories(p, profile); @@ -602,7 +603,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation { menu.addMenuClickHandler(slot, (pl, s, is, action) -> { if (action.isShiftClicked()) { - openMainMenu(profile, 1); + openMainMenu(profile, profile.getGuideHistory().getMainMenuPage()); } else { history.goBack(this); } @@ -612,7 +613,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation { } else { menu.addItem(slot, new CustomItem(ChestMenuUtils.getBackButton(p, "", ChatColor.GRAY + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide")))); menu.addMenuClickHandler(slot, (pl, s, is, action) -> { - openMainMenu(profile, 1); + openMainMenu(profile, profile.getGuideHistory().getMainMenuPage()); return false; }); }