Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Item with custom name

Comments in 'Plugin Development' started by IcePL, May 27, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi.
    It is possible to give of an item that has changed the name but his real name is not affected?
    for instance a player has a diamond blade that is not renamed and a second diamond sword that has changed the name .

    I need to use this by using code instead of / give
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Item::setCustomName()
    IcePL likes this.
  3. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    And t is possible to remove this item with custom name?
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Isn't that simple? Inventory::removeItem($item)
    IcePL likes this.
  5. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Ok thanks for help.
    I have one question:
    It is possible and how to stop damage of item when player attack e.q zombie.
  6. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    IcePL likes this.
  7. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    But how to stop damage in this API?
  8. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Sorry, the api cannot change the damage
    You can set that with EntityDamageEvent
  9. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    but I mean to stop damage to the weapons and do not stop the damage inflicted by weapons
  10. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Any help me? ;)
  11. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Cancel the EntityDamageEvent
  12. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I agree with @korado531m7, try this:
    PHP:
    public function onEntityDamageEvent(EntityDamageEvent $event){
        if(
    $event instanceof EntityDamageByEntityEvent){
            
    $customName "YourCustomName";
            if(
    $event->getDamager()->getItemInHand()->getCustomName() == $customName){
                
    $event->setCancelled();
            }
        }
    }
    I'm not sure if this will work, but it's worth a try
  13. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    If you are using my naming API plugin, you can use this (not tested)
    API : http://forums.pocketmine.net/threads/renamed-enchanted-item-with-api.16682/

    PHP:
    //if you add item that name is "test sword" (Diamond Sword)

    function onEntityDamageEvent(EntityDamageEvent $ev){
        if(
    $ev instanceof EntityDamageByEntityEvent){
            
    $damager $ev->getDamager();
                if(
    $damager instanceof Player){
                    if(
    $damager->getInventory()->getItemInHand()->getName() == "test sword"){
                       
    $ev->setCancelled(true);
                    }
               }
       }
    }

Share This Page

Advertisement