diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java index a58d0b139..bb6055555 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java @@ -61,8 +61,8 @@ public final class HashedArmorpiece { this.hash = copy.hashCode(); } - if (item instanceof SlimefunArmorPiece) { - this.item = Optional.of((SlimefunArmorPiece) item); + if (item instanceof SlimefunArmorPiece slimefunArmorPiece) { + this.item = Optional.of(slimefunArmorPiece); } else { this.item = Optional.empty(); } 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 9de395309..26bfd604f 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 && isItemStackImmutable()) { - ((SlimefunItemStack) itemStackTemplate).lock(); + if (itemStackTemplate instanceof SlimefunItemStack slimefunItemStack && isItemStackImmutable()) { + slimefunItemStack.lock(); } postRegister(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index 024972196..5604cdcfa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -128,12 +128,12 @@ public class SlimefunItemStack extends ItemStack { im.setLore(lines); } - if (im instanceof LeatherArmorMeta) { - ((LeatherArmorMeta) im).setColor(color); + if (im instanceof LeatherArmorMeta leatherArmorMeta) { + leatherArmorMeta.setColor(color); } - if (im instanceof PotionMeta) { - ((PotionMeta) im).setColor(color); + if (im instanceof PotionMeta potionMeta) { + potionMeta.setColor(color); } }); } @@ -154,9 +154,9 @@ public class SlimefunItemStack extends ItemStack { im.setLore(lines); } - if (im instanceof PotionMeta) { - ((PotionMeta) im).setColor(color); - ((PotionMeta) im).addCustomEffect(effect, true); + if (im instanceof PotionMeta potionMeta) { + potionMeta.setColor(color); + potionMeta.addCustomEffect(effect, true); if (effect.getType().equals(PotionEffectType.SATURATION)) { im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); 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 bd7543b84..346b9a161 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 @@ -487,9 +487,7 @@ public class PlayerProfile { if (!armorPiece.isPresent()) { setId = null; - } else if (armorPiece.get() instanceof ProtectiveArmor) { - ProtectiveArmor protectedArmor = (ProtectiveArmor) armorPiece.get(); - + } else if (armorPiece.get() instanceof ProtectiveArmor protectedArmor) { if (setId == null && protectedArmor.isFullSetRequired()) { setId = protectedArmor.getArmorSetId(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java index cc6e1d127..c15b9e483 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java @@ -175,8 +175,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy if (isValidInventory(targetBlock)) { BlockState state = PaperLib.getBlockState(targetBlock, false).getState(); - if (state instanceof InventoryHolder) { - Inventory inv = ((InventoryHolder) state).getInventory(); + if (state instanceof InventoryHolder inventoryHolder) { + Inventory inv = inventoryHolder.getInventory(); if (craft(inv, recipe)) { // We are done crafting! @@ -202,14 +202,12 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy protected boolean isValidInventory(@Nonnull Block block) { Material type = block.getType(); - switch (type) { - case CHEST: - case TRAPPED_CHEST: - case BARREL: - return true; - default: - return SlimefunTag.SHULKER_BOXES.isTagged(type); - } + return switch (type) { + case CHEST, + TRAPPED_CHEST, + BARREL -> true; + default -> SlimefunTag.SHULKER_BOXES.isTagged(type); + }; } /** @@ -251,16 +249,16 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy BlockStateSnapshotResult result = PaperLib.getBlockState(b, false); BlockState state = result.getState(); - if (state instanceof Skull) { + if (state instanceof Skull skull) { if (recipe == null) { // Clear the value from persistent data storage - PersistentDataAPI.remove((Skull) state, recipeStorageKey); + PersistentDataAPI.remove(skull, recipeStorageKey); // Also remove the "enabled" state since this should be per-recipe. - PersistentDataAPI.remove((Skull) state, recipeEnabledKey); + PersistentDataAPI.remove(skull, recipeEnabledKey); } else { // Store the value to persistent data storage - PersistentDataAPI.setString((Skull) state, recipeStorageKey, recipe.toString()); + PersistentDataAPI.setString(skull, recipeStorageKey, recipe.toString()); } // Fixes #2899 - Update the BlockState if necessary @@ -337,12 +335,12 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy BlockState state = PaperLib.getBlockState(b, false).getState(); // Make sure the block is still a Skull - if (state instanceof Skull) { + if (state instanceof Skull skull) { if (enabled) { - PersistentDataAPI.remove((Skull) state, recipeEnabledKey); + PersistentDataAPI.remove(skull, recipeEnabledKey); Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.re-enabled"); } else { - PersistentDataAPI.setByte((Skull) state, recipeEnabledKey, (byte) 1); + PersistentDataAPI.setByte(skull, recipeEnabledKey, (byte) 1); Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.temporarily-disabled"); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java index 95a6df565..12cef3cf9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java @@ -136,10 +136,10 @@ public abstract class AbstractRecipe { */ @Nullable public static AbstractRecipe of(@Nullable Recipe recipe) { - if (recipe instanceof ShapedRecipe) { - return new VanillaRecipe((ShapedRecipe) recipe); - } else if (recipe instanceof ShapelessRecipe) { - return new VanillaRecipe((ShapelessRecipe) recipe); + if (recipe instanceof ShapedRecipe shapedRecipe) { + return new VanillaRecipe(shapedRecipe); + } else if (recipe instanceof ShapelessRecipe shapelessRecipe) { + return new VanillaRecipe(shapelessRecipe); } else { return null; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java index 23354ae43..8816461a9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java @@ -60,9 +60,9 @@ public class SlimefunAutoCrafter extends AbstractAutoCrafter { BlockState state = PaperLib.getBlockState(b, false).getState(); - if (state instanceof Skull) { + if (state instanceof Skull skull) { // Read the stored value from persistent data storage - PersistentDataContainer container = ((Skull) state).getPersistentDataContainer(); + PersistentDataContainer container = skull.getPersistentDataContainer(); String value = container.get(recipeStorageKey, PersistentDataType.STRING); SlimefunItem item = SlimefunItem.getById(value); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java index 8302f9b91..8c54e77af 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java @@ -61,9 +61,9 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter { public @Nullable AbstractRecipe getSelectedRecipe(@Nonnull Block b) { BlockState state = PaperLib.getBlockState(b, false).getState(); - if (state instanceof Skull) { + if (state instanceof Skull skull) { // Read the stored value from persistent data storage - PersistentDataContainer container = ((Skull) state).getPersistentDataContainer(); + PersistentDataContainer container = skull.getPersistentDataContainer(); String value = container.get(recipeStorageKey, PersistentDataType.STRING); if (value != null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java index e4d6b1f99..0654c4e36 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java @@ -81,19 +81,19 @@ class VanillaRecipe extends AbstractRecipe { RecipeChoice[] choices = Slimefun.getMinecraftRecipeService().getRecipeShape(recipe); ItemStack[] items = new ItemStack[9]; - if (choices.length == 1 && choices[0] instanceof MaterialChoice) { - items[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0)); + if (choices.length == 1 && choices[0] instanceof MaterialChoice materialChoice) { + items[4] = new ItemStack(materialChoice.getChoices().get(0)); - if (((MaterialChoice) choices[0]).getChoices().size() > 1) { - task.add(slots[4], (MaterialChoice) choices[0]); + if (materialChoice.getChoices().size() > 1) { + task.add(slots[4], materialChoice); } } else { for (int i = 0; i < choices.length; i++) { - if (choices[i] instanceof MaterialChoice) { - items[i] = new ItemStack(((MaterialChoice) choices[i]).getChoices().get(0)); + if (choices[i] instanceof MaterialChoice materialChoice) { + items[i] = new ItemStack(materialChoice.getChoices().get(0)); - if (((MaterialChoice) choices[i]).getChoices().size() > 1) { - task.add(slots[i], (MaterialChoice) choices[i]); + if (materialChoice.getChoices().size() > 1) { + task.add(slots[i], materialChoice); } } } @@ -107,8 +107,8 @@ class VanillaRecipe extends AbstractRecipe { @Override public String toString() { - if (recipe instanceof Keyed) { - return ((Keyed) recipe).getKey().toString(); + if (recipe instanceof Keyed keyed) { + return keyed.getKey().toString(); } else { return "invalid-recipe"; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java index 0daf352b6..ee06f9ae3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java @@ -83,12 +83,11 @@ public abstract class AbstractMonsterSpawner extends SlimefunItem { ItemMeta meta = item.getItemMeta(); // Fixes #2583 - Proper NBT handling of Spawners - if (meta instanceof BlockStateMeta) { - BlockStateMeta stateMeta = (BlockStateMeta) meta; + if (meta instanceof BlockStateMeta stateMeta) { BlockState state = stateMeta.getBlockState(); - if (state instanceof CreatureSpawner) { - ((CreatureSpawner) state).setSpawnedType(type); + if (state instanceof CreatureSpawner creatureSpawner) { + creatureSpawner.setSpawnedType(type); } stateMeta.setBlockState(state); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java index 530a0742c..0e884b135 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java @@ -222,8 +222,7 @@ public class BlockPlacer extends SlimefunItem { if (meta.hasDisplayName()) { BlockStateSnapshotResult blockState = PaperLib.getBlockState(facedBlock, false); - if ((blockState.getState() instanceof Nameable)) { - Nameable nameable = ((Nameable) blockState.getState()); + if (blockState.getState() instanceof Nameable nameable) { nameable.setCustomName(meta.getDisplayName()); if (blockState.isSnapshot()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java index ebb0d081a..575177c71 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java @@ -203,10 +203,9 @@ public class Crucible extends SimpleSlimefunItem implements Rec // Fixes #2903 - Cancel physics update to resolve weird overlapping block.setType(water ? Material.WATER : Material.LAVA, false); } else { - if (water && block.getBlockData() instanceof Waterlogged) { - Waterlogged wl = (Waterlogged) block.getBlockData(); - wl.setWaterlogged(true); - block.setBlockData(wl, false); + if (water && block.getBlockData() instanceof Waterlogged waterlogged) { + waterlogged.setWaterlogged(true); + block.setBlockData(waterlogged, false); block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F); return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java index 6290535d8..b41cd8904 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java @@ -87,8 +87,8 @@ public class EnhancedFurnace extends SimpleSlimefunItem { BlockState state = result.getState(); // Check if the BlockState is a Furnace and cooking something - if (state instanceof Furnace && ((Furnace) state).getCookTime() > 0) { - setProgress((Furnace) state); + if (state instanceof Furnace furnace && furnace.getCookTime() > 0) { + setProgress(furnace); // Only update if necessary if (result.isSnapshot()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java index 26d117b85..731a695c7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java @@ -140,11 +140,11 @@ public class HologramProjector extends SlimefunItem implements HologramOwner { Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5); for (Entity n : l.getChunk().getEntities()) { - if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4) { + if (n instanceof ArmorStand armorStand && l.distanceSquared(n.getLocation()) < 0.4) { String customName = n.getCustomName(); if (customName != null && customName.equals(nametag)) { - return (ArmorStand) n; + return armorStand; } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java index fe18b36d9..ae3735b89 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java @@ -116,8 +116,8 @@ public class IgnitionChamber extends SlimefunItem { if (block.getType() == Material.DROPPER && BlockStorage.check(block) instanceof IgnitionChamber) { BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState(); - if (state instanceof Dropper) { - return ((Dropper) state).getInventory(); + if (state instanceof Dropper dropper) { + return dropper.getInventory(); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java index 91d7843e2..5e8201437 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java @@ -83,8 +83,8 @@ public class OutputChest extends SlimefunItem { // Found the output chest! Now, let's check if we can fit the product in it. BlockState state = PaperLib.getBlockState(potentialOutput, false).getState(); - if (state instanceof Chest) { - Inventory inv = ((Chest) state).getInventory(); + if (state instanceof Chest chest) { + Inventory inv = chest.getInventory(); // Check if the Item fits into that inventory. if (InvUtils.fits(inv, item)) {