Replace Timers with Bukkit schedulers

This commit is contained in:
cnaude 2013-04-04 20:48:56 -07:00
parent d97c1adaf0
commit e135df1c62
3 changed files with 16 additions and 22 deletions

View File

@ -1,8 +1,6 @@
package net.spoothie.chairs; package net.spoothie.chairs;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -55,21 +53,18 @@ public class EventListener implements Listener {
} }
} }
class sendSitTask extends TimerTask {
@Override
public void run() {
plugin.sendSit();
}
}
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Timer timer = new Timer(); delayedSitTask();
long delay = 1 * 2000; }
timer.schedule(new sendSitTask(), delay);
//plugin.sendSit(); private void delayedSitTask() {
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
plugin.sendSit();
}
}, 20 );
} }
@EventHandler @EventHandler
@ -113,6 +108,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getItemInHand().getType().isBlock() if (event.getPlayer().getItemInHand().getType().isBlock()
&& (event.getPlayer().getItemInHand().getTypeId() != 0)
&& plugin.ignoreIfBlockInHand) { && plugin.ignoreIfBlockInHand) {
return; return;
} }
@ -287,9 +283,7 @@ public class EventListener implements Listener {
plugin.sit.put(player.getName(), block.getLocation()); plugin.sit.put(player.getName(), block.getLocation());
event.setUseInteractedBlock(Result.DENY); event.setUseInteractedBlock(Result.DENY);
Timer timer = new Timer(); delayedSitTask();
long delay = 1 * 2000;
timer.schedule(new sendSitTask(), delay);
} }
} }
} }

View File

@ -1,5 +1,5 @@
name: Chairs name: Chairs
version: 2.0.1 version: 2.0.2
description: Let players sit on blocks. description: Let players sit on blocks.
authors: authors:
- spoothie - spoothie