Xpeawey
Xpeawey

Reputation: 547

How to get a value from a key?

I want to track the bib click, the tracking works, but I need to get executableitems:ie-id to check the bib for authenticity.

Here is full item informations:

enter image description here enter image description here

My code:

@EventHandler
public void onItemClick(PlayerInteractEvent e) {
   if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction()!= Action.RIGHT_CLICK_AIR) return;

        ItemStack item = e.getItem();
        if(item == null) return;
        e.getPlayer().sendMessage("Start!");
        if(item.getType() == Material.NETHERITE_CHESTPLATE) {
//      e.getPlayer().sendMessage(String.valueOf(e.getItem().serialize()));
        e.getPlayer().sendMessage(String.valueOf(e.getItem().serialize().get("executableitems:ie-id")));
//      e.getPlayer().sendMessage(String.valueOf(e.getItem().getData()));
        e.getPlayer().sendMessage("Blaze rod clicked!");
    }
}

Upvotes: 0

Views: 81

Answers (1)

Elikill58
Elikill58

Reputation: 4908

You can use a tag API located in ItemMeta.

For some old version, it will be by using getCustomTagContainer() then simply use getCustomTag. The namespaced key should be NamespacedKey.fromString("executableitems", "ie-id").

For new versions, you should use getPersistentDataContainer() then simply use get or getOrDefault.

Upvotes: 2

Related Questions