Bukkit在游戏的每个刻度上更新项目的名称

问题描述 投票:0回答:1

我试图更新游戏的每个滴答的剩余秒数。我不知道从这里开始

这是我的代码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的新手,所以对我来说很容易。

java bukkit
1个回答
0
投票

在你的插件类中添加:

private static Main instance;

public static Main getInstance() {
    return instance;
}

public void onEnable() {
    instance = this;
}

然后使用以下命令启动Bukkit Scheduler:

new BukkitRunnable() {
    @Override
    public void run() {
        // code to execute every tick
    }
}.runTaskTimer(Main.getInstance(), 1, 1);
© www.soinside.com 2019 - 2024. All rights reserved.