diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/recipes/RecipeType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/recipes/RecipeType.java index 828c78ddb..10a1694dc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/recipes/RecipeType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/recipes/RecipeType.java @@ -99,8 +99,8 @@ public class RecipeType implements Keyed { this.key = key; this.consumer = callback; - if (item instanceof SlimefunItemStack) { - this.machine = ((SlimefunItemStack) item).getItemId(); + if (item instanceof SlimefunItemStack slimefunItemStack) { + this.machine = slimefunItemStack.getItemId(); } else { this.machine = ""; } @@ -109,7 +109,7 @@ public class RecipeType implements Keyed { public RecipeType(NamespacedKey key, ItemStack item) { this.key = key; this.item = item; - this.machine = item instanceof SlimefunItemStack ? ((SlimefunItemStack) item).getItemId() : ""; + this.machine = item instanceof SlimefunItemStack slimefunItemStack ? slimefunItemStack.getItemId() : ""; } public RecipeType(MinecraftRecipe recipe) { @@ -124,8 +124,8 @@ public class RecipeType implements Keyed { } else { SlimefunItem slimefunItem = SlimefunItem.getById(this.machine); - if (slimefunItem instanceof MultiBlockMachine) { - ((MultiBlockMachine) slimefunItem).addRecipe(recipe, result); + if (slimefunItem instanceof MultiBlockMachine multiBlockMachine) { + multiBlockMachine.addRecipe(recipe, result); } } } @@ -149,8 +149,8 @@ public class RecipeType implements Keyed { @Override public final boolean equals(Object obj) { - if (obj instanceof RecipeType) { - return ((RecipeType) obj).getKey().equals(this.getKey()); + if (obj instanceof RecipeType recipeType) { + return recipeType.getKey().equals(this.getKey()); } else { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java index 56350d931..d1580b93f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java @@ -82,8 +82,8 @@ public abstract class SubCommand { */ @Nonnull public String getDescription(@Nonnull CommandSender sender) { - if (sender instanceof Player) { - return Slimefun.getLocalization().getMessage((Player) sender, getDescription()); + if (sender instanceof Player player) { + return Slimefun.getLocalization().getMessage(player, getDescription()); } else { return Slimefun.getLocalization().getMessage(getDescription()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index 29aaca740..431d47cb6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -40,7 +40,7 @@ class BackpackCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.backpack")) { if (args.length != 3) { Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack ")); @@ -71,7 +71,7 @@ class BackpackCommand extends SubCommand { Slimefun.runSync(() -> { ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone(); Slimefun.getBackpackListener().setBackpackId(backpackOwner, item, 2, id); - ((Player) sender).getInventory().addItem(item); + player.getInventory().addItem(item); Slimefun.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given"); }); }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java index 6bfbf147a..119091e1e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java @@ -33,14 +33,12 @@ class ChargeCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.charge")) { - Player p = (Player) sender; - ItemStack item = p.getInventory().getItemInMainHand(); + ItemStack item = player.getInventory().getItemInMainHand(); SlimefunItem slimefunItem = SlimefunItem.getByItem(item); - if (slimefunItem instanceof Rechargeable) { - Rechargeable rechargeableItem = (Rechargeable) slimefunItem; + if (slimefunItem instanceof Rechargeable rechargeableItem) { rechargeableItem.setItemCharge(item, rechargeableItem.getMaxItemCharge(item)); Slimefun.getLocalization().sendMessage(sender, "commands.charge.charge-success", true); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java index f3fcd4987..973ed1ee3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java @@ -19,9 +19,9 @@ class CheatCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.cheat.items")) { - SlimefunGuide.openCheatMenu((Player) sender); + SlimefunGuide.openCheatMenu(player); } else { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java index 9769ce564..cc79b113e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java @@ -19,8 +19,8 @@ class DebugFishCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player && sender.hasPermission("slimefun.debugging")) { - ((Player) sender).getInventory().addItem(SlimefunItems.DEBUG_FISH.clone()); + if (sender instanceof Player player && sender.hasPermission("slimefun.debugging")) { + player.getInventory().addItem(SlimefunItems.DEBUG_FISH.clone()); } else { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java index 7849d49e4..006744d6c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java @@ -20,10 +20,10 @@ class GuideCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.guide")) { SlimefunGuideMode design = SlimefunGuide.getDefaultMode(); - ((Player) sender).getInventory().addItem(SlimefunGuide.getItem(design).clone()); + player.getInventory().addItem(SlimefunGuide.getItem(design).clone()); } else { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java index 2d89f09b0..83db84292 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java @@ -21,9 +21,9 @@ class OpenGuideCommand extends SubCommand { @Override @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.open_guide")) { - SlimefunGuide.openGuide((Player) sender, SlimefunGuideMode.SURVIVAL_MODE); + SlimefunGuide.openGuide(player, SlimefunGuideMode.SURVIVAL_MODE); } else { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java index 3e87fb40b..9783518b1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java @@ -23,11 +23,11 @@ class SearchCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.search")) { if (args.length > 1) { String query = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - PlayerProfile.get((Player) sender, profile -> SlimefunGuide.openSearch(profile, query, SlimefunGuideMode.SURVIVAL_MODE, true)); + PlayerProfile.get(player, profile -> SlimefunGuide.openSearch(profile, query, SlimefunGuideMode.SURVIVAL_MODE, true)); } else { Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf search ")); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java index 6e08f6e01..1ea7a60f6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java @@ -35,8 +35,8 @@ class StatsCommand extends SubCommand { } else { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } - } else if (sender instanceof Player) { - PlayerProfile.get((Player) sender, profile -> profile.sendStats(sender)); + } else if (sender instanceof Player player) { + PlayerProfile.get(player, profile -> profile.sendStats(sender)); } else { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java index 8401e3b5d..a10941d40 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java @@ -21,18 +21,17 @@ class TeleporterCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { if (sender.hasPermission("slimefun.command.teleporter")) { if (args.length == 1) { - Player p = (Player) sender; - Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(p, p.getUniqueId(), p.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); + Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, player.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); } else if (args.length == 2) { @SuppressWarnings("deprecation") - OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[1]); - if (player.getName() != null) { - Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI((Player) sender, player.getUniqueId(), ((Player) sender).getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); + if (offlinePlayer.getName() != null) { + Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, offlinePlayer.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); } else { Slimefun.getLocalization().sendMessage(sender, "messages.unknown-player", msg -> msg.replace("%player%", args[1])); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java index 74abcd902..3f65ee241 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java @@ -88,8 +88,8 @@ class TimingsCommand extends SubCommand { @Nonnull private PerformanceInspector inspectorOf(@Nonnull CommandSender sender, boolean verbose) { - if (sender instanceof Player) { - return new PlayerPerformanceInspector((Player) sender); + if (sender instanceof Player player) { + return new PlayerPerformanceInspector(player); } else { return new ConsolePerformanceInspector(sender, verbose); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 17e01dde0..bc5db4063 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -76,10 +76,10 @@ public class RainbowTickHandler extends BlockTicker { } for (Material type : materials) { - /** - * This BlockData is purely virtual and only created on startup, it should have - * no impact on performance, in fact it should save performance as it preloads - * the data but also saves heavy calls for other Materials + /* + This BlockData is purely virtual and only created on startup, it should have + no impact on performance, in fact it should save performance as it preloads + the data but also saves heavy calls for other Materials */ if (type.createBlockData() instanceof GlassPane) { return true; @@ -92,9 +92,9 @@ public class RainbowTickHandler extends BlockTicker { @Override public void tick(Block b, SlimefunItem item, Config data) { if (b.getType() == Material.AIR) { - /** - * The block was broken, setting the Material now would result in a - * duplication glitch + /* + The block was broken, setting the Material now would result in a + duplication glitch */ return; } @@ -102,12 +102,9 @@ public class RainbowTickHandler extends BlockTicker { if (glassPanes) { BlockData blockData = b.getBlockData(); - if (blockData instanceof GlassPane) { + if (blockData instanceof GlassPane previousData) { BlockData block = material.createBlockData(bd -> { - if (bd instanceof GlassPane) { - GlassPane previousData = (GlassPane) blockData; - GlassPane nextData = (GlassPane) bd; - + if (bd instanceof GlassPane nextData) { nextData.setWaterlogged(previousData.isWaterlogged()); for (BlockFace face : previousData.getAllowedFaces()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index ea096a2e7..c108671b2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -94,21 +94,17 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner { return null; } - switch (id) { - case "CARGO_MANAGER": - return NetworkComponent.REGULATOR; - case "CARGO_NODE": - return NetworkComponent.CONNECTOR; - case "CARGO_NODE_INPUT": - case "CARGO_NODE_OUTPUT": - case "CARGO_NODE_OUTPUT_ADVANCED": - case "CT_IMPORT_BUS": - case "CT_EXPORT_BUS": - case "CHEST_TERMINAL": - return NetworkComponent.TERMINUS; - default: - return null; - } + return switch (id) { + case "CARGO_MANAGER" -> NetworkComponent.REGULATOR; + case "CARGO_NODE" -> NetworkComponent.CONNECTOR; + case "CARGO_NODE_INPUT", + "CARGO_NODE_OUTPUT", + "CARGO_NODE_OUTPUT_ADVANCED", + "CT_IMPORT_BUS", + "CT_EXPORT_BUS", + "CHEST_TERMINAL" -> NetworkComponent.TERMINUS; + default -> null; + }; } @Override @@ -123,15 +119,10 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner { if (to == NetworkComponent.TERMINUS) { String id = BlockStorage.checkID(l); switch (id) { - case "CARGO_NODE_INPUT": - inputNodes.add(l); - break; - case "CARGO_NODE_OUTPUT": - case "CARGO_NODE_OUTPUT_ADVANCED": - outputNodes.add(l); - break; - default: - break; + case "CARGO_NODE_INPUT" -> inputNodes.add(l); + case "CARGO_NODE_OUTPUT", + "CARGO_NODE_OUTPUT_ADVANCED" -> outputNodes.add(l); + default -> {} } } }