The reason I am using nms is because I need to store values in custom items, so the custom items can have a level, the can be increased by using it. I think it would be nice if I had an api for this plugin, and therefor I want to let people using the api be able to get the player holding the specific item. Method can be called with PetsAPI#getPetHolder(<item in players hand>) Code (Java): @Override public Player getPetHolder(ItemStack pet) { return null; } Notice the Itemstack have an nbttag
Javadoc: public interface ItemMeta extends Cloneable, ConfigurationSerializable, PersistentDataHolder
I dont think the ItemStack itself saves the player who is holding it so you maybe could add a NBT Tag to save the information when a player swaps to that item?
because that's not the method name. Please actually take the time to look at the Javadocs that were linked (or even just use your IDE...) and realize that there's literally only one method added by PersistentDataHolder, #getPersistentDataContainer(). Use the API. You have no reason whatsoever to be using servers internals to be doing this. Also, no. ItemStacks are nothing more than information about a quantified item. They are not tied to a specific player nor inventory.
I know thats not the name, I just hoped you would know what I meant, but I can see how that is very unclear to know. I found out I should need #getCustomContainer.
I switched over to PersistenDataContainer: This is my code for now, dont know if it works yet. Code (Java): @Override public Player getPetHolder(ItemStack pet) { CustomItemTagContainer ctc = pet.getItemMeta().getCustomTagContainer(); if(ctc.getCustomTag(plugin.wrapper.holderKey, ItemTagType.STRING) == null) return null; Player holder = Bukkit.getPlayer(ctc.getCustomTag(plugin.wrapper.holderKey, ItemTagType.STRING)); return holder; } Then I will create a custom event that checks if the pet is in a new inventory or something along the lines
Your suggestion is pretty damn awful, if you have many players online you with generate a huge overhead. I am sure people like you are the reason why why a server with 80 plugins runs on 3 tps. Taking the easy way out, screw the performance of the server right? The last person I would ever want to comission something from is someone that shares your thought process. The little things add up for awful performance loss, dont just shrug over it thinking you will only lose a little tiny bit of performance.