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
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); } } } }
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.
Reptar_ just add that in an if-statement before setting their food level. Also, are/were you getting any errors in console?
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.