1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Item Naming?

Discussion in 'Development' started by Junkdude, Nov 20, 2016.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Hello, How would I go about not changing an items custom name, but adding a new line to it with \n. Keep in mind, i dont want to change the original line, just add to it. Thanks in advance.
     
  2. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You can get the custom name and then add more text:
    PHP:
    // $item being an instance of pocketmine\item\Item
    $oldName $item->getCustomName(); // get the exising custom name if it exists
    $newName "Your new name"// the text you're adding
    $item->setCustomName($oldName "\n" $newName); // set the items new name

    // Single line
    $item->setCustomName($item->getCustomName() . "\n" "Your new name");
    You would want to perform some simple checks to make sure the item has a custom name and making sure the item doesn't already have a two line name or the text will most likely go off the client's screen.
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    How would I go about checking it? Confused about it
     
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Nevermind thank you for your help!
     
  5. BalAnce

    BalAnce Silverfish

    Messages:
    22
    GitHub:
    YaBoiBalAnce
    For others who may want to know how to check if item has custom name this may be helpful:
    PHP:
    $oldname $item->getName();
    if (
    $item->hasCustomName()) $oldname $item->getCustomName();
    //rest of the code
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.