I'm writing a plugin that disables jump building. It's almost finished, except that it is still possible to jump build if you hold down jump and spam to place blocks. Can anyone explain why this happens and how I would fix it? My guess would be to put a delay on either jumping or placing the blocks, but I don't know how to do this. I tried using event.wait(Timer.ONE_SECOND), but I don't think I'm implementing it correctly because it's not working.. Any help would be much appreciated. EDIT Fixed, thanks!
For delayed tasks, use the bukkit scheduler, here's an example: Code: getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { public void run() { //your code here } }, 1200L); //delay in ticks, 20 ticks per seconds.
Thanks! Where do I put this though? In main, or in my listener (where my code is)? When I try to stick it in my listener class, it keeps throwing syntax errors.. Also, this should delay placing a block down if I use it onBlockPlace, right?
You can place it anywhere you can get the server object (from the getServer() method or directly with a server instance), but keep in mind that any data you'll be passing to it will need to come from class variables. As for the error, I forgot to specify that "this" on the first line is an instance of your main class (for you plugin), I'll guess that's your problem. Also, don't create to many tasks, you might overload the server, so keep it out of listeners that trigger often, unless your planing to use it only on special occasion (like if a player right clicks a sign with specific text on it).
Well, I'm wanting to delay either placing a block down or jumping.. In order to do this would I place that code around the onBlockPlace method? I'm wanting to make it so you can't spam jump and right click to place blocks, because this makes my plugin not work properly. Still looking for help or an explanation on this. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
If you already have code that identifies when a player places a block below him, the rest would be relatively easy. I suggest you just store per player the time he last placed a block below him: long lastTime = System.getCurrentTimeMillis(); and write your onblockplace method like this: Code: onBlockPlace(... ) { if(jumpblockplace) // Your code that identifies jumpbuilding decides if this is true or false if(lastTime + 1000 > System.getCurrentTimeMillis()) { // not enough time passed since last time event.setCancelled(true); else lastTime = System.getCurrentTimeMillis(); } } The 1000 is 1 second, you can choose a different delay. Now all you have to do is remember "lastTime" for each player between events. This method doesn't need any bukkit task to work.