Particles not show and error in Console

Discussion in 'Spigot Plugin Development' started by SwissiMusic, Jun 28, 2016.

  1. Hi,

    I have trouble with my Plugin... i want update PlayEffect for 1.9 to use in my World of Warcraft Plugin.
    but... not work!
    Here the problem code:
    Code (Text):
    Vec3D = Class.forName(nmsPrefix + "Vec3D");
                    newVec3D = Vec3D.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE});
                    Packet = Class.forName(nmsPrefix + "Packet");
                    StringBuilder stringBuilder = new StringBuilder(String.valueOf(nmsPrefix));
                    String str = (version.startsWith("v1_6") || version.startsWith("v1_5")) ? "Packet60Explosion" : "PacketPlayOutExplosion";
                    Packet60Explosion = Class.forName(stringBuilder.append(str).toString());
                    CraftServer = Class.forName(obcPrefix + "CraftServer");
                    CraftWorld = Class.forName(obcPrefix + "CraftWorld");
                    DedicatedPlayerList = Class.forName(nmsPrefix + "DedicatedPlayerList");
                    WorldServer = Class.forName(nmsPrefix + "WorldServer");
                    getHandleCS = CraftServer.getMethod("getHandle", new Class[0]);
                    sendPacketNearby = DedicatedPlayerList.getMethod("sendPacketNearby", new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Integer.TYPE, Packet});
                    getHandleCW = CraftWorld.getMethod("getHandle", new Class[0]);
                    dimensionField = WorldServer.getField("dimension");
                    newPacket = Packet60Explosion.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, List.class, Vec3D});
                    PacketPlayOutWorldParticles = Class.forName(nmsPrefix + "PacketPlayOutWorldParticles");
                    world_getHandle = CraftWorld.getMethod("getHandle", new Class[0]);
                    CraftFirework = Class.forName(obcPrefix + "entity.CraftFirework");
                    firework_getHandle = CraftFirework.getMethod("getHandle", new Class[0]);
                    EntityFireworks = Class.forName(nmsPrefix + "EntityFireworks");
                    expectedLifespan = EntityFireworks.getField("expectedLifespan");
                    ticksFlown = EntityFireworks.getDeclaredField("ticksFlown");
                    ticksFlown.setAccessible(true);
                    NmsWorld = Class.forName(nmsPrefix + "World");
                    NmsEntity = Class.forName(nmsPrefix + "Entity");
                    broadcastEntityEffect = NmsWorld.getMethod("broadcastEntityEffect", new Class[]{NmsEntity, Byte.TYPE});
                    EnumParticle = Class.forName(nmsPrefix + "EnumParticle");
                    fillParticles();
                    disabled = false;
    sendPacketNearby not work... and i dont know the new class for 1.9 :(
    Error:
    Code (Text):
    [18:43:50] [Server thread/INFO]: [PlayEffect] Enabling PlayEffect v0.4.2
    [18:43:50] [Server thread/INFO]: [PlayEffect] Warning! PlayEffect was not tested with server version:1.9.4-R0.1-SNAPSHOT
    [18:43:50] [Server thread/INFO]: [PlayEffect] Check updates at http://dev.bukkit.org/bukkit-plugins/playeffect/
    [18:43:50] [Server thread/INFO]: [PlayEffect] or use this version at your own risk.
    [18:43:50] [Server thread/INFO]: [PlayEffect] net.minecraft.server.v1_9_R2.DedicatedPlayerList.sendPacketNearby(double, double, double, double, int, net.minecraft.server.v1_9_R2.Packet)
    [18:43:50] [Server thread/INFO]: [PlayEffect] Warning! PacketNMS library is not compatible with git-Spigot-798f32d-0cd0397 (MC: 1.9.4)
    [18:43:50] [Server thread/INFO]: [PlayEffect] Check updates of PlayEffect at http://dev.bukkit.org/bukkit-plugins/playeffect/
    [18:43:50] [Server thread/INFO]: [PlayEffect] or use this version at your own risk.
    [18:43:50] [Server thread/INFO]: [PlayEffect] Error message:
    [18:43:50] [Server thread/WARN]: java.lang.NoSuchMethodException: net.minecraft.server.v1_9_R2.DedicatedPlayerList.sendPacketNearby(double, double, double, double, int, net.minecraft.server.v1_9_R2.Packet)
    [18:43:50] [Server thread/WARN]:     at java.lang.Class.getMethod(Class.java:1786)
    [18:43:50] [Server thread/WARN]:     at me.fromgate.playeffect.customeffects.PacketNMS.init(PacketNMS.java:100)
    [18:43:50] [Server thread/WARN]:     at me.fromgate.playeffect.PlayEffect.onEnable(PlayEffect.java:62)
    [18:43:50] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292)
    [18:43:50] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    [18:43:50] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [18:43:50] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin(CraftServer.java:362)
    [18:43:50] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins(CraftServer.java:322)
    [18:43:50] [Server thread/WARN]:     at net.minecraft.server.v1_9_R2.MinecraftServer.t(MinecraftServer.java:416)
    [18:43:50] [Server thread/WARN]:     at net.minecraft.server.v1_9_R2.MinecraftServer.l(MinecraftServer.java:381)
    [18:43:50] [Server thread/WARN]:     at net.minecraft.server.v1_9_R2.MinecraftServer.a(MinecraftServer.java:336)
    [18:43:50] [Server thread/WARN]:     at net.minecraft.server.v1_9_R2.DedicatedServer.init(DedicatedServer.java:268)
    [18:43:50] [Server thread/WARN]:     at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:532)
    [18:43:50] [Server thread/WARN]:     at java.lang.Thread.run(Thread.java:745)
    What is wrong on my code? I have no idea with packets... :(
     
  2. The method you're using was removed on 1.9. It used to call the method below with null as argument for the entity. Simply adjust your code to call it directly.
    [​IMG]
     
  3. i dont know to use this code.... for what is d{numbers}?
    Not work for me....

    Code (Text):
    package ch.swissi.brandnetz.particle.customeffects;

    import java.lang.reflect.Constructor;
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.FireworkEffect;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.meta.FireworkMeta;

    import ch.swissi.brandnetz.particle.PlayEffect;
    import ch.swissi.brandnetz.particle.VisualEffect;
    import net.minecraft.server.v1_9_R2.EntityHuman;
    import net.minecraft.server.v1_9_R2.EntityPlayer;

    public class PacketNMS {
        private static Class<?> CraftFirework;
        private static Class<?> CraftServer;
        private static Class<?> CraftWorld;
        private static Class<?> DedicatedPlayerList;
        private static Class<?> EntityFireworks;
        private static Class<?> EnumParticle;
        private static Class<?> NmsEntity;
        private static Class<?> NmsWorld;
        private static Class<?> Packet;
        private static Class<?> Packet60Explosion;
        private static Class<?> PacketPlayOutWorldParticles;
        private static Class<?> Vec3D;
        private static Class<?> WorldServer;
        private static boolean activated;
        private static Method broadcastEntityEffect;
        private static Field dimensionField;
        private static boolean disabled;
        private static Method enumParticle_name;
        private static Map<VisualEffect, Object> enumParticles;
        private static Field expectedLifespan;
        private static Method firework_getHandle;
        private static Method getHandleCS;
        private static Method getHandleCW;
        private static Constructor<?> newPacket;
        private static Constructor<?> newVec3D;
        private static String nmsPrefix;
        private static String obcPrefix;
        private static Method sendPacketNearby;
        private static String[] tested_versions;
        private static Field ticksFlown;
        private static String version;
        private static Method world_getHandle;

        private static PlayEffect plg() {
            return PlayEffect.instance;
        }

        static {
            tested_versions = new String[]{"v1_8_R1", "v1_8_R2"};
            disabled = true;
            activated = false;
            obcPrefix = "org.bukkit.craftbukkit.";
            nmsPrefix = "net.minecraft.server.";
            version = "";
        }

        public static void init() {
            if (!activated) {
                String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
                if (v.length == 4) {
                    version = v[3];
                    obcPrefix = "org.bukkit.craftbukkit." + version + ".";
                    nmsPrefix = "net.minecraft.server." + version + ".";
                }
                isTestedInform();
                try {
                    Vec3D = Class.forName(nmsPrefix + "Vec3D");
                    newVec3D = Vec3D.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE});
                    Packet = Class.forName(nmsPrefix + "Packet");
                    StringBuilder stringBuilder = new StringBuilder(String.valueOf(nmsPrefix));
                    String str = (version.startsWith("v1_6") || version.startsWith("v1_5")) ? "Packet60Explosion" : "PacketPlayOutExplosion";
                    Packet60Explosion = Class.forName(stringBuilder.append(str).toString());
                    CraftServer = Class.forName(obcPrefix + "CraftServer");
                    CraftWorld = Class.forName(obcPrefix + "CraftWorld");
                    DedicatedPlayerList = Class.forName(nmsPrefix + "DedicatedPlayerList");
                    WorldServer = Class.forName(nmsPrefix + "WorldServer");
                    getHandleCS = CraftServer.getMethod("getHandle", new Class[0]);
                    sendPacketNearby = DedicatedPlayerList.getMethod("sendPacketNearby", new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Integer.TYPE, Packet});
                    getHandleCW = CraftWorld.getMethod("getHandle", new Class[0]);
                    dimensionField = WorldServer.getField("dimension");
                    newPacket = Packet60Explosion.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, List.class, Vec3D});
                    PacketPlayOutWorldParticles = Class.forName(nmsPrefix + "PacketPlayOutWorldParticles");
                    world_getHandle = CraftWorld.getMethod("getHandle", new Class[0]);
                    CraftFirework = Class.forName(obcPrefix + "entity.CraftFirework");
                    firework_getHandle = CraftFirework.getMethod("getHandle", new Class[0]);
                    EntityFireworks = Class.forName(nmsPrefix + "EntityFireworks");
                    expectedLifespan = EntityFireworks.getField("expectedLifespan");
                    ticksFlown = EntityFireworks.getDeclaredField("ticksFlown");
                    ticksFlown.setAccessible(true);
                    NmsWorld = Class.forName(nmsPrefix + "World");
                    NmsEntity = Class.forName(nmsPrefix + "Entity");
                    broadcastEntityEffect = NmsWorld.getMethod("broadcastEntityEffect", new Class[]{NmsEntity, Byte.TYPE});
                    EnumParticle = Class.forName(nmsPrefix + "EnumParticle");
                    fillParticles();
                    disabled = false;
                } catch (Exception e) {
                   
                    e.printStackTrace();
                    disabled = true;
                }
                activated = true;
            }
        }

        public static boolean isTestedVersion() {
            for (String equalsIgnoreCase : tested_versions) {
                if (equalsIgnoreCase.equalsIgnoreCase(version)) {
                    return true;
                }
            }
            return false;
        }

        public static String getVersion() {
            return version;
        }

        public static void isTestedInform() {
            if (!isTestedVersion()) {
            }
        }

        public static boolean isDisabled() {
            return disabled;
        }

        public static void sendExplosionPacket(Location loc, float size) {
            if (!disabled) {
                try {
                    Object v = newVec3D.newInstance(new Object[]{Double.valueOf(0.0d), Double.valueOf(0.0d), Double.valueOf(0.0d)});
                    Object handleCraftServer = getHandleCS.invoke(Bukkit.getServer(), new Object[0]);
                    int dimension = dimensionField.getInt(getHandleCW.invoke(loc.getWorld(), new Object[0]));
                    Object packet = newPacket.newInstance(new Object[]{Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Float.valueOf(size), new ArrayList(), v});
                    sendPacketNearby.invoke(handleCraftServer, new Object[]{Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Integer.valueOf(64), Integer.valueOf(dimension), packet});
                } catch (Exception e) {
                    disabled = true;
                    e.printStackTrace();
                    //log("Failed to create explosion effect.");
                    e.printStackTrace();
                }
            }
        }

        private static void fillParticles() {
            enumParticles = new HashMap();
            for (VisualEffect ve : VisualEffect.values()) {
                for (Object obj : EnumParticle.getEnumConstants()) {
                    String name = null;
                    try {
                        enumParticle_name = obj.getClass().getMethod("name", new Class[0]);
                        name = (String) enumParticle_name.invoke(obj, new Object[0]);
                    } catch (Exception e) {
                    }
                    if (name != null && name.equalsIgnoreCase(ve.name())) {
                        enumParticles.put(ve, obj);
                    }
                }
            }
        }

        private static Object getEnumParticle(VisualEffect effect) {
            if (!disabled && enumParticles.containsKey(effect)) {
                return enumParticles.get(effect);
            }
            return null;
        }

        public static void sendParticlesPacket(VisualEffect effect, Location loc, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount) {
            Object enumParticle = getEnumParticle(effect);
            if (enumParticle != null && loc != null) {
                int[] extra = new int[0];
                if (id > 0) {
                    extra = effect == VisualEffect.ITEM_CRACK ? new int[]{id, data} : new int[]{(data << 12) | (id & 4095)};
                }
                try {
                    Object sPacket = PacketPlayOutWorldParticles.newInstance();
                    for (Field f : PacketPlayOutWorldParticles.getDeclaredFields()) {
                        f.setAccessible(true);
                        String fld = f.getName();
                        if (fld.equals("a")) {
                            f.set(sPacket, enumParticle);
                        }
                        if (fld.equals("j")) {
                            f.set(sPacket, Boolean.valueOf(true));
                        }
                        if (fld.equals("b")) {
                            f.set(sPacket, Float.valueOf((float) loc.getX()));
                        }
                        if (fld.equals("c")) {
                            f.set(sPacket, Float.valueOf((float) loc.getY()));
                        }
                        if (fld.equals("d")) {
                            f.set(sPacket, Float.valueOf((float) loc.getZ()));
                        }
                        if (fld.equals("e")) {
                            f.set(sPacket, Float.valueOf(offsetX));
                        }
                        if (fld.equals("f")) {
                            f.set(sPacket, Float.valueOf(offsetY));
                        }
                        if (fld.equals("g")) {
                            f.set(sPacket, Float.valueOf(offsetZ));
                        }
                        if (fld.equals("h")) {
                            f.set(sPacket, Float.valueOf(speed));
                        }
                        if (fld.equals("i")) {
                            f.set(sPacket, Integer.valueOf(particleCount));
                        }
                        if (fld.equals("k")) {
                            f.set(sPacket, extra);
                        }
                    }
                    Player p = Bukkit.getServer().getPlayer("BNLynxion");
                    players.add(p);
                    Object handleCraftServer = getHandleCS.invoke(Bukkit.getServer(), new Object[0]);
                    int dimension = dimensionField.getInt(getHandleCW.invoke(loc.getWorld(), new Object[0]));
                    sendPacketNearby(null, Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Integer.valueOf(64), Integer.valueOf(dimension), (net.minecraft.server.v1_9_R2.Packet<?>) sPacket);
                } catch (Exception e) {
                    e.printStackTrace();
                    disabled = true;
                    //log("Failed to create particles effect.");
                }
            }
        }

        public static void playFirework164(World world, Location loc, FireworkEffect fe) {
            if (!disabled) {
                try {
                    Firework fw = world.spawn(loc, Firework.class);
                    Object nms_world = world_getHandle.invoke(world, new Object[0]);
                    Object nms_firework = firework_getHandle.invoke(fw, new Object[0]);
                    FireworkMeta data = fw.getFireworkMeta();
                    data.clearEffects();
                    data.setPower(1);
                    data.addEffect(fe);
                    fw.setFireworkMeta(data);
                    broadcastEntityEffect.invoke(nms_world, new Object[]{nms_firework, Byte.valueOf((byte) 17)});
                    fw.remove();
                } catch (Exception e) {
                    disabled = true;
                    //log("Failed to create firework effect.");
                }
            }
        }
       
        static ArrayList<Player> players = new ArrayList<Player>();
       
        public static void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, net.minecraft.server.v1_9_R2.Packet<?> packet){
            for (int j = 0; j < players.size(); j++){
                EntityPlayer entityplayer = (EntityPlayer)players.get(j);
                System.out.println(entityplayer.getHealth());
                if ((entityhuman == null) || (!(entityhuman instanceof EntityPlayer)) || (entityplayer.getBukkitEntity().canSee(((EntityPlayer)entityplayer).getBukkitEntity()))){
                    if ((entityplayer != entityhuman) && (entityplayer.dimension == 1)){
                        double d4 = d0 - entityplayer.locX;
                        double d5 = d1 - entityplayer.locY;
                        double d6 = d2 - entityplayer.locZ;
                        if (d4 * d4 + d5 * d5 + d6 * d6 < d3 * d3){
                            entityplayer.playerConnection.sendPacket(packet);
                        }
                    }
                }
            }
        }

        public static void playFirework172(World world, Location loc, FireworkEffect fe) {
            if (!disabled) {
                Firework fw = world.spawn(loc, Firework.class);
                FireworkMeta data = fw.getFireworkMeta();
                data.clearEffects();
                data.setPower(0);
                data.addEffect(fe);
                fw.setFireworkMeta(data);
                try {
                    Object nms_firework = firework_getHandle.invoke(fw, new Object[0]);
                    expectedLifespan.set(nms_firework, Integer.valueOf(1));
                    ticksFlown.set(nms_firework, Integer.valueOf(1));
                } catch (Exception e) {
                    disabled = true;
                    //log("Failed to create firework effect.");
                }
            }
        }
    }
     
     
    #3 SwissiMusic, Jun 28, 2016
    Last edited: Jun 28, 2016
  4. The first 3 values represent the position where the effect will be displayed and the last one is the radius.
     
  5. Okey.... but i can not send packet... in my code is packet a Object?
    I have tested on my dev server and send no System.out.println(entityplayer.getHealth()); or error and i can't see the particles

    :( I'm totally noob on packets sent programming
     
  6. I really don't understand what you're doing. You initially got errors, now they're gone. Have you changed anything on the code? Tested with another version?
     
  7. The code works but the packet has errors or is not send to players...
    This code is from Play Effect Plugin

    EDIT://This is my first time by packets in my Plugin or my recode plugin
     
  8. Then give us everything. All the logs and errors you came across, all the code you have tested and changed. Give us detailed information.
     
  9. Ok here is the class that not work: PacketNMS.class
    Code (Text):
    package ch.swissi.brandnetz.particle.customeffects;

    import java.lang.reflect.Constructor;
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.FireworkEffect;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.meta.FireworkMeta;

    import ch.swissi.brandnetz.particle.PlayEffect;
    import ch.swissi.brandnetz.particle.VisualEffect;
    import net.minecraft.server.v1_9_R2.EntityHuman;
    import net.minecraft.server.v1_9_R2.EntityPlayer;

    public class PacketNMS {
        private static Class<?> CraftFirework;
        private static Class<?> CraftServer;
        private static Class<?> CraftWorld;
        private static Class<?> DedicatedPlayerList;
        private static Class<?> EntityFireworks;
        private static Class<?> EnumParticle;
        private static Class<?> NmsEntity;
        private static Class<?> NmsWorld;
        private static Class<?> Packet;
        private static Class<?> Packet60Explosion;
        private static Class<?> PacketPlayOutWorldParticles;
        private static Class<?> Vec3D;
        private static Class<?> WorldServer;
        private static boolean activated;
        private static Method broadcastEntityEffect;
        private static Field dimensionField;
        private static boolean disabled;
        private static Method enumParticle_name;
        private static Map<VisualEffect, Object> enumParticles;
        private static Field expectedLifespan;
        private static Method firework_getHandle;
        private static Method getHandleCS;
        private static Method getHandleCW;
        private static Constructor<?> newPacket;
        private static Constructor<?> newVec3D;
        private static String nmsPrefix;
        private static String obcPrefix;
        private static Method sendPacketNearby;
        private static String[] tested_versions;
        private static Field ticksFlown;
        private static String version;
        private static Method world_getHandle;

        private static PlayEffect plg() {
            return PlayEffect.instance;
        }

        static {
            tested_versions = new String[]{"v1_8_R1", "v1_8_R2"};
            disabled = true;
            activated = false;
            obcPrefix = "org.bukkit.craftbukkit.";
            nmsPrefix = "net.minecraft.server.";
            version = "";
        }

        public static void init() {
            if (!activated) {
                String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
                if (v.length == 4) {
                    version = v[3];
                    obcPrefix = "org.bukkit.craftbukkit." + version + ".";
                    nmsPrefix = "net.minecraft.server." + version + ".";
                }
                isTestedInform();
                try {
                    Vec3D = Class.forName(nmsPrefix + "Vec3D");
                    newVec3D = Vec3D.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE});
                    Packet = Class.forName(nmsPrefix + "Packet");
                    StringBuilder stringBuilder = new StringBuilder(String.valueOf(nmsPrefix));
                    String str = (version.startsWith("v1_6") || version.startsWith("v1_5")) ? "Packet60Explosion" : "PacketPlayOutExplosion";
                    Packet60Explosion = Class.forName(stringBuilder.append(str).toString());
                    CraftServer = Class.forName(obcPrefix + "CraftServer");
                    CraftWorld = Class.forName(obcPrefix + "CraftWorld");
                    DedicatedPlayerList = Class.forName(nmsPrefix + "DedicatedPlayerList");
                    WorldServer = Class.forName(nmsPrefix + "WorldServer");
                    getHandleCS = CraftServer.getMethod("getHandle", new Class[0]);
                    sendPacketNearby = DedicatedPlayerList.getMethod("sendPacketNearby", new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Integer.TYPE, Packet});
                    getHandleCW = CraftWorld.getMethod("getHandle", new Class[0]);
                    dimensionField = WorldServer.getField("dimension");
                    newPacket = Packet60Explosion.getConstructor(new Class[]{Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, List.class, Vec3D});
                    PacketPlayOutWorldParticles = Class.forName(nmsPrefix + "PacketPlayOutWorldParticles");
                    world_getHandle = CraftWorld.getMethod("getHandle", new Class[0]);
                    CraftFirework = Class.forName(obcPrefix + "entity.CraftFirework");
                    firework_getHandle = CraftFirework.getMethod("getHandle", new Class[0]);
                    EntityFireworks = Class.forName(nmsPrefix + "EntityFireworks");
                    expectedLifespan = EntityFireworks.getField("expectedLifespan");
                    ticksFlown = EntityFireworks.getDeclaredField("ticksFlown");
                    ticksFlown.setAccessible(true);
                    NmsWorld = Class.forName(nmsPrefix + "World");
                    NmsEntity = Class.forName(nmsPrefix + "Entity");
                    broadcastEntityEffect = NmsWorld.getMethod("broadcastEntityEffect", new Class[]{NmsEntity, Byte.TYPE});
                    EnumParticle = Class.forName(nmsPrefix + "EnumParticle");
                    fillParticles();
                    disabled = false;
                } catch (Exception e) {
                   
                    e.printStackTrace();
                    disabled = true;
                }
                activated = true;
            }
        }

        public static boolean isTestedVersion() {
            for (String equalsIgnoreCase : tested_versions) {
                if (equalsIgnoreCase.equalsIgnoreCase(version)) {
                    return true;
                }
            }
            return false;
        }

        public static String getVersion() {
            return version;
        }

        public static void isTestedInform() {
            if (!isTestedVersion()) {
            }
        }

        public static boolean isDisabled() {
            return disabled;
        }

        public static void sendExplosionPacket(Location loc, float size) {
            if (!disabled) {
                try {
                    Object v = newVec3D.newInstance(new Object[]{Double.valueOf(0.0d), Double.valueOf(0.0d), Double.valueOf(0.0d)});
                    Object handleCraftServer = getHandleCS.invoke(Bukkit.getServer(), new Object[0]);
                    int dimension = dimensionField.getInt(getHandleCW.invoke(loc.getWorld(), new Object[0]));
                    Object packet = newPacket.newInstance(new Object[]{Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Float.valueOf(size), new ArrayList(), v});
                    sendPacketNearby.invoke(handleCraftServer, new Object[]{Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Integer.valueOf(64), Integer.valueOf(dimension), packet});
                } catch (Exception e) {
                    disabled = true;
                    e.printStackTrace();
                    //log("Failed to create explosion effect.");
                    e.printStackTrace();
                }
            }
        }

        private static void fillParticles() {
            enumParticles = new HashMap();
            for (VisualEffect ve : VisualEffect.values()) {
                for (Object obj : EnumParticle.getEnumConstants()) {
                    String name = null;
                    try {
                        enumParticle_name = obj.getClass().getMethod("name", new Class[0]);
                        name = (String) enumParticle_name.invoke(obj, new Object[0]);
                    } catch (Exception e) {
                    }
                    if (name != null && name.equalsIgnoreCase(ve.name())) {
                        enumParticles.put(ve, obj);
                    }
                }
            }
        }

        private static Object getEnumParticle(VisualEffect effect) {
            if (!disabled && enumParticles.containsKey(effect)) {
                return enumParticles.get(effect);
            }
            return null;
        }

        public static void sendParticlesPacket(VisualEffect effect, Location loc, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount) {
            Object enumParticle = getEnumParticle(effect);
            if (enumParticle != null && loc != null) {
                int[] extra = new int[0];
                if (id > 0) {
                    extra = effect == VisualEffect.ITEM_CRACK ? new int[]{id, data} : new int[]{(data << 12) | (id & 4095)};
                }
                try {
                    Object sPacket = PacketPlayOutWorldParticles.newInstance();
                    for (Field f : PacketPlayOutWorldParticles.getDeclaredFields()) {
                        f.setAccessible(true);
                        String fld = f.getName();
                        if (fld.equals("a")) {
                            f.set(sPacket, enumParticle);
                        }
                        if (fld.equals("j")) {
                            f.set(sPacket, Boolean.valueOf(true));
                        }
                        if (fld.equals("b")) {
                            f.set(sPacket, Float.valueOf((float) loc.getX()));
                        }
                        if (fld.equals("c")) {
                            f.set(sPacket, Float.valueOf((float) loc.getY()));
                        }
                        if (fld.equals("d")) {
                            f.set(sPacket, Float.valueOf((float) loc.getZ()));
                        }
                        if (fld.equals("e")) {
                            f.set(sPacket, Float.valueOf(offsetX));
                        }
                        if (fld.equals("f")) {
                            f.set(sPacket, Float.valueOf(offsetY));
                        }
                        if (fld.equals("g")) {
                            f.set(sPacket, Float.valueOf(offsetZ));
                        }
                        if (fld.equals("h")) {
                            f.set(sPacket, Float.valueOf(speed));
                        }
                        if (fld.equals("i")) {
                            f.set(sPacket, Integer.valueOf(particleCount));
                        }
                        if (fld.equals("k")) {
                            f.set(sPacket, extra);
                        }
                    }
                    World world = Bukkit.getWorld("world");
                    for(int i = 0; i < world.getEntities().size(); i++)
                    {
                        EntityPlayer playerMP = (EntityPlayer) world.getEntities().get(i);
                        players.add(playerMP);
                    }
                    Object handleCraftServer = getHandleCS.invoke(Bukkit.getServer(), new Object[0]);
                    int dimension = dimensionField.getInt(getHandleCW.invoke(loc.getWorld(), new Object[0]));
                    sendPacketNearby(null, Double.valueOf(loc.getX()), Double.valueOf(loc.getY()), Double.valueOf(loc.getZ()), Integer.valueOf(64), Integer.valueOf(dimension), (net.minecraft.server.v1_9_R2.Packet<?>) sPacket);
                } catch (Exception e) {
                    e.printStackTrace();
                    disabled = true;
                    //log("Failed to create particles effect.");
                }
            }
        }

        public static void playFirework164(World world, Location loc, FireworkEffect fe) {
            if (!disabled) {
                try {
                    Firework fw = world.spawn(loc, Firework.class);
                    Object nms_world = world_getHandle.invoke(world, new Object[0]);
                    Object nms_firework = firework_getHandle.invoke(fw, new Object[0]);
                    FireworkMeta data = fw.getFireworkMeta();
                    data.clearEffects();
                    data.setPower(1);
                    data.addEffect(fe);
                    fw.setFireworkMeta(data);
                    broadcastEntityEffect.invoke(nms_world, new Object[]{nms_firework, Byte.valueOf((byte) 17)});
                    fw.remove();
                } catch (Exception e) {
                    disabled = true;
                    //log("Failed to create firework effect.");
                }
            }
        }
       
        static ArrayList<EntityPlayer> players = new ArrayList<EntityPlayer>();
       
        public static void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, net.minecraft.server.v1_9_R2.Packet<?> packet){
            for (int j = 0; j < players.size(); j++){
                EntityPlayer entityplayer = (EntityPlayer)players.get(j);
                System.out.println(entityplayer.getHealth());
                if ((entityhuman == null) || (!(entityhuman instanceof EntityPlayer)) || (entityplayer.getBukkitEntity().canSee(((EntityPlayer)entityplayer).getBukkitEntity()))){
                    if ((entityplayer != entityhuman) && (entityplayer.dimension == 1)){
                        double d4 = d0 - entityplayer.locX;
                        double d5 = d1 - entityplayer.locY;
                        double d6 = d2 - entityplayer.locZ;
                        if (d4 * d4 + d5 * d5 + d6 * d6 < d3 * d3){
                            entityplayer.playerConnection.sendPacket(packet);
                        }
                    }
                }
            }
        }

        public static void playFirework172(World world, Location loc, FireworkEffect fe) {
            if (!disabled) {
                Firework fw = world.spawn(loc, Firework.class);
                FireworkMeta data = fw.getFireworkMeta();
                data.clearEffects();
                data.setPower(0);
                data.addEffect(fe);
                fw.setFireworkMeta(data);
                try {
                    Object nms_firework = firework_getHandle.invoke(fw, new Object[0]);
                    expectedLifespan.set(nms_firework, Integer.valueOf(1));
                    ticksFlown.set(nms_firework, Integer.valueOf(1));
                } catch (Exception e) {
                    disabled = true;
                    //log("Failed to create firework effect.");
                }
            }
        }
    }
     
     

    Attached Files: