From e47d0171ccd2a210d652e8c082e8630ea1c85e70 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 7 Feb 2021 12:30:55 +0100 Subject: [PATCH] Fixes #2810 --- CHANGELOG.md | 1 + .../core/categories/LockedCategory.java | 3 ++- .../guide/SurvivalSlimefunGuide.java | 2 +- .../Slimefun/Objects/Category.java | 3 +-- .../Objects/SlimefunItem/SlimefunItem.java | 20 +++++++++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6322122d5..527b51960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * Fixed #2794 * Fixed #2793 * Fixed #2809 +* Fixed #2810 * Fixed a small exception which gets thrown when Slimefun is disabled due to an invalid environment ## Release Candidate 20 (30 Jan 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java index 98dfa4a69..d5334e011 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java @@ -157,7 +157,8 @@ public class LockedCategory extends Category { for (Category category : parents) { for (SlimefunItem item : category.getItems()) { - if (!item.canUse(p, false)) { + // Check if the Player has researched every item (if the item is enabled) + if (!item.isDisabledIn(p.getWorld()) && item.hasResearch() && !profile.hasUnlocked(item.getResearch())) { return false; } } 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 c59c7dfb9..0a1f20420 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 @@ -266,7 +266,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation { SlimefunItem sfitem = category.getItems().get(target); - if (Slimefun.isEnabled(p, sfitem, false)) { + if (!sfitem.isDisabledIn(p.getWorld())) { displaySlimefunItem(menu, category, p, profile, sfitem, page, index); index++; } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java index cf95721f3..6bf1bf0a7 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java @@ -26,7 +26,6 @@ import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.api.Slimefun; /** * Represents a category, which structure multiple {@link SlimefunItem} in the {@link SlimefunGuide}. @@ -258,7 +257,7 @@ public class Category implements Keyed { */ public boolean isHidden(@Nonnull Player p) { for (SlimefunItem slimefunItem : getItems()) { - if (!slimefunItem.isHidden() && Slimefun.isEnabled(p, slimefunItem, false)) { + if (!slimefunItem.isHidden() && !slimefunItem.isDisabledIn(p.getWorld())) { return false; } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index d205894db..d1c443496 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -380,6 +380,26 @@ public class SlimefunItem implements Placeable { return state != ItemState.ENABLED; } + /** + * This method returns whether this {@link SlimefunItem} is disabled + * for that specific {@link World}. + * Note that if the item is disabled globally, this method will still return false. + * + * @param world + * The {@link World} to check + * + * @return Whether this {@link SlimefunItem} is disabled in that world (or in general). + */ + public boolean isDisabledIn(@Nonnull World world) { + if (state == ItemState.UNREGISTERED) { + error("isDisabled(World) cannot be called before registering the item", new UnregisteredItemException(this)); + return false; + } + + // Check if the Item is disabled globally or in this specific world + return isDisabled() || !SlimefunPlugin.getWorldSettingsService().isEnabled(world, this); + } + /** * This method returns the {@link SlimefunAddon} that registered this * {@link SlimefunItem}. If this Item is from Slimefun itself, the current