最近我開始開發一個Bukkit插件,我需要幫助在我的代碼中進行睡眠/等待。我有點新來java,所以如果你能解釋它,我會很感激。這裏是我的代碼:bukkit - 等待?
@EventHandler
public void onTnt(PlayerInteractEntityEvent e) {
Player clicker = e.getPlayer();
Player rightclick = (Player) e.getRightClicked();
rightclick.sendMessage(ChatColor.GRAY + "~" + ChatColor.DARK_PURPLE + "AN INSTAKILLER HAS YOU AS A TARGET! SNEAK NOW!");
rightclick.sendMessage(ChatColor.GRAY + "~" + ChatColor.DARK_RED + "AN INSTAKILLER HAS YOU AS A TARGET! SNEAK NOW!");
rightclick.sendMessage(ChatColor.GRAY + "~" + ChatColor.GOLD + "AN INSTAKILLER HAS YOU AS A TARGET! SNEAK NOW!");
/* Then wait 3 sec. I've tried Thread.Sleep, wait() and sleep(), no sucess*/
if (!(rightclick.isSneaking())) {
rightclick.sendMessage(ChatColor.GRAY + "~" + ChatColor.GOLD + "Bye bye.");
rightclick.setHealth(0);
}
}
我不認爲等待或睡眠這裏是正確的想法,做一個新的bukkitrunnable,並安排其運行3秒鐘,以免睡眠插件的線程 – zack6849