diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 55e048735..29dd89602 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -70,21 +70,19 @@ final class CargoUtils { Material type = block.getType(); - switch (type) { - case CHEST: - case TRAPPED_CHEST: - case FURNACE: - case DISPENSER: - case DROPPER: - case HOPPER: - case BREWING_STAND: - case BARREL: - case BLAST_FURNACE: - case SMOKER: - return true; - default: - return SlimefunTag.SHULKER_BOXES.isTagged(type); - } + return switch (type) { + case CHEST, + TRAPPED_CHEST, + FURNACE, + DISPENSER, + DROPPER, + HOPPER, + BREWING_STAND, + BARREL, + BLAST_FURNACE, + SMOKER -> true; + default -> SlimefunTag.SHULKER_BOXES.isTagged(type); + }; } @Nonnull @@ -145,8 +143,8 @@ final class CargoUtils { BlockState state = PaperLib.getBlockState(target, false).getState(); - if (state instanceof InventoryHolder) { - inventory = ((InventoryHolder) state).getInventory(); + if (state instanceof InventoryHolder inventoryHolder) { + inventory = inventoryHolder.getInventory(); inventories.put(target.getLocation(), inventory); return withdrawFromVanillaInventory(network, node, template, inventory); } @@ -230,8 +228,8 @@ final class CargoUtils { BlockState state = PaperLib.getBlockState(target, false).getState(); - if (state instanceof InventoryHolder) { - inventory = ((InventoryHolder) state).getInventory(); + if (state instanceof InventoryHolder inventoryHolder) { + inventory = inventoryHolder.getInventory(); inventories.put(target.getLocation(), inventory); return withdrawFromVanillaInventory(network, node, inventory); } @@ -278,8 +276,8 @@ final class CargoUtils { BlockState state = PaperLib.getBlockState(target, false).getState(); - if (state instanceof InventoryHolder) { - inventory = ((InventoryHolder) state).getInventory(); + if (state instanceof InventoryHolder inventoryHolder) { + inventory = inventoryHolder.getInventory(); inventories.put(target.getLocation(), inventory); return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index f29e85583..32bd4136d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -75,16 +75,13 @@ public class EnergyNet extends Network implements HologramOwner { if (component == null) { return null; } else { - switch (component.getEnergyComponentType()) { - case CONNECTOR: - case CAPACITOR: - return NetworkComponent.CONNECTOR; - case CONSUMER: - case GENERATOR: - return NetworkComponent.TERMINUS; - default: - return null; - } + return switch (component.getEnergyComponentType()) { + case CONNECTOR, + CAPACITOR -> NetworkComponent.CONNECTOR; + case CONSUMER, + GENERATOR -> NetworkComponent.TERMINUS; + default -> null; + }; } } @@ -106,10 +103,10 @@ public class EnergyNet extends Network implements HologramOwner { consumers.put(l, component); break; case GENERATOR: - if (component instanceof EnergyNetProvider) { - generators.put(l, (EnergyNetProvider) component); - } else if (component instanceof SlimefunItem) { - ((SlimefunItem) component).warn("This Item is marked as a GENERATOR but does not implement the interface EnergyNetProvider!"); + if (component instanceof EnergyNetProvider energyNetProvider) { + generators.put(l, energyNetProvider); + } else if (component instanceof SlimefunItem slimefunItem) { + slimefunItem.warn("This Item is marked as a GENERATOR but does not implement the interface EnergyNetProvider!"); } break; default: @@ -275,8 +272,8 @@ public class EnergyNet extends Network implements HologramOwner { private static EnergyNetComponent getComponent(@Nonnull Location l) { SlimefunItem item = BlockStorage.check(l); - if (item instanceof EnergyNetComponent) { - return ((EnergyNetComponent) item); + if (item instanceof EnergyNetComponent energyNetComponent) { + return energyNetComponent; } return null; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java index 2d952c642..216302973 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java @@ -72,9 +72,9 @@ public class BlockDataService implements Keyed { */ BlockState state = b.getState(); - if (state instanceof TileState) { + if (state instanceof TileState tileState) { try { - PersistentDataContainer container = ((TileState) state).getPersistentDataContainer(); + PersistentDataContainer container = tileState.getPersistentDataContainer(); container.set(namespacedKey, PersistentDataType.STRING, value); state.update(); } catch (Exception x) { @@ -111,8 +111,8 @@ public class BlockDataService implements Keyed { @Nullable private PersistentDataContainer getPersistentDataContainer(@Nonnull BlockState state) { - if (state instanceof TileState) { - return ((TileState) state).getPersistentDataContainer(); + if (state instanceof TileState tileState) { + return tileState.getPersistentDataContainer(); } else { return null; } @@ -137,31 +137,31 @@ public class BlockDataService implements Keyed { return false; } - switch (type) { - case PLAYER_HEAD: - case PLAYER_WALL_HEAD: - case CHEST: - case DISPENSER: - case BREWING_STAND: - case DROPPER: - case FURNACE: - case BLAST_FURNACE: - case HOPPER: - case LECTERN: - case JUKEBOX: - case ENDER_CHEST: - case ENCHANTING_TABLE: - case DAYLIGHT_DETECTOR: - case SMOKER: - case BARREL: - case SPAWNER: - case BEACON: + return switch (type) { + case PLAYER_HEAD, + PLAYER_WALL_HEAD, + CHEST, + DISPENSER, + BREWING_STAND, + DROPPER, + FURNACE, + BLAST_FURNACE, + HOPPER, + LECTERN, + JUKEBOX, + ENDER_CHEST, + ENCHANTING_TABLE, + DAYLIGHT_DETECTOR, + SMOKER, + BARREL, + SPAWNER, + BEACON -> // All of the above Materials are Tile Entities - return true; - default: + true; + default -> // Otherwise we assume they're not Tile Entities - return false; - } + false; + }; } } \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java index fb3647285..37a45e431 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java @@ -82,7 +82,7 @@ class GitHubTask implements Runnable { } for (GitHubConnector connector : gitHubService.getConnectors()) { - if (connector instanceof ContributionsConnector && !((ContributionsConnector) connector).hasFinished()) { + if (connector instanceof ContributionsConnector contributionsConnector && !contributionsConnector.hasFinished()) { return; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java index 3804d5b00..b69e71d53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java @@ -62,9 +62,9 @@ class Hologram { ArmorStand getArmorStand() { Entity n = Bukkit.getEntity(uniqueId); - if (n instanceof ArmorStand && n.isValid()) { + if (n instanceof ArmorStand armorStand && n.isValid()) { this.lastAccess = System.currentTimeMillis(); - return (ArmorStand) n; + return armorStand; } else { this.lastAccess = 0; return null; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java index 6241737a5..2673dd9b9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java @@ -191,11 +191,9 @@ public class HologramsService { * @return Whether this could be a hologram */ private boolean isHologram(@Nonnull Entity n) { - if (n instanceof ArmorStand) { - ArmorStand armorstand = (ArmorStand) n; - + if (n instanceof ArmorStand armorStand) { // The absolute minimum requirements to count as a hologram - return !armorstand.isVisible() && armorstand.isSilent() && !armorstand.hasGravity(); + return !armorStand.isVisible() && armorStand.isSilent() && !armorStand.hasGravity(); } else { return false; } @@ -216,22 +214,20 @@ public class HologramsService { */ @Nullable private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity entity, @Nonnull PersistentDataContainer container) { - if (entity instanceof ArmorStand) { - ArmorStand armorstand = (ArmorStand) entity; - - armorstand.setVisible(false); - armorstand.setInvulnerable(true); - armorstand.setSilent(true); - armorstand.setMarker(true); - armorstand.setAI(false); - armorstand.setGravity(false); - armorstand.setRemoveWhenFarAway(false); + if (entity instanceof ArmorStand armorStand) { + armorStand.setVisible(false); + armorStand.setInvulnerable(true); + armorStand.setSilent(true); + armorStand.setMarker(true); + armorStand.setAI(false); + armorStand.setGravity(false); + armorStand.setRemoveWhenFarAway(false); // Set a persistent tag to re-identify the correct hologram later container.set(persistentDataKey, PersistentDataType.LONG, position.getPosition()); // Store in cache for faster access - Hologram hologram = new Hologram(armorstand.getUniqueId()); + Hologram hologram = new Hologram(armorStand.getUniqueId()); cache.put(position, hologram); return hologram; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java index 185d803e2..893e3baf2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java @@ -348,8 +348,8 @@ public abstract class SlimefunLocalization implements Keyed { String prefix = addPrefix ? getChatPrefix() : ""; - if (recipient instanceof Player) { - recipient.sendMessage(ChatColors.color(prefix + getMessage((Player) recipient, key))); + if (recipient instanceof Player player) { + recipient.sendMessage(ChatColors.color(prefix + getMessage(player, key))); } else { recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key)))); } @@ -383,8 +383,8 @@ public abstract class SlimefunLocalization implements Keyed { String prefix = addPrefix ? getChatPrefix() : ""; - if (recipient instanceof Player) { - recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) recipient, key)))); + if (recipient instanceof Player player) { + recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage(player, key)))); } else { recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key))))); } @@ -393,8 +393,8 @@ public abstract class SlimefunLocalization implements Keyed { public void sendMessages(@Nonnull CommandSender recipient, @Nonnull String key) { String prefix = getChatPrefix(); - if (recipient instanceof Player) { - for (String translation : getMessages((Player) recipient, key)) { + if (recipient instanceof Player player) { + for (String translation : getMessages(player, key)) { String message = ChatColors.color(prefix + translation); recipient.sendMessage(message); } @@ -410,8 +410,8 @@ public abstract class SlimefunLocalization implements Keyed { public void sendMessages(CommandSender recipient, String key, boolean addPrefix, UnaryOperator function) { String prefix = addPrefix ? getChatPrefix() : ""; - if (recipient instanceof Player) { - for (String translation : getMessages((Player) recipient, key)) { + if (recipient instanceof Player player) { + for (String translation : getMessages(player, key)) { String message = ChatColors.color(prefix + function.apply(translation)); recipient.sendMessage(message); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java index d34265914..5883ef445 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -95,9 +95,9 @@ class PerformanceSummary { List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); String prefix = count + " " + name + (count != 1 ? 's' : ""); - if (inspector instanceof PlayerPerformanceInspector) { + if (inspector instanceof PlayerPerformanceInspector playerPerformanceInspector) { TextComponent component = summarizeAsTextComponent(count, prefix, results, formatter); - ((PlayerPerformanceInspector) inspector).sendMessage(component); + playerPerformanceInspector.sendMessage(component); } else { String text = summarizeAsString(inspector, count, prefix, results, formatter); inspector.sendMessage(text);