Solved Trying to add a delay to spawn firework. Need Help Please!

Discussion in 'Plugin Development' started by McKiller5252, Feb 13, 2014.

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

    McKiller5252

    Okay so i am trying to add a few second delay when a player moves because when the player moves it spawns constantly as seen here:
    [​IMG]

    I want to add a 5 second delay before each spawn but keep getting this error
    Error Log:
    Show Spoiler

    2014-02-13 11:52:58 AM [SEVERE] Could not pass event PlayerMoveEvent to ParticlePack v1.0
    2014-02-13 11:52:58 AM org.bukkit.event.EventException
    2014-02-13 11:52:58 AMat org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:234) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.PacketPlayInPosition.handle(SourceFile:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AM Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    2014-02-13 11:52:58 AMat org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.validate(CraftScheduler.java:391) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:120) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:116) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:100) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AMat me.McKiller5252.particlepack.allparticles.FireworkParticle.preformEffect(FireworkParticle.java:22) ~[?:?]
    2014-02-13 11:52:58 AMat me.McKiller5252.particlepack.listener.ParticlePackListener.playerMove(ParticlePackListener.java:25) ~[?:?]
    2014-02-13 11:52:58 AMat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
    2014-02-13 11:52:58 AMat sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
    2014-02-13 11:52:58 AMat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
    2014-02-13 11:52:58 AMat java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
    2014-02-13 11:52:58 AMat org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b3005jnks]
    2014-02-13 11:52:58 AM... 13 more


    Here is the current code for PlayerMove:
    Code:java
    1. @EventHandler
    2. public void playerMove(PlayerMoveEvent event)
    3. {
    4. Player player = event.getPlayer();
    5. if (!blockChange(event))
    6. return;
    7. if (plugin.getPlayerParticle(player) != null)
    8. {
    9. Particle par = plugin.getPlayerParticle(player);
    10. par.preformEffect(player);
    11. }
    12. }


    and here is the firework:
    Code:java
    1. public void preformEffect(final Player player)
    2. {
    3. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    4. @Override
    5. public void run() {
    6. Location loc = player.getLocation().subtract(0, 0.6F, 0);
    7. RandomFireworks.getManager().launchRandomFirework(loc);
    8. }
    9. },100L);
    10. }


    RandomFirework:

    Code:java
    1. private static RandomFireworks fireWorks = new RandomFireworks();
    2.  
    3. public static RandomFireworks getManager(){
    4. return fireWorks;
    5. }
    6. ArrayList<Color> colors = new ArrayList<Color>();
    7. ArrayList<FireworkEffect.Type> types = new ArrayList<FireworkEffect.Type>();
    8.  
    9.  
    10. public void addColors(){
    11. colors.add(Color.WHITE);
    12. colors.add(Color.PURPLE);
    13. colors.add(Color.RED);
    14. colors.add(Color.GREEN);
    15. colors.add(Color.AQUA);
    16. colors.add(Color.BLUE);
    17. colors.add(Color.FUCHSIA);
    18. colors.add(Color.GRAY);
    19. colors.add(Color.LIME);
    20. colors.add(Color.MAROON);
    21. colors.add(Color.YELLOW);
    22. colors.add(Color.SILVER);
    23. colors.add(Color.TEAL);
    24. colors.add(Color.ORANGE);
    25. colors.add(Color.OLIVE);
    26. colors.add(Color.NAVY);
    27. colors.add(Color.BLACK);
    28. }
    29. public void addTypes(){
    30. types.add(FireworkEffect.Type.BURST);
    31. types.add(FireworkEffect.Type.BALL);
    32. types.add(FireworkEffect.Type.BALL_LARGE);
    33. types.add(FireworkEffect.Type.CREEPER);
    34. types.add(FireworkEffect.Type.STAR);
    35. }
    36. public FireworkEffect.Type getRandomType(){
    37. int size = types.size();
    38. Random ran = new Random();
    39. FireworkEffect.Type theType = types.get(ran.nextInt(size));
    40. return theType;
    41. }
    42. public Color getRandomColor(){
    43. int size = colors.size();
    44. Random ran = new Random();
    45. Color color = colors.get(ran.nextInt(size));return color;
    46. }
    47.  
    48. public void launchRandomFirework(Location loc){
    49. Firework fw = loc.getWorld().spawn(loc, Firework.class);
    50. FireworkMeta fm = fw.getFireworkMeta();
    51. fm.setPower(1);
    52. fm.addEffects(FireworkEffect.builder().with(getRandomType()).withColor(getRandomColor()).build());
    53. fw.setFireworkMeta(fm);
    54. }
    55. }


    Is there are way to add something like that to my code?
     
  2. Offline

    mrCookieSlime

    McKiller5252
    For me it seems like you forgot to call new FireworkParticle(this); in your onEnable() void (if you're using that constructor)
     
  3. Offline

    McKiller5252

    Accually i have FireWorkParticle in onEnable but i did it like this
    Code:java
    1.  
    2. public void onEnable() {
    3. loadParticles();
    4. }

    to new constructor
    Code:java
    1. private void loadParticles()
    2. {
    3. particles.add(new FireworkParticle());
    4.  
    5. }
     
  4. Offline

    mrCookieSlime

    McKiller5252
    Ok but you never defined the plugin variable in FireworkParticles since the error is basicly saying that plugin = null so you forgot to add the plugin instance to add to your constructor. Or if not please show me where you defined the plugin variable
     
  5. Offline

    McKiller5252


    Code:java
    1. public class ParticlePackListener implements Listener {
    2.  
    3. ParticlePack plugin = ParticlePack.Instance();
    4.  
    5. @EventHandler
    6. public void playerMove(PlayerMoveEvent event)
    7. {
    8. Player player = event.getPlayer();
    9. if (!blockChange(event))
    10. return;
    11. if (plugin.getPlayerParticle(player) != null)
    12. {
    13. Particle par = plugin.getPlayerParticle(player);
    14. par.preformEffect(player);
    15. }
    16. }

    This is in main class:
    Code:java
    1.  
    2. private static ParticlePack instance;
    3.  
    4. public void onEnable(){
    5. instance = this;
    6. try
    7. {
    8. getLogger().info("ParticlePack Enabled! Enjoy the particles :D");
    9.  
    10. cfg = new PPConfig(this);
    11. cfg.init();
    12.  
    13. ppgui = new ParticlePackGUI(this);
    14.  
    15. RandomFireworks.getManager().addColors();
    16. RandomFireworks.getManager().addTypes();
    17.  
    18. registerEvents();
    19. loadParticles();
    20.  
    21. }
    22. catch (IOException | InstantiationException | IllegalAccessException | InvalidConfigurationException e)
    23. {
    24. e.printStackTrace();
    25. getServer().getPluginManager().disablePlugin(this);
    26. }
    27.  
    28. this.getCommand("particlepack").setExecutor(new CommandHandler());
    29.  
    30. }
    31.  
    32.  
    33. public static ParticlePack Instance(){
    34. return instance;
    35. }
     
  6. Offline

    mrCookieSlime

    I see. Not the most fanciest way to do it, but at least it works ;) . Well, you're still getting exactly the same error? Cause it's definitely leading to a not defined plugin variable... Also I'm not sure if it would change anything, but try changing new Runnable() to new BukkitRunnable() .
     
  7. Offline

    McKiller5252

    It dose work with BukkitRunnable but when i move it keeps spawning a firework but i want it to have small breaks before spawing another 1 here is a example : 5 sec -----> a fireworks spawns -----> 5 sec ------> a firework spawns
     
  8. Offline

    mrCookieSlime

    McKiller5252
    Then you'd have to change some things. The way I'd use is running a TaskTimer in your onEnable void with a 1 sec Interval and store the Playername in a HashMap with the cooldown time and decrease the colldown in the HashMap via the TaskTimer every second and when it hits 0 remove the Player from the Map. How to handle that in the MoveEvent should be clear.
     
  9. Offline

    McKiller5252

    mrCookieSlime
    Could you give me a example of a TaskTime, I've seen them before but didn't get what they were for.
     
  10. Offline

    mrCookieSlime

    McKiller5252
    just do Bukkit.getScheduler().runTaskTimer(plugin, new BukkitRunnable(), 0L, 20L); This will run every second. But I'm sorry I'm tired I'll be back tomorrow.
     
  11. Offline

    McKiller5252

    Okay np Good night :)
     
  12. Offline

    mrCookieSlime

    McKiller5252
    Ok I'm awake now. Since you marked it as Solved, you coded the rest now?
     
  13. Offline

    McKiller5252

    No, I just marked it at solved cuz i got the runnable working because you helped me, I just need help on the task timer now
     
Thread Status:
Not open for further replies.

Share This Page