Solved making a method repeat for 4 seconds

Discussion in 'Plugin Development' started by kamakarzy, May 5, 2013.

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

    kamakarzy

    hi fellow bukkiters how would i go about making this method run for 4 seconds

    Code:
    public void Hearts(Player p){
            String name = p.getName();
            Wolf o = p.getWorld().spawn(p.getLocation(), Wolf.class);
            o.playEffect(EntityEffect.WOLF_HEARTS);
            o.remove();
        }
    i was going to start it by using

    Code:
    Hearts(player);
     
  2. Offline

    MP5K

  3. Offline

    kamakarzy

    thanks MP5K
    but i tried that i just get problems because id need to change Player p to final and i would have no idea about that
     
  4. Offline

    MP5K

    PHP:
    public void Hearts( final Player p){
            
    String name p.getName();
            
    Wolf o p.getWorld().spawn(p.getLocation(), Wolf.class);
            
    o.playEffect(EntityEffect.WOLF_HEARTS);
            
    o.remove();
        }
     
  5. Offline

    kamakarzy

    thatnks didnt realise it was that simple :)

    MP5K thats all working but now it stays on how do i get it to finish would i have to do a coundown or is there an easyway

    Code:
    if(args.length == 1){
                    Player Player2 = player1.getServer().getPlayer(args[0]);
                    if(player1.getLocation().distanceSquared(Player2.getLocation()) <= 4) {
                        this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
                           
                            public void run(){
                                hearts(player1);
                            }
                        }, 0L, 20L);
                       
                    }
                    else{
                        player1.sendMessage("You need to be close to hug");
                    }
                }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  6. Offline

    MP5K

    i would use that code: (so basically increment a Variable every time the Method is Called and if the Value is bigger then X cancel the Task.)
    PHP:
            BukkitRunnable run = new BukkitRunnable(){
     
                private 
    int count 0;
               
                @
    Override
                
    public void run() {
                    if(
    count >= 4){
                        
    this.cancel();
                        return;
                    }
                    
    Heart(player1);
                    
    count++;
                   
                }
               
            };
            
    run.runTaskTimer(plugin0L20L);
     
  7. Offline

    kamakarzy

    MP5K thank you your a superstar:)
     
Thread Status:
Not open for further replies.

Share This Page