diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index fafef5e8..10877034 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -78,13 +78,11 @@ public class ItemFun extends FreedomService @EventHandler public void onPlayerEntityInteract(PlayerInteractEntityEvent event) { - if (plugin.sh == null) return; // This is to prevent an NPE if the Shoppe isn't present. - Player player = event.getPlayer(); Entity entity = event.getRightClicked(); FPlayer fPlayer = plugin.pl.getPlayer(player); - if (player.getInventory().getItemInMainHand().getType().equals(Material.POTATO) || entity.getType().equals(EntityType.PLAYER)) + if (plugin.sh != null && player.getInventory().getItemInMainHand().getType().equals(Material.POTATO)) { if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.STACKING_POTATO, player.getInventory(), plugin.sh.getStackingPotato())) { @@ -126,13 +124,13 @@ public class ItemFun extends FreedomService Entity entity = event.getEntity(); - if (entity instanceof Player || !(event.getDamager() instanceof Player)) + // Why the fuck do we have 3 if checks in a row that do the exact same damn thing? Couldn't this be condensed into a single if check?! + + if (entity instanceof Player || !(event.getDamager() instanceof Player player)) { return; } - Player player = (Player) event.getDamager(); - if (!player.getInventory().getItemInMainHand().getType().equals(Material.POTATO)) { return; @@ -150,8 +148,6 @@ public class ItemFun extends FreedomService @EventHandler public void onPlayerInteractEvent(PlayerInteractEvent event) { - if (plugin.sh == null) return; // This is to prevent an NPE if the Shoppe isn't present. - if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { @@ -182,6 +178,8 @@ public class ItemFun extends FreedomService } case BLAZE_ROD -> { + if (plugin.sh == null) return; // This is to prevent an NPE if the Shoppe isn't present. + if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.LIGHTNING_ROD, player.getInventory(), plugin.sh.getLightningRod())) { break; @@ -204,6 +202,8 @@ public class ItemFun extends FreedomService } case FIRE_CHARGE -> { + if (plugin.sh == null) return; // This is to prevent an NPE if the Shoppe isn't present. + if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.FIRE_BALL, player.getInventory(), plugin.sh.getFireBall())) { break; @@ -223,6 +223,8 @@ public class ItemFun extends FreedomService } case TROPICAL_FISH -> { + if (plugin.sh == null) return; // This is to prevent an NPE if the Shoppe isn't present. + final int RADIUS_HIT = 5; final int STRENGTH = 4; @@ -269,14 +271,9 @@ public class ItemFun extends FreedomService if (didHit) { - final Sound[] sounds = Sound.values(); - for (Sound sound : sounds) - { - if (sound.toString().contains("HIT")) - { - Objects.requireNonNull(playerLoc.getWorld()).playSound(randomOffset(playerLoc), sound, 20f, randomDoubleRange(0.5, 2.0).floatValue()); - } - } + Arrays.stream(Sound.values()).filter(sound -> sound.toString().contains("HIT")).forEach(sound -> + Objects.requireNonNull(playerLoc.getWorld()).playSound(randomOffset(playerLoc), sound, + SoundCategory.PLAYERS, 20f, randomDoubleRange(0.5, 2.0).floatValue())); cooldown(player, ShopItem.CLOWN_FISH, 30); } } @@ -293,13 +290,10 @@ public class ItemFun extends FreedomService if (plugin.sh == null) return; Projectile entity = event.getEntity(); - if (entity instanceof EnderPearl && entity.getShooter() instanceof Player) + if (entity instanceof EnderPearl && entity.getShooter() instanceof Player player + && plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.RIDEABLE_PEARL, player.getInventory(), plugin.sh.getRideablePearl())) { - Player player = (Player) entity.getShooter(); - if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.RIDEABLE_PEARL, player.getInventory(), plugin.sh.getRideablePearl())) - { - entity.addPassenger(player); - } + entity.addPassenger(player); } } @@ -356,9 +350,6 @@ public class ItemFun extends FreedomService if (plugin.sh == null) return; Player player = event.getPlayer(); - PlayerData data = plugin.pl.getData(player); - PlayerInventory inv = event.getPlayer().getInventory(); - ItemStack rod = inv.getItemInMainHand(); if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.GRAPPLING_HOOK, player.getInventory(), plugin.sh.getGrapplingHook())) { if (event.getState() == PlayerFishEvent.State.REEL_IN || event.getState() == PlayerFishEvent.State.IN_GROUND) @@ -383,32 +374,40 @@ public class ItemFun extends FreedomService if (orientation >= 0.0 && orientation < 22.5) { zVel = speed; - } else if (orientation >= 22.5 && orientation < 67.5) + } + else if (orientation >= 22.5 && orientation < 67.5) { xVel = -(speed / 2.0); zVel = speed / 2.0; - } else if (orientation >= 67.5 && orientation < 112.5) + } + else if (orientation >= 67.5 && orientation < 112.5) { xVel = -speed; - } else if (orientation >= 112.5 && orientation < 157.5) + } + else if (orientation >= 112.5 && orientation < 157.5) { xVel = -(speed / 2.0); zVel = -(speed / 2.0); - } else if (orientation >= 157.5 && orientation < 202.5) + } + else if (orientation >= 157.5 && orientation < 202.5) { zVel = -speed; - } else if (orientation >= 202.5 && orientation < 247.5) + } + else if (orientation >= 202.5 && orientation < 247.5) { xVel = speed / 2.0; zVel = -(speed / 2.0); - } else if (orientation >= 247.5 && orientation < 292.5) + } + else if (orientation >= 247.5 && orientation < 292.5) { xVel = speed; - } else if (orientation >= 292.5 && orientation < 337.5) + } + else if (orientation >= 292.5 && orientation < 337.5) { xVel = speed / 2.0; zVel = speed / 2.0; - } else if (orientation >= 337.5 && orientation < 360.0) + } + else if (orientation >= 337.5 && orientation < 360.0) { zVel = speed; } @@ -418,7 +417,8 @@ public class ItemFun extends FreedomService if (event.getState() == PlayerFishEvent.State.FISHING) { orientationTracker.put(player, player.getLocation().getYaw()); - } else + } + else { orientationTracker.remove(player); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index fbe39168..65dd8c02 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -11,6 +11,7 @@ import me.totalfreedom.totalfreedommod.api.ShopItem; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player;