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); }
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!
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_lore, true);}else{ $key = count($lore);}$lore[$key] = //new enchantment lore$item->setLore($lore);