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

names repeating over and over again

Discussion in 'Development' started by iCirgio, Jul 21, 2018.

  1. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    so basically im trying to make a ce plugin. but when i enchant it keeps showing name over and over again (i looked at piggyce and got some of the code)

    eg.
    CE II
    CE III

    i got it to stop repeating
    CE II
    CE II
    But levels still repeat

    Anyone can help?
    PHP:
    $ench $item->getNamedTagEntry(Item::TAG_ENCH);
      
    $found false;
      if(!(
    $ench instanceof ListTag)){
           
    $ench = new ListTag(Item::TAG_ENCH, [], NBT::TAG_Compound);
                } else {
              foreach(
    $ench as $k => $entry){
                  if(
    $entry->getShort("id") === $enchant){
                     
    $ench->set($k, new CompoundTag("", [
           new 
    ShortTag("id"$enchant),
           new 
    ShortTag("lvl"$param[3])]));
      
    $iname $item->getName();
      
    $itag "\n" $name " " $lvl;
      
    $iname =  str_replace($itag""$iname) . $itag;
      
    $item->setCustomName($iname);
      
    $p->getInventory()->setItemInHand($item);

     
    $found true;

           }
        }
    }

        if(!
    $found){
                     
    $ench->push(new CompoundTag("", [
           new 
    ShortTag("id"$enchant),
           new 
    ShortTag("lvl"$param[3])]));
      
    $item->setCustomName(C::AQUA $item->getName() . C::RESET PHP_EOL ' '$name ' '$lvl);
      
    $p->getInventory()->setItemInHand($item);
       
    $item->setNamedTagEntry($ench);

        }
     
    Last edited: Jul 21, 2018
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    $name $item->getName();
    $tag "\n" $enchantment->getName() . " " . ($args[2] ?? 1);
    $name str_replace($tag""$name) . $tag;
    $item->setCustomName($name);
    - Muqsit

    This worked for me!
     
  3. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    Still keeps repeating

    The enchant with the same level won't repeat but other lvl repeats
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Do same with level than
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Override the old ench then? Btw Item->addEnchantment() does the same thing what you're doing.
    PHP:
    $lore $item->getLore();

    //Before enchanting the item.
    $old_ench $item->getEnchantment($id);
    if(
    $enchantment !== null){
        
    $old_lore $old_ench->getName() . " " $old_ench->getLevel();
        
    $key array_search($lore$old_loretrue);
    }else{
        
    $key count($lore);
    }

    $lore[$key] = //new enchantment lore
    $item->setLore($lore);
     
    OnTheVerge likes this.
  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.