Changing ItemMeta with BukkitTask

时间:2015-08-07 02:17:30

标签: java bukkit

I'm not able to change ItemMeta on ItemStack that's placed on a player inventory via repeating task. I tried the following:

BukkitTask taskTp;
int tempTp = 20;

private void rodarTeleport(final Player player, final ItemStack item) {
    final ItemMeta meta = item.getItemMeta();
    final String nome = meta.getDisplayName();

    taskTp = Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {

        @Override
        public void run() {
            if (tempTp > 0) {
                tempTp--;
                meta.setDisplayName(nome +" - " + tempTp + "s restantes." );
                item.setItemMeta(meta);
                player.updateInventory();
            }
            else {
                meta.setDisplayName(nome);
                item.setItemMeta(meta);
                player.updateInventory();
                taskTp.cancel();
            }
        }
    }, 20, 20);
}

It's supposed to change the display name once every second, but it's not updating it at all.

1 个答案:

答案 0 :(得分:-1)

在更新播放器广告资源之前:

p.setItem(slot, item);

所以你可以肯定,该项目现在位于正确的位置。