I am currently working on a plugin that will allow players to rename items held in their hand by using a command to rename them. I was wondering how i might be able to do this while only checking if the command is used. PlayerHeldItemEvent checks on its own without calling, so I excluded that from my use. I have the plugin in development here: https://github.com/PocketMineMasters/ItemRenamer Thank you for the help.
Here's the code that isn't working: PHP: $sender->getInventory()->getItemInHand()->setCustomName($args[0]); //doesn't work$ItemName = $sender->getInventory()->getItemInHand()->getName();$sender->sendMessage(TF::BOLD.TF::GREEN."[Item Renamer] ".TF::RESET.TF::GREEN."The Item's Name Changed to: \n".TF::GREEN.$ItemName);return true;
This will each time write to the Console e.g. [ItemRenamer] The Item's Name Changed to: Stone Sword. Use getCustomName() instead of getName() Does the player see customName in-game?
PHP: Public function onHand(PlayerItemHeldEvent $event){If($event->getPlayer()->getInventory()->getItemInHand()->getId() == $item){$event->getPlayer()->sendPopup("Hello !"); }}
The issue with your method is that the item's name is still the same. You just added a popup to overshadow it. What I am trying to do is rename the item so that it can be given to another player and keep the name with the NBT tag