mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-02-11 03:29:53 +00:00
Fix fishing style in 1.12.2-
This commit is contained in:
parent
440c4621e9
commit
91697ee112
1 changed files with 19 additions and 5 deletions
|
@ -3,18 +3,30 @@ package dev.esophose.playerparticles.styles;
|
||||||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||||
import dev.esophose.playerparticles.particles.PParticle;
|
import dev.esophose.playerparticles.particles.PParticle;
|
||||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerFishEvent;
|
import org.bukkit.event.player.PlayerFishEvent;
|
||||||
|
|
||||||
public class ParticleStyleFishing extends DefaultParticleStyle implements Listener {
|
public class ParticleStyleFishing extends DefaultParticleStyle implements Listener {
|
||||||
|
|
||||||
private List<FishHook> 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<Projectile> projectiles;
|
||||||
|
|
||||||
public ParticleStyleFishing() {
|
public ParticleStyleFishing() {
|
||||||
super("fishing", false, false, 0);
|
super("fishing", false, false, 0);
|
||||||
|
@ -26,9 +38,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
|
||||||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||||
List<PParticle> particles = new ArrayList<>();
|
List<PParticle> particles = new ArrayList<>();
|
||||||
|
|
||||||
List<FishHook> listCopy = new ArrayList<>(this.projectiles); // Copy in case of modification while looping due to async
|
List<Projectile> listCopy = new ArrayList<>(this.projectiles); // Copy in case of modification while looping due to async
|
||||||
for (FishHook fishHook : listCopy)
|
for (Projectile projectile : listCopy)
|
||||||
particles.add(new PParticle(fishHook.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
|
particles.add(new PParticle(projectile.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
|
||||||
|
|
||||||
return particles;
|
return particles;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +68,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
|
||||||
// Done through a string switch for 1.9.4 compatibility
|
// Done through a string switch for 1.9.4 compatibility
|
||||||
switch (event.getState().toString()) {
|
switch (event.getState().toString()) {
|
||||||
case "FISHING":
|
case "FISHING":
|
||||||
this.projectiles.add(event.getHook());
|
try {
|
||||||
|
this.projectiles.add((Projectile) PlayerFishEvent_getHook.invoke(event));
|
||||||
|
} catch (ReflectiveOperationException ignored) { }
|
||||||
break;
|
break;
|
||||||
case "CAUGHT_FISH":
|
case "CAUGHT_FISH":
|
||||||
case "CAUGHT_ENTITY":
|
case "CAUGHT_ENTITY":
|
||||||
|
|
Loading…
Reference in a new issue