我正在尝试更新游戏的每个滴答的剩余秒数。我不知道在这里开始
这是我的代码atm:
@SuppressWarnings("deprecation")
@EventHandler
public void ItemRightClick(PlayerInteractEvent e) {
Player p = e.getPlayer();
Action a = e.getAction();
ItemStack item = p.getItemInHand();
ItemMeta itemmeta = item.getItemMeta();
if(a == Action.PHYSICAL) return;
if(!p.getItemInHand().getType().equals(Material.DIAMOND_HOE)) return;
if(!itemmeta.getDisplayName().contains("Wand of Regen")) return;
if(cooldown.containsKey(p)) {
if(cooldown.get(p) + cooldownTime <= System.currentTimeMillis()) {
cooldown.remove(p);
} else {
if((int) (cooldown.get(p) + cooldownTime - System.currentTimeMillis()) / 1000 != 0) {
itemmeta.setDisplayName(ChatColor.RED + "Wand of Regen" + ChatColor.GRAY + " - " + ChatColor.AQUA + "Remaining " + ChatColor.GREEN + (int) (cooldown.get(p) + cooldownTime - System.currentTimeMillis()) / 1000 + ChatColor.AQUA + " seconds");
item.setItemMeta(itemmeta);
return;
}
itemmeta.setDisplayName(ChatColor.RED + "Wand of Regen" + ChatColor.GRAY + " - " + ChatColor.GREEN + "Ready");
item.setItemMeta(itemmeta);
}
}
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5 * 100, 3));
p.sendMessage("Regen activated");
cooldown.put(p, System.currentTimeMillis());
}
我该怎么办?他们说使用调度程序,但我是java和bukkit的新手,所以对我来说很容易。
答案 0 :(得分:0)
在你的插件类中添加:
private static Main instance;
public static Main getInstance() {
return instance;
}
public void onEnable() {
instance = this;
}
然后用:
启动Bukkit调度程序new BukkitRunnable() {
@Override
public void run() {
// code to execute every tick
}
}.runTaskTimer(Main.getInstance(), 1, 1);