Trying to add a Tasktimer to launch fireworks every 5 sec on PlayerMoveEvent

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

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

    McKiller5252

    Title says it all
    [​IMG]

    I want to add a tasktimer but i don't really know how cause you can see in the pic everytime i move it spawns fireworks constantly and it gets really anoyying so i want to add a 5 sec delay before each firework launch, How would i be available to do that? Here is the code for the firework:

    The firework launch happens in the performEffect area and thats where i want the tasktimer to go

    Code:java
    1. TCNParticles plugin = TCNParticles.Instance();
    2.  
    3. public String getName()
    4. {
    5. return "Firework";
    6. }
    7.  
    8. public void preformEffect(final Player player) {
    9.  
    10. Location loc = player.getLocation().add(0, 1, 0);
    11. RandomFireworks.getManager().launchRandomFirework(loc);
    12. }
    13.  
    14. @Override
    15. public boolean canUse(Player player)
    16. {
    17. if (player.hasPermission("particlepack.firework"))
    18. return true;
    19. return false;
    20. }
    21.  
    22.  
    23. @Override
    24. public void setValue(String str) {}
    25. }
     
  2. Offline

    Gater12

    McKiller5252
    That picture makes a really good wallpaper, IMO.

    Have you tried doing a delayedTask for 5 seconds that launches the firework effect?
     
    Wizehh likes this.
  3. Offline

    McKiller5252

    Gater12
    Haha yea you're right about the picture :D

    Umm this is what i had before but i just spawned on a small delay after i moved and just keep spawning fireworks non-stop
    Code:java
    1. public void preformEffect(final Player player) {
    2. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new BukkitRunnable(){
    3. Location loc = player.getLocation().add(0, 1, 0);
    4. @Override
    5. public void run() {
    6. RandomFireworks.getManager().launchRandomFirework(loc);
    7. }
    8. },5L);
    9. }
     
  4. Offline

    Gater12

    McKiller5252
    That's right, except the delay. It should be 5 seconds not 5 ticks. 20 ticks = 1 second. So 5 * 20L = 5 seconds.
     
  5. Offline

    McKiller5252

    Gater12
    Nope that just delays the firework to spawn :p
    [​IMG]

    This is sorta what i mean: 5 sec -----> a fireworks spawns -----> 5 sec ------> another firework spawns and sooo on
     
  6. Offline

    Panjab

    McKiller5252

    Code:java
    1.  
    2. private boolean spawnFirework = true;
    3.  
    4. public void spawnFireworkTask() {
    5. Bukkit.getScheduker().scheduleSyncDelayedTask(plugin, new BukkitRunnable() {
    6. @Override
    7. public void run() {
    8. if (spawnFirework)
    9. spawnFirework = false;
    10. else
    11. spawnFirework = true;
    12. }, 20L * 5);
    13. }
    14.  
    15.  
    16. public void performEffect(final Player player) {
    17. if (!spawnFirework) return;
    18.  
    19. Location loc = player.getLocation().add(0, 1, 0);
    20. RandomFireworks.getManager().launchRandomFirework(loc);
    21.  
    22. }


    You just have to call the method "spawnFireworkTask" anywhere, e.g. in onEnable().
    It will switch the cancellation every 5 seconds. So it will only spawn one firework every 5 sec.
     
    McKiller5252 likes this.
  7. Offline

    McKiller5252

    Panjab
    What do you mean about onEnable()?

    Panjab It still won't work :p

    I still need help with this. Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  8. Offline

    Fight_Or_Die

    McKiller5252

    Give this a try:
    Code:java
    1. .runTaskLater(this.plugin, 60);

    on your public final class.
     
  9. Offline

    McKiller5252

    Already got it working :p Thanks for the help anyways
     
    Fight_Or_Die likes this.
Thread Status:
Not open for further replies.

Share This Page