From 2e7756ed0f1a1f0d7fcb812803146a5174fd7ae2 Mon Sep 17 00:00:00 2001 From: Video Date: Sat, 11 Mar 2023 00:55:02 -0700 Subject: [PATCH] [COMMONS] Bugfixes, cleanup, and a much-needed clownfish tweak - Fixes bug that caused non-shop items (like the mob tosser) to not work if the Shop plugin is not already installed - Finally makes the fucking clownfish something that can be turned down in the sound settings by having it play the sound at the Player sound category --- .../totalfreedommod/fun/ItemFun.java | 68 +++++++++---------- .../totalfreedommod/fun/Trailer.java | 1 + 2 files changed, 35 insertions(+), 34 deletions(-) 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;