1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #3107 from martinbrom/fix/flex-category-visibility

FlexCategories can now be made visible in CheatSheet and Survival SlimefunGuide
This commit is contained in:
TheBusyBiscuit 2021-07-26 20:57:59 +02:00 committed by GitHub
commit 0262830ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 23 deletions

View File

@ -77,12 +77,12 @@ public abstract class FlexCategory extends Category {
}
@Override
public final void add(SlimefunItem item) {
public final void add(@Nonnull SlimefunItem item) {
throw new UnsupportedOperationException("You cannot add items to a FlexCategory!");
}
@Override
public final List<SlimefunItem> getItems() {
public final @Nonnull List<SlimefunItem> getItems() {
throw new UnsupportedOperationException("A FlexCategory has no items!");
}
@ -92,7 +92,7 @@ public abstract class FlexCategory extends Category {
}
@Override
public final void remove(SlimefunItem item) {
public final void remove(@Nonnull SlimefunItem item) {
throw new UnsupportedOperationException("A FlexCategory has no items, so there is nothing remove!");
}

View File

@ -64,7 +64,7 @@ public class MultiCategory extends FlexCategory {
@Override
@ParametersAreNonnullByDefault
public boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideMode mode) {
return true;
return mode == SlimefunGuideMode.SURVIVAL_MODE;
}
@Override

View File

@ -47,13 +47,12 @@ public class CheatSheetSlimefunGuide extends SurvivalSlimefunGuide {
* The {@link PlayerProfile} of the {@link Player}
* @return a {@link List} of visible {@link Category} instances
*/
@Nonnull
@Override
protected List<Category> getVisibleCategories(@Nonnull Player p, @Nonnull PlayerProfile profile) {
protected @Nonnull List<Category> getVisibleCategories(@Nonnull Player p, @Nonnull PlayerProfile profile) {
List<Category> categories = new LinkedList<>();
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
if (!(category instanceof FlexCategory)) {
if (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getMode())) {
categories.add(category);
}
}
@ -61,15 +60,13 @@ public class CheatSheetSlimefunGuide extends SurvivalSlimefunGuide {
return categories;
}
@Nonnull
@Override
public SlimefunGuideMode getMode() {
public @Nonnull SlimefunGuideMode getMode() {
return SlimefunGuideMode.CHEAT_MODE;
}
@Nonnull
@Override
public ItemStack getItem() {
public @Nonnull ItemStack getItem() {
return item;
}

View File

@ -55,7 +55,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* The {@link SurvivalSlimefunGuide} is the standard version of our {@link SlimefunGuide}.
* It uses an {@link Inventory} to display {@link SlimefunGuide} contents.
*
*
* @author TheBusyBiscuit
*
* @see SlimefunGuide
@ -83,18 +83,17 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
*
* @return The {@link Sound}
*/
@Nonnull
public Sound getSound() {
public @Nonnull Sound getSound() {
return sound;
}
@Override
public SlimefunGuideMode getMode() {
public @Nonnull SlimefunGuideMode getMode() {
return SlimefunGuideMode.SURVIVAL_MODE;
}
@Override
public ItemStack getItem() {
public @Nonnull ItemStack getItem() {
return item;
}
@ -111,13 +110,16 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
* The {@link PlayerProfile} of the {@link Player}
* @return a {@link List} of visible {@link Category} instances
*/
@Nonnull
protected List<Category> getVisibleCategories(@Nonnull Player p, @Nonnull PlayerProfile profile) {
protected @Nonnull List<Category> getVisibleCategories(@Nonnull Player p, @Nonnull PlayerProfile profile) {
List<Category> categories = new LinkedList<>();
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
try {
if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getMode()))) {
if (category instanceof FlexCategory) {
if (((FlexCategory) category).isVisible(p, profile, getMode())) {
categories.add(category);
}
} else if (!category.isHidden(p)) {
categories.add(category);
}
} catch (Exception | LinkageError x) {
@ -219,6 +221,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
}
@Override
@ParametersAreNonnullByDefault
public void openCategory(PlayerProfile profile, Category category, int page) {
Player p = profile.getPlayer();
@ -383,6 +386,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
}
@Override
@ParametersAreNonnullByDefault
public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) {
Player p = profile.getPlayer();
@ -487,6 +491,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
}
@Override
@ParametersAreNonnullByDefault
public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) {
Player p = profile.getPlayer();
@ -620,9 +625,8 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
}
}
@Nonnull
@ParametersAreNonnullByDefault
private static ItemStack getDisplayItem(Player p, boolean isSlimefunRecipe, ItemStack item) {
private static @Nonnull ItemStack getDisplayItem(Player p, boolean isSlimefunRecipe, ItemStack item) {
if (isSlimefunRecipe) {
SlimefunItem slimefunItem = SlimefunItem.getByItem(item);
@ -723,8 +727,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
return SlimefunPlugin.getPermissionsService().hasPermission(p, item);
}
@Nonnull
private ChestMenu create(@Nonnull Player p) {
private @Nonnull ChestMenu create(@Nonnull Player p) {
ChestMenu menu = new ChestMenu(SlimefunPlugin.getLocalization().getMessage(p, "guide.title.main"));
menu.setEmptySlotsClickable(false);