Scheduler Problems

Discussion in 'Plugin Development' started by Reptar_, Jun 10, 2013.

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

    Reptar_

    So my friend uses the plugin Skript for a Super Smash server he's working on but can't do an effective double jump code with it. So I'm working with java for him to get it done. Here's how I want it:

    Click with an item, check if player's hunger is full, set hunger to half, push player up, then every second, add 1 to the player's hunger until full again. The only problem I have is the scheduler adding onto the player's hunger each second after the push jump.

    http://pastebin.com/c7ye97xf
     
  2. Offline

    Aqua

    Reptar_ Currently you add food to the player only if delay == 0.
    Try this:
    Code:
    public class SkriptJump extends JavaPlugin implements Listener{
       
            public void onEnable(){
                    Bukkit.getPluginManager().registerEvents(this, this);
            }
       
            public int delay = 5;
            public int regen = 2;
       
            @EventHandler
            public void onPlayerInteractEvent(PlayerInteractEvent e){
                    final Player p = e.getPlayer();
                    if((e.getAction() == Action.LEFT_CLICK_AIR) && (p.getItemInHand().getType() == Material.GHAST_TEAR)){
                            if(p.getFoodLevel() == 20){
                                    p.setVelocity(new Vector(p.getVelocity().getBlockX(), 1, p.getVelocity().getBlockZ()));
                                    p.setFoodLevel(10);
                                    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                                       
                                            public void run(){
                                                    if (delay !=-1){
                                                            if (delay !=0){
                                                                    p.setFoodLevel(p.getFoodLevel() + regen);
                                                                    delay--;
                                                            }
                                                    }
                                            }
                                    }, 0L, 20L);
                            }
                    }   
            }
    }
     
  3. Offline

    Reptar_

    Aqua
    Just tried that and it doesn't work.
     
  4. Offline

    Aqua

    Reptar_ Add a few debug messages, see what is happening.
    For instance, display delay and regen at start of the event. Then display delay insude the run():
    Code:
    Bukkit.broadcastMessage("delay - " + delay);
    It will get spammy as hell, but you get to see what is going on ;)
    Add a few more messages before and after if-statements to see if they succeed.
     
  5. Offline

    chasechocolate

    Reptar_ do a check to see if player.getFoodLevel() + regen <= 20 before adding more hunger bars.
     
  6. Offline

    Reptar_

    How would I do that? :3
     
  7. Offline

    chasechocolate

    Reptar_ just add that in an if-statement before setting their food level. Also, are/were you getting any errors in console?
     
  8. Offline

    Reptar_

    This is what I have: http://pastebin.com/pzXv7ZAu

    And no errors.

    Ok so I just had to kill my guy and do it. Now it works, but the regen is too fast. How do i fix that?

    What it does is that it works the first time, then any other time it will all regenerate in 1 second.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page