|
|
@ -8,6 +8,7 @@ import java.util.HashMap; |
|
|
|
|
|
|
|
import org.bukkit.Bukkit; |
|
|
|
import org.bukkit.Location; |
|
|
|
import org.bukkit.Particle; |
|
|
|
import org.bukkit.entity.Entity; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
|
|
|
@ -19,7 +20,6 @@ public class ParticleHandler { |
|
|
|
private static Method player_sendPacket = null; |
|
|
|
private static HashMap<Class<? extends Entity>, Method> handles = new HashMap<Class<? extends Entity>, Method>(); |
|
|
|
|
|
|
|
private static boolean newParticlePacketConstructor = false; |
|
|
|
private static Class<Enum> enumParticle = null; |
|
|
|
|
|
|
|
private ParticleType type; |
|
|
@ -27,8 +27,6 @@ public class ParticleHandler { |
|
|
|
private int count; |
|
|
|
private double radius; |
|
|
|
|
|
|
|
private static boolean compatible = true; |
|
|
|
|
|
|
|
public static void load() { |
|
|
|
String vString = getVersion().replace("v", ""); |
|
|
|
double v = 0; |
|
|
@ -37,25 +35,20 @@ public class ParticleHandler { |
|
|
|
v = Double.parseDouble(array[0] + "." + array[1]); |
|
|
|
} |
|
|
|
try { |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Hooking into Netty NMS classes"); |
|
|
|
packetClass = getNmsClass("PacketPlayOutWorldParticles"); |
|
|
|
if (v == 1.8 || v == 1.9 || v == 1.10 || v == 1.11 || v == 1.12) { |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Version is " + v + " - using old packet constructor"); |
|
|
|
if (v == 1.8) { |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Hooking into Netty NMS classes"); |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Version is " + v + " - using packet constructor"); |
|
|
|
enumParticle = (Class<Enum>) getNmsClass("EnumParticle"); |
|
|
|
packetConstructor = packetClass.getDeclaredConstructor(enumParticle, boolean.class, float.class, |
|
|
|
float.class, float.class, float.class, float.class, float.class, float.class, int.class, |
|
|
|
int[].class); |
|
|
|
} else { |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Version is " + v + " - using new packet constructor"); |
|
|
|
newParticlePacketConstructor = true; |
|
|
|
enumParticle = (Class<Enum>) getNmsClass("EnumParticle"); |
|
|
|
packetConstructor = packetClass.getDeclaredConstructor(enumParticle, boolean.class, float.class, |
|
|
|
float.class, float.class, float.class, float.class, float.class, float.class, int.class); |
|
|
|
Bukkit.getLogger().info("[ParticleHandler] Hooking into the new particle system"); |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
ex.printStackTrace(); |
|
|
|
Bukkit.getLogger().severe("[ParticleHandler] Failed to initialize NMS components!"); |
|
|
|
compatible = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -79,13 +72,25 @@ public class ParticleHandler { |
|
|
|
} |
|
|
|
|
|
|
|
public void sendToLocation(Location location) { |
|
|
|
try { |
|
|
|
Object packet = createPacket(location); |
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) { |
|
|
|
sendPacket(player, packet); |
|
|
|
String vString = getVersion().replace("v", ""); |
|
|
|
double v = 0; |
|
|
|
if (!vString.isEmpty()) { |
|
|
|
String[] array = vString.split("_"); |
|
|
|
v = Double.parseDouble(array[0] + "." + array[1]); |
|
|
|
} |
|
|
|
if (v == 1.8) { |
|
|
|
try { |
|
|
|
Object packet = createPacket(location); |
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) { |
|
|
|
sendPacket(player, packet); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} else { |
|
|
|
location.getWorld().spawnParticle(Particle.valueOf(type.getName().toUpperCase()), (float) location.getX(), |
|
|
|
(float) location.getY(), (float) location.getZ(), this.count, (float) this.radius, |
|
|
|
(float) this.radius, (float) this.radius, (float) this.speed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -95,17 +100,10 @@ public class ParticleHandler { |
|
|
|
this.count = 1; |
|
|
|
} |
|
|
|
Object packet; |
|
|
|
if (newParticlePacketConstructor) { |
|
|
|
Object particleType = enumParticle.getEnumConstants()[type.getId()]; |
|
|
|
packet = packetConstructor.newInstance(particleType, true, (float) location.getX(), |
|
|
|
(float) location.getY(), (float) location.getZ(), (float) this.radius, (float) this.radius, |
|
|
|
(float) this.radius, (float) this.speed, this.count); |
|
|
|
} else { |
|
|
|
Object particleType = enumParticle.getEnumConstants()[type.getId()]; |
|
|
|
packet = packetConstructor.newInstance(particleType, true, (float) location.getX(), |
|
|
|
(float) location.getY(), (float) location.getZ(), (float) this.radius, (float) this.radius, |
|
|
|
(float) this.radius, (float) this.speed, this.count, new int[0]); |
|
|
|
} |
|
|
|
Object particleType = enumParticle.getEnumConstants()[type.getId()]; |
|
|
|
packet = packetConstructor.newInstance(particleType, true, (float) location.getX(), (float) location.getY(), |
|
|
|
(float) location.getZ(), (float) this.radius, (float) this.radius, (float) this.radius, |
|
|
|
(float) this.speed, this.count, new int[0]); |
|
|
|
return packet; |
|
|
|
} catch (IllegalAccessException ex) { |
|
|
|
ex.printStackTrace(); |
|
|
@ -178,10 +176,6 @@ public class ParticleHandler { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
public static boolean isCompatible() { |
|
|
|
return compatible; |
|
|
|
} |
|
|
|
|
|
|
|
public enum ParticleType { |
|
|
|
|
|
|
|
EXPLOSION_NORMAL("explode", 0, 17), EXPLOSION_LARGE("largeexplode", 1, 1), |
|
|
|