Hi great devs of pmmp. I have a few questions. How would I utilize one of the three in the title to make an item identifiable? i.e. I'm making a Notes plugin (Dollar Bills) PHP: public function onPlayerInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $note = $player->getInventory()->getItemInHand()->getID(); $verify = $player->getInventory()->getItemInHand()->getCustomName(); $money = $player->getInventory()->getItemInHand()->getCompoundTag(); if($player instanceof Player){ if($note === Item::PAPER and $verify === "§aOfficial Note"){ $player->sendMessage(TF::GREEN."You have successfully saved into your account!"); EconomyAPI::getInstance()->addMoney($player, $money); } } } Which is in my Main class (All commands and Events are registered, don't worry) and this PHP: $sender->getInventory()->setItemInHand(Item::get(339, 0, $args[1])); sleep(1); $sender->getInventory()->getItemInHand()->setCustomName("§aOfficial Note"); $sender->getInventory()->getItemInHand()->setCompoundTag($args[0]); $sender->sendMessage(TF::GREEN . "Your notes has been issued successfully!"); return true; is how I designed to issue notes. What am I doing wrong? Custom name is not appearing and the listener in main class fails to identify that it's a note, not a normal paper item upon Interaction Event. All help's appreciated! Shadow
Wait, isn't it this ? PHP: $nbt = $item->getNamedTag(); also never use sleep(Int $number); it will basically freeze your whole server for $number seconds .. also after setting everything, you have to do PHP: $player->setItemInHand($item); in order to show the item's new properties like custom names, lores and other things
Yeah, realized that now Oh, need to try that. The help was greatly appreciated. NOT marking resolved for now.
@Az928 BTW I do not quite understand the $item part. What would that be defined as? $player->getInventory()->getItemInHand? Or something else? All helps are appreciated!
You shouldnt store it in item name instated, you should store it in NBT data, storing if it's valid AND the amount in NBT tags (search this forum to find out how
HOLD UP. Is that a sleep() I see in your second bit of code? Do NOT use sleep() in the main thread! That stops the whole server for as long as that sleep is set to which could cause players to be disconnected. Use a delayed task instead if you want something to happen after an amount of time
Never mind. Console returned new error "Trying to get Property 'isNote' of non-object" My code to read the tag is this PHP: public function onPlayerInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $note = $player->getInventory()->getItemInHand(); $verify = $note->getNamedTag()->isNote; $money = $note->getNamedTag()->noteValue; if($player instanceof Player){ if($note === Item::PAPER and $verify === "true"){ $player->sendMessage(TF::GREEN."You have successfully saved into your account!"); EconomyAPI::getInstance()->addMoney($player, $money); } } } And i use this code to set the note. PHP: $sender->getInventory()->setItemInHand(Item::get(339, 0, $args[1])); $note = $sender->getInventory()->getItemInHand(); $nbt = $note->getNamedTag() ?? new CompoundTag("", []); $nbt->isNote = new StringTag("isNote", "true"); $note->setNamedTag($nbt); $sender->getInventory()->setItemInHand($note); $nbt = $note->getNamedTag() ?? new CompoundTag("", []); $nbt->noteValue = new StringTag("noteValue", $args[0]); $note->setNamedTag($nbt); $sender->getInventory()->setItemInHand($note); $sender->sendMessage(TF::GREEN . "Your notes has been issued successfully!"); which is inside a execute() function. It is properly configured. What am I doing wrong here? All help's greatly appreciated.