diff --git a/src/main/java/dev/esophose/playerparticles/styles/ParticleStyleFishing.java b/src/main/java/dev/esophose/playerparticles/styles/ParticleStyleFishing.java index 71f405d..37a3957 100644 --- a/src/main/java/dev/esophose/playerparticles/styles/ParticleStyleFishing.java +++ b/src/main/java/dev/esophose/playerparticles/styles/ParticleStyleFishing.java @@ -3,18 +3,30 @@ package dev.esophose.playerparticles.styles; import dev.esophose.playerparticles.config.CommentedFileConfiguration; import dev.esophose.playerparticles.particles.PParticle; import dev.esophose.playerparticles.particles.ParticlePair; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.bukkit.Location; import org.bukkit.entity.FishHook; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; public class ParticleStyleFishing extends DefaultParticleStyle implements Listener { - private List projectiles; + // I hate legacy versions. The Spigot API changed the PlayerFishEvent#getHook method from returning a Fish to a FishHook in 1.13 + private static Method PlayerFishEvent_getHook; + static { + try { + PlayerFishEvent_getHook = PlayerFishEvent.class.getDeclaredMethod("getHook"); + } catch (ReflectiveOperationException ex) { + ex.printStackTrace(); + } + } + + private List projectiles; public ParticleStyleFishing() { super("fishing", false, false, 0); @@ -26,9 +38,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen public List getParticles(ParticlePair particle, Location location) { List particles = new ArrayList<>(); - List listCopy = new ArrayList<>(this.projectiles); // Copy in case of modification while looping due to async - for (FishHook fishHook : listCopy) - particles.add(new PParticle(fishHook.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F)); + List listCopy = new ArrayList<>(this.projectiles); // Copy in case of modification while looping due to async + for (Projectile projectile : listCopy) + particles.add(new PParticle(projectile.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F)); return particles; } @@ -56,7 +68,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen // Done through a string switch for 1.9.4 compatibility switch (event.getState().toString()) { case "FISHING": - this.projectiles.add(event.getHook()); + try { + this.projectiles.add((Projectile) PlayerFishEvent_getHook.invoke(event)); + } catch (ReflectiveOperationException ignored) { } break; case "CAUGHT_FISH": case "CAUGHT_ENTITY":