Help with Bukkit Runnables and run task timer

Discussion in 'Plugin Development' started by Charliebiff05, Apr 23, 2020.

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

    Charliebiff05

    Code:
    public class WandEventsclass implements Listener{
      
    
        @SuppressWarnings("deprecation")
        @EventHandler
            public void onUse(PlayerInteractEvent e) {
            
            Player p = e.getPlayer();
             ItemStack item = p.getItemInHand();
             ItemMeta meta = item.getItemMeta();
              
                if (p instanceof Player) {
                    if(p.getItemInHand().getType() == Material.STICK) {
                        if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                            if(meta.getDisplayName().equalsIgnoreCase("Staff")){
                                p.sendMessage("Pew!");
                              
                            Snowball ball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
                          
                            ball.setShooter(p);
                            ball.setVelocity(p.getLocation().getDirection().multiply(1.5));
                              
                                    BukkitTask task = new BukkitRunnable() {
                                        public void run() {
                                            Firework f = p.getWorld().spawn(p.getEyeLocation(), Firework.class);
    
                                            ball.addPassenger(f);
                                            f.detonate();   
                                        }
                                      
                                    }.runTaskTimer(, 0L, 20L );
                              }
                        }                          
                   }
              }
        }
    }
    Sorry about the codes alignment lol, not sure what happened.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 23, 2020
  2. Online

    timtower Administrator Administrator Moderator

    @Charliebiff05 Might help if you would also say what you want.
    Because now you just posted some code.
     
  3. Offline

    Charliebiff05

    @timtower cheers for the reply, I need the firework to repeat explode as it follows the snow ball after it was been cast so some sort of loop every half second
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    Charliebiff05

    just the single explosion on launch of snowball, the explosion effect, it does not trail a,long with the snowball. cheers again
     
  6. Online

    timtower Administrator Administrator Moderator

    @Charliebiff05 Snowball is still flying? Tried adding debug statements to see if it is still running?
     
  7. Offline

    Charliebiff05

    the snowball fly's but the explosion effect is not carried as the ball gets thrown, I want some sort of loop that I could set that makes the effect happen every couple ticks at the ball goes through the air, that's basically what I am trying to do.
     
  8. Online

    timtower Administrator Administrator Moderator

    Does the runnable run multiple times?
    You can check that with a broadcast in the first line of the runnable.
     
    Charliebiff05 likes this.
  9. Offline

    Charliebiff05

    Code:
    if (p instanceof Player) {
                    if(p.getItemInHand().getType() == Material.STICK) {
                        if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                            if(meta.hasDisplayName()){
                                p.sendMessage("Pew!");
                              
                            Snowball ball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
                          
                            ball.setShooter(p);
                            ball.setVelocity(p.getLocation().getDirection().multiply(1.5));
                              
                                    BukkitTask task = new BukkitRunnable() {
                                        public void run() {
                                            Firework f = p.getWorld().spawn(p.getEyeLocation(), Firework.class);
    
                                            ball.addPassenger(f);
                                            f.detonate();   
                                        }
                                      
                                    }.runTaskTimer(, 0L, 20L ); --------------------- This is the part that is coming up with and error
                              }
                        }                          
                   }
     
  10. Online

    timtower Administrator Administrator Moderator

  11. Offline

    Charliebiff05

    }.runTaskTimer(, 0L, 20L ); its telling me to remove the first comma in the parenthesises

    The method runTaskTimer(Plugin, long, long) in the type BukkitRunnable is not applicable for the arguments (long, long) - error, when the comma is removed...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  12. Online

    timtower Administrator Administrator Moderator

  13. Offline

    Charliebiff05

    in what respect? sorry I think this is where I am forgetting / stuck here, the plugin like the Main or?? Sorry for noob in this area
     
  14. Online

    timtower Administrator Administrator Moderator

    Charliebiff05 likes this.
  15. Offline

    Charliebiff05

    :'(I tried referencing it but it didnt work

    upload_2020-4-24_21-51-50.png
     
  16. Online

    timtower Administrator Administrator Moderator

    @Charliebiff05 Then you need to pass it along using a constructor.
     
  17. Offline

    Charliebiff05

    if(meta.hasDisplayName()){ <---(IN PINK) this part here I want to reference a specific name not just nay display name
    p.sendMessage("Pew!");

    Snowball ball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);

    ball.setShooter(p);
    ball.setVelocity(p.getLocation().getDirection().multiply(1.5));

    BukkitTask task = new BukkitRunnable() {
    public void run() {
    Firework f = p.getWorld().spawn(p.getEyeLocation(), Firework.class);

    ball.addPassenger(f);
    f.detonate();
    }

    }.runTaskTimer(Main, 0L, 20L );

    DO you have an exg fr me of that? I have been looking all over

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  18. Online

    timtower Administrator Administrator Moderator

  19. Offline

    NukerFall

    private Main main;
    public MinorWandEventsclass(Main main) {
    this. main = main;
    main.getServer().getPluginManager().registerEvents(this, main);
    }

    and in main class:
    new MinorWandEventsclass(this);
     
Thread Status:
Not open for further replies.

Share This Page