diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java index 9472884e5..c8064299a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java @@ -61,9 +61,9 @@ public class PickaxeOfContainment extends SimpleSlimefunItem { private @Nonnull ItemStack breakSpawner(@Nonnull Block b) { AbstractMonsterSpawner spawner; - /** - * If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner - * and should not give a broken spawner but a repaired one instead. + /* + If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner + and should not give a broken spawner but a repaired one instead. */ if (BlockStorage.hasBlockInfo(b)) { spawner = (AbstractMonsterSpawner) SlimefunItems.REPAIRED_SPAWNER.getItem(); @@ -73,8 +73,8 @@ public class PickaxeOfContainment extends SimpleSlimefunItem { BlockState state = PaperLib.getBlockState(b, false).getState(); - if (state instanceof CreatureSpawner) { - EntityType entityType = ((CreatureSpawner) state).getSpawnedType(); + if (state instanceof CreatureSpawner creatureSpawner) { + EntityType entityType = creatureSpawner.getSpawnedType(); return spawner.getItemForEntityType(entityType); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java index 7baab167a..474a7277d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java @@ -36,16 +36,14 @@ public class IcyBow extends SlimefunBow { @Override public BowShootHandler onShoot() { return (e, n) -> { - if (n instanceof Player) { - Player p = (Player) n; - + if (n instanceof Player player) { // Fixes #3060 - Don't apply effects if the arrow was successfully blocked. - if (p.isBlocking() && e.getFinalDamage() <= 0) { + if (player.isBlocking() && e.getFinalDamage() <= 0) { return; } if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) { - p.setFreezeTicks(60); + player.setFreezeTicks(60); } } n.getWorld().playEffect(n.getLocation(), Effect.STEP_SOUND, Material.ICE); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java index f9dd81f85..0c15115e2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java @@ -92,7 +92,7 @@ public class AutoCrafterListener implements Listener { @ParametersAreNonnullByDefault private boolean hasUnlockedRecipe(Player p, ItemStack item) { for (Recipe recipe : Slimefun.getMinecraftRecipeService().getRecipesFor(item)) { - if (recipe instanceof Keyed && !p.hasDiscoveredRecipe(((Keyed) recipe).getKey())) { + if (recipe instanceof Keyed keyed && !p.hasDiscoveredRecipe(keyed.getKey())) { return false; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java index a3ff32e05..796f6917b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java @@ -94,12 +94,12 @@ public class BackpackListener implements Listener { if (item != null) { SlimefunItem backpack = SlimefunItem.getByItem(item); - if (backpack instanceof SlimefunBackpack) { + if (backpack instanceof SlimefunBackpack slimefunBackpack) { if (e.getClick() == ClickType.NUMBER_KEY) { if (e.getClickedInventory().getType() != InventoryType.PLAYER) { ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); - if (!isAllowed((SlimefunBackpack) backpack, hotbarItem)) { + if (!isAllowed(slimefunBackpack, hotbarItem)) { e.setCancelled(true); } } @@ -107,10 +107,10 @@ public class BackpackListener implements Listener { // Fixes #3265 ItemStack offHandItem = e.getWhoClicked().getInventory().getItemInOffHand(); - if (!isAllowed((SlimefunBackpack) backpack, offHandItem)) { + if (!isAllowed(slimefunBackpack, offHandItem)) { e.setCancelled(true); } - } else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) { + } else if (!isAllowed(slimefunBackpack, e.getCurrentItem())) { e.setCancelled(true); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ButcherAndroidListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ButcherAndroidListener.java index 46f540f17..1432edd1d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ButcherAndroidListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ButcherAndroidListener.java @@ -49,8 +49,8 @@ public class ButcherAndroidListener implements Listener { // Collect any nearby dropped items for (Entity n : e.getEntity().getNearbyEntities(0.5D, 0.5D, 0.5D)) { - if (n instanceof Item && n.isValid() && !SlimefunUtils.hasNoPickupFlag((Item) n)) { - items.add(((Item) n).getItemStack()); + if (n instanceof Item item && n.isValid() && !SlimefunUtils.hasNoPickupFlag(item)) { + items.add(item.getItemStack()); n.remove(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java index 35bab4d40..4b818a4d2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CoolerListener.java @@ -49,19 +49,17 @@ public class CoolerListener implements Listener { @EventHandler public void onHungerLoss(FoodLevelChangeEvent e) { - if (e.getEntity() instanceof Player) { - Player p = (Player) e.getEntity(); - - if (e.getFoodLevel() < p.getFoodLevel()) { - checkAndConsume(p); + if (e.getEntity() instanceof Player player) { + if (e.getFoodLevel() < player.getFoodLevel()) { + checkAndConsume(player); } } } @EventHandler public void onHungerDamage(EntityDamageEvent e) { - if (e.getEntity() instanceof Player && e.getCause() == DamageCause.STARVATION) { - checkAndConsume((Player) e.getEntity()); + if (e.getEntity() instanceof Player player && e.getCause() == DamageCause.STARVATION) { + checkAndConsume(player); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java index e4d4a7ac3..00dcacf06 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java @@ -168,8 +168,7 @@ public class DebugFishListener implements Listener { p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + Slimefun.getProfiler().getTime(b.getChunk()))); } - if (item instanceof EnergyNetComponent) { - EnergyNetComponent component = (EnergyNetComponent) item; + if (item instanceof EnergyNetComponent component) { p.sendMessage(ChatColors.color("&dEnergyNet Component")); p.sendMessage(ChatColors.color(" &dType: &e" + component.getEnergyComponentType())); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java index cbcdf7eed..34851c679 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java @@ -46,8 +46,7 @@ public class DispenserListener implements Listener { machine.callItemHandler(BlockDispenseHandler.class, handler -> { BlockState state = PaperLib.getBlockState(b, false).getState(); - if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser) state; + if (state instanceof Dispenser dispenser) { BlockFace face = ((Directional) b.getBlockData()).getFacing(); Block block = b.getRelative(face); handler.onBlockDispense(e, dispenser, block, machine); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraImpactListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraImpactListener.java index cf99c9d0e..d01a4596b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraImpactListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraImpactListener.java @@ -60,8 +60,8 @@ public class ElytraImpactListener implements Listener { e.setDamage(0); p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1); - if (item instanceof DamageableItem) { - ((DamageableItem) item).damageItem(p, p.getInventory().getHelmet()); + if (item instanceof DamageableItem damageableItem) { + damageableItem.damageItem(p, p.getInventory().getHelmet()); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GadgetsListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GadgetsListener.java index 9c5c0f323..7f5048f83 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GadgetsListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GadgetsListener.java @@ -70,8 +70,8 @@ public class GadgetsListener implements Listener { return; } - if (chestplate instanceof Jetpack) { - double thrust = ((Jetpack) chestplate).getThrust(); + if (chestplate instanceof Jetpack jetpack) { + double thrust = jetpack.getThrust(); if (thrust > 0.2) { new JetpackTask(p, (Jetpack) chestplate).scheduleRepeating(0, 3); @@ -82,8 +82,8 @@ public class GadgetsListener implements Listener { } private void handleBoots(@Nonnull Player p, @Nullable SlimefunItem boots) { - if (boots instanceof JetBoots && boots.canUse(p, true)) { - double speed = ((JetBoots) boots).getSpeed(); + if (boots instanceof JetBoots jetBoots && boots.canUse(p, true)) { + double speed = jetBoots.getSpeed(); if (speed > 0.2) { new JetBootsTask(p, (JetBoots) boots).scheduleRepeating(0, 2); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java index b9b69ff0a..fe57d8197 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java @@ -61,8 +61,8 @@ public class GrapplingHookListener implements Listener { return; } - if (e.getDamager() instanceof Arrow) { - handleGrapplingHook((Arrow) e.getDamager()); + if (e.getDamager() instanceof Arrow arrow) { + handleGrapplingHook(arrow); } } @@ -73,8 +73,8 @@ public class GrapplingHookListener implements Listener { } Slimefun.runSync(() -> { - if (e.getEntity() instanceof Arrow) { - handleGrapplingHook((Arrow) e.getEntity()); + if (e.getEntity() instanceof Arrow arrow) { + handleGrapplingHook(arrow); } }, 2L); } @@ -86,8 +86,8 @@ public class GrapplingHookListener implements Listener { } // This is called when the arrow shoots off a painting or an item frame - if (e.getRemover() instanceof Arrow) { - handleGrapplingHook((Arrow) e.getRemover()); + if (e.getRemover() instanceof Arrow arrow) { + handleGrapplingHook(arrow); } } @@ -130,8 +130,8 @@ public class GrapplingHookListener implements Listener { return; } - if (e.getEntity() instanceof Arrow) { - handleGrapplingHook((Arrow) e.getEntity()); + if (e.getEntity() instanceof Arrow arrow) { + handleGrapplingHook(arrow); } } @@ -153,9 +153,8 @@ public class GrapplingHookListener implements Listener { } private void handleGrapplingHook(@Nullable Arrow arrow) { - if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) { - Player p = (Player) arrow.getShooter(); - GrapplingHookEntity hook = activeHooks.get(p.getUniqueId()); + if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player player) { + GrapplingHookEntity hook = activeHooks.get(player.getUniqueId()); if (hook != null) { Location target = arrow.getLocation(); @@ -163,14 +162,14 @@ public class GrapplingHookListener implements Listener { Vector velocity = new Vector(0.0, 0.2, 0.0); - if (p.getLocation().distance(target) < 3.0) { - if (target.getY() <= p.getLocation().getY()) { - velocity = target.toVector().subtract(p.getLocation().toVector()); + if (player.getLocation().distance(target) < 3.0) { + if (target.getY() <= player.getLocation().getY()) { + velocity = target.toVector().subtract(player.getLocation().toVector()); } } else { - Location l = p.getLocation(); + Location l = player.getLocation(); l.setY(l.getY() + 0.5); - p.teleport(l); + player.teleport(l); double g = -0.08; double d = target.distance(l); @@ -179,16 +178,16 @@ public class GrapplingHookListener implements Listener { double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t; double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t; - velocity = p.getVelocity(); + velocity = player.getVelocity(); velocity.setX(vX); velocity.setY(vY); velocity.setZ(vZ); } - p.setVelocity(velocity); + player.setVelocity(velocity); hook.remove(); - Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L); + Slimefun.runSync(() -> activeHooks.remove(player.getUniqueId()), 20L); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBootsListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBootsListener.java index 0962dab1e..ceb532b39 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBootsListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBootsListener.java @@ -68,9 +68,9 @@ public class SlimefunBootsListener implements Listener { return; } - if (boots instanceof StomperBoots) { + if (boots instanceof StomperBoots stomperBoots) { e.setCancelled(true); - ((StomperBoots) boots).stomp(e); + stomperBoots.stomp(e); } else if (boots instanceof LongFallBoots) { e.setCancelled(true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java index 5e4a7bd27..286bd2c2e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java @@ -55,8 +55,8 @@ public class SlimefunBowListener implements Listener { if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) { SlimefunItem bow = SlimefunItem.getByItem(e.getBow()); - if (bow instanceof SlimefunBow) { - projectiles.put(e.getProjectile().getUniqueId(), (SlimefunBow) bow); + if (bow instanceof SlimefunBow slimefunBow) { + projectiles.put(e.getProjectile().getUniqueId(), slimefunBow); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java index 5bfca5a24..0a720585e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java @@ -99,8 +99,8 @@ public class TalismanListener implements Listener { Talisman.trigger(e, SlimefunItems.TALISMAN_WARRIOR); break; case PROJECTILE: - if (e instanceof EntityDamageByEntityEvent) { - onProjectileDamage((EntityDamageByEntityEvent) e); + if (e instanceof EntityDamageByEntityEvent entityDamageByEntityEvent) { + onProjectileDamage(entityDamageByEntityEvent); } break; default: @@ -111,9 +111,7 @@ public class TalismanListener implements Listener { private void onProjectileDamage(@Nonnull EntityDamageByEntityEvent e) { // "Fixes" #1022 - We just ignore Tridents now. - if (e.getDamager() instanceof Projectile && !(e.getDamager() instanceof Trident)) { - Projectile projectile = (Projectile) e.getDamager(); - + if (e.getDamager() instanceof Projectile projectile && !(e.getDamager() instanceof Trident)) { if (Talisman.trigger(e, SlimefunItems.TALISMAN_WHIRLWIND)) { Player p = (Player) e.getEntity(); returnProjectile(p, projectile); @@ -138,8 +136,7 @@ public class TalismanListener implements Listener { returnedProjectile.setShooter(projectile.getShooter()); returnedProjectile.setVelocity(direction); - if (projectile instanceof AbstractArrow) { - AbstractArrow firedArrow = (AbstractArrow) projectile; + if (projectile instanceof AbstractArrow firedArrow) { AbstractArrow returnedArrow = (AbstractArrow) returnedProjectile; returnedArrow.setDamage(firedArrow.getDamage()); @@ -188,14 +185,12 @@ public class TalismanListener implements Listener { List items = new ArrayList<>(drops); // Prevent duplication of items stored inside a Horse's chest - if (entity instanceof ChestedHorse) { - ChestedHorse horse = (ChestedHorse) entity; - - if (horse.isCarryingChest()) { + if (entity instanceof ChestedHorse chestedHorse) { + if (chestedHorse.isCarryingChest()) { // The chest is not included in getStorageContents() items.remove(new ItemStack(Material.CHEST)); - for (ItemStack item : horse.getInventory().getStorageContents()) { + for (ItemStack item : chestedHorse.getInventory().getStorageContents()) { items.remove(item); } } @@ -252,8 +247,8 @@ public class TalismanListener implements Listener { ItemStack item = e.getBrokenItem().clone(); ItemMeta meta = item.getItemMeta(); - if (meta instanceof Damageable) { - ((Damageable) meta).setDamage(0); + if (meta instanceof Damageable damageable) { + damageable.setDamage(0); } item.setItemMeta(meta); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java index 6d09fbef7..a6807f1ed 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java @@ -64,7 +64,7 @@ public class TeleporterListener implements Listener { // Pressure plate was an elevator ElevatorPlate elevator = SlimefunItems.ELEVATOR_PLATE.getItem(ElevatorPlate.class); elevator.openInterface(p, b); - } else if (item instanceof AbstractTeleporterPlate && ((AbstractTeleporterPlate) item).hasAccess(p, b)) { + } else if (item instanceof AbstractTeleporterPlate abstractTeleporterPlate && abstractTeleporterPlate.hasAccess(p, b)) { // Pressure plate was a teleporter SlimefunItem teleporter = BlockStorage.check(b.getRelative(BlockFace.DOWN)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/AnvilListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/AnvilListener.java index 535ba45ef..3059b17c8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/AnvilListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/AnvilListener.java @@ -34,7 +34,7 @@ public class AnvilListener implements SlimefunCraftingListener { if (hasUnallowedItems(item1, item2)) { e.setResult(Result.DENY); - Slimefun.getLocalization().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true); + Slimefun.getLocalization().sendMessage(e.getWhoClicked(), "anvil.not-working", true); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/CartographyTableListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/CartographyTableListener.java index 5db7fcfb9..d1cb56ace 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/CartographyTableListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/CartographyTableListener.java @@ -34,7 +34,7 @@ public class CartographyTableListener implements SlimefunCraftingListener { if (hasUnallowedItems(item1, item2)) { e.setResult(Result.DENY); - Slimefun.getLocalization().sendMessage((Player) e.getWhoClicked(), "cartography_table.not-working", true); + Slimefun.getLocalization().sendMessage(e.getWhoClicked(), "cartography_table.not-working", true); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/FireworksListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/FireworksListener.java index d2fc17b79..66f7291b0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/FireworksListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/FireworksListener.java @@ -28,15 +28,14 @@ public class FireworksListener implements Listener { @EventHandler public void onResearchFireworkDamage(EntityDamageByEntityEvent e) { - if (e.getDamager() instanceof Firework) { - Firework firework = (Firework) e.getDamager(); + if (e.getDamager() instanceof Firework firework) { FireworkMeta meta = firework.getFireworkMeta(); - /** - * We could use Peristent Data for this in the future, but ItemMeta display names - * work pretty reliably too and they don't cause any memory leaks like metadata. - * - * Entity display names do not work either as Firework cannot be named. + /* + We could use Peristent Data for this in the future, but ItemMeta display names + work pretty reliably too and they don't cause any memory leaks like metadata. + + Entity display names do not work either as Firework cannot be named. */ if (meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.GREEN + "Slimefun Research")) { e.setCancelled(true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/MobDropListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/MobDropListener.java index 77e2e267e..7d69ffc90 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/MobDropListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/MobDropListener.java @@ -67,16 +67,16 @@ public class MobDropListener implements Listener { if (sfItem == null) { return true; } else if (sfItem.canUse(p, true)) { - if (sfItem instanceof RandomMobDrop) { + if (sfItem instanceof RandomMobDrop randomMobDrop) { int random = ThreadLocalRandom.current().nextInt(100); - if (((RandomMobDrop) sfItem).getMobDropChance() <= random) { + if (randomMobDrop.getMobDropChance() <= random) { return false; } } - if (sfItem instanceof BasicCircuitBoard) { - return ((BasicCircuitBoard) sfItem).isDroppedFromGolems(); + if (sfItem instanceof BasicCircuitBoard basicCircuitBoard) { + return basicCircuitBoard.isDroppedFromGolems(); } return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/PiglinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/PiglinListener.java index fa996e0d0..bb153b299 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/PiglinListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/PiglinListener.java @@ -90,8 +90,8 @@ public class PiglinListener implements Listener { SlimefunItem sfi = SlimefunItem.getByItem(is); // Check the getBarteringLootChance and compare against a random number 0-100, // if the random number is greater then replace the item. - if (sfi instanceof PiglinBarterDrop) { - int chance = ((PiglinBarterDrop) sfi).getBarteringLootChance(); + if (sfi instanceof PiglinBarterDrop piglinBarterDrop) { + int chance = piglinBarterDrop.getBarteringLootChance(); if (chance < 1 || chance >= 100) { sfi.warn("The Piglin Bartering chance must be between 1-99% on item: " + sfi.getId()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/WitherListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/WitherListener.java index 4bb5a2b65..2cad17a85 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/WitherListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/entity/WitherListener.java @@ -36,9 +36,9 @@ public class WitherListener implements Listener { SlimefunItem item = BlockStorage.check(e.getBlock()); // Hardened Glass is excluded from here - if (item instanceof WitherProof && !item.getId().equals(SlimefunItems.HARDENED_GLASS.getItemId())) { + if (item instanceof WitherProof witherProof && !item.getId().equals(SlimefunItems.HARDENED_GLASS.getItemId())) { e.setCancelled(true); - ((WitherProof) item).onAttack(e.getBlock(), (Wither) e.getEntity()); + witherProof.onAttack(e.getBlock(), (Wither) e.getEntity()); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index 1a0567d3a..13e7e7ef5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -193,9 +193,7 @@ public final class PostSetup { } for (SlimefunItem item : Slimefun.getRegistry().getEnabledSlimefunItems()) { - if (item instanceof AContainer) { - AContainer machine = (AContainer) item; - + if (item instanceof AContainer machine) { if (machine.getMachineIdentifier().equals("ELECTRIC_SMELTERY")) { List recipes = machine.getMachineRecipes(); Collections.sort(recipes, Comparator.comparingInt(recipe -> recipe == null ? 0 : -recipe.getInput().length)); @@ -233,12 +231,8 @@ public final class PostSetup { private static void registerMachineRecipe(String machine, int seconds, ItemStack[] input, ItemStack[] output) { for (SlimefunItem item : Slimefun.getRegistry().getEnabledSlimefunItems()) { - if (item instanceof AContainer) { - AContainer container = (AContainer) item; - - if (container.getMachineIdentifier().equals(machine)) { - container.registerRecipe(seconds, input, output); - } + if (item instanceof AContainer container && container.getMachineIdentifier().equals(machine)) { + container.registerRecipe(seconds, input, output); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index 253d4800a..fb686422e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -137,8 +137,8 @@ public class ArmorTask implements Runnable { SlimefunItem item = SlimefunItem.getByItem(helmet); - if (item instanceof SolarHelmet && item.canUse(p, true)) { - ((SolarHelmet) item).rechargeItems(p); + if (item instanceof SolarHelmet solarHelmet && item.canUse(p, true)) { + solarHelmet.rechargeItems(p); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/InfusedMagnetTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/InfusedMagnetTask.java index f9aed1f42..f89f70807 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/InfusedMagnetTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/InfusedMagnetTask.java @@ -48,9 +48,7 @@ public class InfusedMagnetTask extends AbstractPlayerTask { boolean playSound = false; for (Entity n : p.getNearbyEntities(radius, radius, radius)) { - if (n instanceof Item) { - Item item = (Item) n; - + if (n instanceof Item item) { if (!SlimefunUtils.hasNoPickupFlag(item) && item.getPickupDelay() <= 0 && p.getLocation().distanceSquared(item.getLocation()) > 0.3) { item.teleport(p.getLocation()); playSound = true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java index 8502733ab..bd9da15a1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java @@ -41,7 +41,7 @@ class ClearLagIntegration implements Listener { while (iterator.hasNext()) { Entity n = iterator.next(); - if (n instanceof Item && SlimefunUtils.hasNoPickupFlag((Item) n)) { + if (n instanceof Item item && SlimefunUtils.hasNoPickupFlag(item)) { iterator.remove(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java index c00c18db4..826fb1e4b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java @@ -82,8 +82,8 @@ class PlaceholderAPIIntegration extends PlaceholderExpansion { if (profile.isPresent()) { Stream stream = profile.get().getResearches().stream(); return String.valueOf(stream.mapToInt(Research::getCost).sum()); - } else if (p instanceof Player) { - return getProfilePlaceholder((Player) p); + } else if (p instanceof Player player) { + return getProfilePlaceholder(player); } } @@ -93,8 +93,8 @@ class PlaceholderAPIIntegration extends PlaceholderExpansion { if (profile.isPresent()) { Set set = profile.get().getResearches(); return String.valueOf(set.size()); - } else if (p instanceof Player) { - return getProfilePlaceholder((Player) p); + } else if (p instanceof Player player) { + return getProfilePlaceholder(player); } } @@ -108,8 +108,8 @@ class PlaceholderAPIIntegration extends PlaceholderExpansion { if (profile.isPresent()) { Set set = profile.get().getResearches(); return String.valueOf(Math.round(((set.size() * 100.0F) / Slimefun.getRegistry().getResearches().size()) * 100.0F) / 100.0F); - } else if (p instanceof Player) { - return getProfilePlaceholder((Player) p); + } else if (p instanceof Player player) { + return getProfilePlaceholder(player); } } @@ -118,8 +118,8 @@ class PlaceholderAPIIntegration extends PlaceholderExpansion { if (profile.isPresent()) { return profile.get().getTitle(); - } else if (p instanceof Player) { - return getProfilePlaceholder((Player) p); + } else if (p instanceof Player player) { + return getProfilePlaceholder(player); } } @@ -131,8 +131,7 @@ class PlaceholderAPIIntegration extends PlaceholderExpansion { return Slimefun.getProfiler().getTime(); } - if (isPlaceholder(p, false, params, "language") && p instanceof Player) { - Player player = (Player) p; + if (isPlaceholder(p, false, params, "language") && p instanceof Player player) { return Slimefun.getLocalization().getLanguage(player).getName(player); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java index f6ba0924e..a15fdad7f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java @@ -132,8 +132,8 @@ public final class ItemStackWrapper extends ItemStack { public static @Nonnull ItemStackWrapper wrap(@Nonnull ItemStack itemStack) { Validate.notNull(itemStack, "The ItemStack cannot be null!"); - if (itemStack instanceof ItemStackWrapper) { - return (ItemStackWrapper) itemStack; + if (itemStack instanceof ItemStackWrapper itemStackWrapper) { + return itemStackWrapper; } return new ItemStackWrapper(itemStack); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java index 570beacb1..fe8901812 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java @@ -106,7 +106,7 @@ public class TagParser implements Keyed { JsonArray values = child.getAsJsonArray(); for (JsonElement element : values) { - if (element instanceof JsonPrimitive && ((JsonPrimitive) element).isString()) { + if (element instanceof JsonPrimitive jsonPrimitive && jsonPrimitive.isString()) { // Strings will be parsed directly parsePrimitiveValue(element.getAsString(), materials, tags, true); } else if (element instanceof JsonObject) { @@ -182,7 +182,7 @@ public class TagParser implements Keyed { JsonElement required = entry.get("required"); // Check if the entry contains elements of the correct type - if (id instanceof JsonPrimitive && ((JsonPrimitive) id).isString() && required instanceof JsonPrimitive && ((JsonPrimitive) required).isBoolean()) { + if (id instanceof JsonPrimitive idJson && idJson.isString() && required instanceof JsonPrimitive requiredJson && requiredJson.isBoolean()) { boolean isRequired = required.getAsBoolean(); /* diff --git a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/MenuListener.java b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/MenuListener.java index 3483e5a6e..5822b8701 100644 --- a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/MenuListener.java +++ b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/MenuListener.java @@ -50,8 +50,8 @@ public class MenuListener implements Listener { if (handler == null) { e.setCancelled(!menu.isEmptySlotsClickable() && (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)); - } else if (handler instanceof AdvancedMenuClickHandler) { - e.setCancelled(!((AdvancedMenuClickHandler) handler).onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e.isRightClick(), e.isShiftClick()))); + } else if (handler instanceof AdvancedMenuClickHandler advancedMenuClickHandler) { + e.setCancelled(!advancedMenuClickHandler.onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e.isRightClick(), e.isShiftClick()))); } else { e.setCancelled(!handler.onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick()))); } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java index df6b7097a..1ef479341 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java @@ -233,8 +233,7 @@ public abstract class BlockMenuPreset extends ChestMenu { menu.addItem(size - 1, null); } - if (menu instanceof BlockMenu) { - BlockMenu blockMenu = (BlockMenu) menu; + if (menu instanceof BlockMenu blockMenu) { newInstance(blockMenu, blockMenu.getLocation()); }