diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java index 66b9b78fa..2c8968f8e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java @@ -327,8 +327,8 @@ public class ItemGroup implements Keyed { @Override public final boolean equals(Object obj) { - if (obj instanceof ItemGroup) { - return ((ItemGroup) obj).getKey().equals(getKey()); + if (obj instanceof ItemGroup group) { + return group.getKey().equals(this.getKey()); } else { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index 26bfd604f..bc8d2e3c2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -482,8 +482,8 @@ public class SlimefunItem implements Placeable { } // Lock the SlimefunItemStack from any accidental manipulations - if (itemStackTemplate instanceof SlimefunItemStack slimefunItemStack && isItemStackImmutable()) { - slimefunItemStack.lock(); + if (itemStackTemplate instanceof SlimefunItemStack stack && isItemStackImmutable()) { + stack.lock(); } postRegister(); @@ -755,8 +755,8 @@ public class SlimefunItem implements Placeable { } // If the given item is a SlimefunitemStack, simply compare the id - if (item instanceof SlimefunItemStack) { - return getId().equals(((SlimefunItemStack) item).getItemId()); + if (item instanceof SlimefunItemStack stack) { + return getId().equals(stack.getItemId()); } if (item.hasItemMeta()) { @@ -807,10 +807,10 @@ public class SlimefunItem implements Placeable { itemhandlers.put(handler.getIdentifier(), handler); // Tickers are a special case (at the moment at least) - if (handler instanceof BlockTicker) { + if (handler instanceof BlockTicker ticker) { ticking = true; Slimefun.getRegistry().getTickerBlocks().add(getId()); - blockTicker = (BlockTicker) handler; + blockTicker = ticker; } } } @@ -1033,8 +1033,8 @@ public class SlimefunItem implements Placeable { addon.getLogger().log(Level.SEVERE, message, throwable); // We definitely want to re-throw them during Unit Tests - if (throwable instanceof RuntimeException && Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { - throw (RuntimeException) throwable; + if (throwable instanceof RuntimeException e && Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { + throw e; } } @@ -1122,8 +1122,8 @@ public class SlimefunItem implements Placeable { @Override public final boolean equals(Object obj) { - if (obj instanceof SlimefunItem) { - return ((SlimefunItem) obj).getId().equals(getId()); + if (obj instanceof SlimefunItem item) { + return item.getId().equals(this.getId()); } else { return false; } @@ -1157,8 +1157,8 @@ public class SlimefunItem implements Placeable { return null; } - if (item instanceof SlimefunItemStack) { - return getById(((SlimefunItemStack) item).getItemId()); + if (item instanceof SlimefunItemStack stack) { + return getById(stack.getItemId()); } Optional itemID = Slimefun.getItemDataService().getItemData(item); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 346b9a161..de807c1d9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -515,7 +515,7 @@ public class PlayerProfile { @Override public boolean equals(Object obj) { - return obj instanceof PlayerProfile && uuid.equals(((PlayerProfile) obj).uuid); + return obj instanceof PlayerProfile profile && uuid.equals(profile.uuid); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index f01b19112..415d75555 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -146,7 +146,7 @@ class VersionsCommand extends SubCommand { secondaryColor = ChatColor.DARK_GREEN; String authors = String.join(", ", plugin.getDescription().getAuthors()); - if (plugin instanceof SlimefunAddon && ((SlimefunAddon) plugin).getBugTrackerURL() != null) { + if (plugin instanceof SlimefunAddon addon && addon.getBugTrackerURL() != null) { // @formatter:off hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder() .append("Author(s): ") @@ -158,7 +158,7 @@ class VersionsCommand extends SubCommand { )); // @formatter:on - clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, ((SlimefunAddon) plugin).getBugTrackerURL()); + clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, addon.getBugTrackerURL()); } else { // @formatter:off hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder() @@ -173,7 +173,7 @@ class VersionsCommand extends SubCommand { primaryColor = ChatColor.RED; secondaryColor = ChatColor.DARK_RED; - if (plugin instanceof SlimefunAddon && ((SlimefunAddon) plugin).getBugTrackerURL() != null) { + if (plugin instanceof SlimefunAddon addon && addon.getBugTrackerURL() != null) { // @formatter:off hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder() .append("This plugin is disabled.\nCheck the console for an error message.") @@ -184,8 +184,6 @@ class VersionsCommand extends SubCommand { )); // @formatter:on - SlimefunAddon addon = (SlimefunAddon) plugin; - if (addon.getBugTrackerURL() != null) { clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, addon.getBugTrackerURL()); } 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 ca9245c10..d84adcfee 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 @@ -188,14 +188,14 @@ public class GuideHistory { private void open(@Nonnull SlimefunGuideImplementation guide, @Nullable GuideEntry entry) { if (entry == null) { guide.openMainMenu(profile, mainMenuPage); - } else if (entry.getIndexedObject() instanceof ItemGroup) { - guide.openItemGroup(profile, (ItemGroup) entry.getIndexedObject(), entry.getPage()); - } else if (entry.getIndexedObject() instanceof SlimefunItem) { - guide.displayItem(profile, (SlimefunItem) entry.getIndexedObject(), false); - } else if (entry.getIndexedObject() instanceof ItemStack) { - guide.displayItem(profile, (ItemStack) entry.getIndexedObject(), entry.getPage(), false); - } else if (entry.getIndexedObject() instanceof String) { - guide.openSearch(profile, (String) entry.getIndexedObject(), false); + } else if (entry.getIndexedObject() instanceof ItemGroup group) { + guide.openItemGroup(profile, group, entry.getPage()); + } else if (entry.getIndexedObject() instanceof SlimefunItem item) { + guide.displayItem(profile, item, false); + } else if (entry.getIndexedObject() instanceof ItemStack stack) { + guide.displayItem(profile, stack, entry.getPage(), false); + } else if (entry.getIndexedObject() instanceof String query) { + guide.openSearch(profile, query, false); } else { throw new IllegalStateException("Unknown GuideHistory entry: " + entry.getIndexedObject()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java index f959a7493..c9137ed24 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java @@ -99,8 +99,7 @@ public class MinecraftRecipeService { * * @return An {@link Optional} describing the furnace output of the given {@link ItemStack} */ - @Nonnull - public Optional getFurnaceOutput(@Nullable ItemStack input) { + public @Nonnull Optional getFurnaceOutput(@Nullable ItemStack input) { if (snapshot == null || input == null) { return Optional.empty(); } @@ -132,18 +131,17 @@ public class MinecraftRecipeService { * * @return An Array of {@link RecipeChoice} representing the shape of this {@link Recipe} */ - @Nonnull - public RecipeChoice[] getRecipeShape(@Nonnull Recipe recipe) { + public @Nonnull RecipeChoice[] getRecipeShape(@Nonnull Recipe recipe) { Validate.notNull(recipe, "Recipe must not be null!"); - if (recipe instanceof ShapedRecipe) { + if (recipe instanceof ShapedRecipe shapedRecipe) { List choices = new LinkedList<>(); - for (String row : ((ShapedRecipe) recipe).getShape()) { + for (String row : shapedRecipe.getShape()) { int columns = row.toCharArray().length; for (char key : row.toCharArray()) { - choices.add(((ShapedRecipe) recipe).getChoiceMap().get(key)); + choices.add(shapedRecipe.getChoiceMap().get(key)); } while (columns < 3) { @@ -167,8 +165,7 @@ public class MinecraftRecipeService { * * @return An array of {@link Recipe Recipes} to craft the given {@link ItemStack} */ - @Nonnull - public Recipe[] getRecipesFor(@Nullable ItemStack item) { + public @Nonnull Recipe[] getRecipesFor(@Nullable ItemStack item) { if (snapshot == null || item == null) { return new Recipe[0]; } else { @@ -187,8 +184,7 @@ public class MinecraftRecipeService { * * @return The corresponding {@link Recipe} or null */ - @Nullable - public Recipe getRecipe(@Nonnull NamespacedKey key) { + public @Nullable Recipe getRecipe(@Nonnull NamespacedKey key) { Validate.notNull(key, "The NamespacedKey should not be null"); if (snapshot != null) {