Firework particals on login Problem

Discussion in 'Plugin Development' started by minelazz, Sep 26, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    minelazz

    Hi, need some help with fireworks particals. I want to make a plugin that when a new player login will it spawn fireworks particals at the spawnpoint. My problem is that it only works when i use a command to start it, but it dont work when new players login. The problem can may be that you dont see it when you login to the server.

    Here is my code to launch the particals


    Code:
    @EventHandler
      public void onLogin(PlayerJoinEvent e) throws IllegalArgumentException, Exception {
          Player player = e.getPlayer();
         
      int TestMode = getConfig().getInt("TestMode");
     
      if((TestMode == 1))
      {
          if (!e.getPlayer().hasPlayedBefore())
          {   
             
                 FireworkParticals fplayer = new FireworkParticals();
            FireworkEffect fe = FireworkEffect.builder().with(Type.BALL).withColor(Color.GREEN).build();
            try {
                fplayer.playFirework(player.getPlayer().getLocation(), fe);
            } catch (Exception w) {
                w.printStackTrace();
            }
       
            }
          }
    Here is the code to make the particals and spawn it
    Code:
    package minelazz.thelobbypack;
       
        import java.lang.reflect.Method;
       
        import org.bukkit.FireworkEffect;
    import org.bukkit.entity.Firework;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
       
       
        public class FireworkParticals {
           
             
                private static Method world_getHandle = null;
                private static Method nms_world_broadcastEntityEffect = null;
                private static Method firework_getHandle = null;
             
     
     
                public static void  playFirework(final Location location, final FireworkEffect fe) throws Exception {
     
                   
                       
                 
                        Firework fw = (Firework)location.getWorld().spawn(new Location(location.getWorld(), 995.5,31,358.5), Firework.class);
                        Object nms_world = null;
                        Object nms_firework = null;
               
                        if(world_getHandle == null) {
                                world_getHandle = getMethod(location.getWorld().getClass(), "getHandle");
                                firework_getHandle = getMethod(fw.getClass(), "getHandle");
                        }
                        nms_world = world_getHandle.invoke(location.getWorld(), (Object[]) null);
                        nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
                        if(nms_world_broadcastEntityEffect == null) {
                                nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
                        }
     
                        FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
                        data.clearEffects();
                        data.setPower(1);
                        data.addEffect(fe);
                        fw.setFireworkMeta(data);
                        nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
                        fw.remove();
                        }
                       
                     
       
           
               
                private static Method getMethod(Class<?> cl, String method) {
                        for(Method m : cl.getMethods()) {
                                if(m.getName().equals(method)) {
                                        return m;
                                }
                        }
                        return null;
                }
       
        }
    
    Here is my other class file that make the particals

    thanks, minelazz
     
  2. Offline

    chasechocolate

    Do some debug messages, it's probably because the player has played before.
     
  3. Offline

    minelazz

    thanks for the help, but can't still find the bug. Added some messages, got reply started and Test 1 that means that it start and "spawn" the particals, but no particals got spawned.


    Here is the code is used, with the console messages;
    Code:java
    1. public static void playFirework(final Location location, final FireworkEffect fe) throws Exception {
    2.  
    3. Bukkit.getServer().getConsoleSender().sendMessage("[TheLobbyPack] Started" + location.getWorld());
    4.  
    5.  
    6.  
    7. Firework fw = (Firework)location.getWorld().spawn(new Location(location.getWorld(), 995.5,31,358.5), Firework.class);
    8. Bukkit.getServer().getConsoleSender().sendMessage("[TheLobbyPack] test 1");
    9.  
    10. Object nms_world = null;
    11. Object nms_firework = null;
    12.  
    13. if(world_getHandle == null) {
    14. world_getHandle = getMethod(location.getWorld().getClass(), "getHandle");
    15. firework_getHandle = getMethod(fw.getClass(), "getHandle");
    16. Bukkit.getServer().getConsoleSender().sendMessage("[TheLobbyPack] test 2");
    17.  
    18. }
    19. nms_world = world_getHandle.invoke(location.getWorld(), (Object[]) null);
    20. nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
    21. if(nms_world_broadcastEntityEffect == null) {
    22. nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
    23. Bukkit.getServer().getConsoleSender().sendMessage("[TheLobbyPack] test 3");
    24.  
    25. }
    26.  
    27. FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
    28. data.clearEffects();
    29. data.setPower(1);
    30. data.addEffect(fe);
    31. fw.setFireworkMeta(data);
    32. nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
    33. fw.remove();
    34. }
    35.  
    36.  
    37.  


    someone who can find the problem why it does not spawn?
     
  4. Offline

    chasechocolate

    minelazz if your firework spawning method works in a command, then it will work in another event/method. Do some debug messages in your join event method, that's probably where the error is.
     
Thread Status:
Not open for further replies.

Share This Page