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

Help!! how do I change an Item's name without using events?

Comments in 'Plugin Development' started by jasonwynn10, Mar 5, 2016.

  1. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    I am currently working on a plugin that will allow players to rename items held in their hand by using a command to rename them. I was wondering how i might be able to do this while only checking if the command is used. PlayerHeldItemEvent checks on its own without calling, so I excluded that from my use. I have the plugin in development here: https://github.com/PocketMineMasters/ItemRenamer
    Thank you for the help.
    Last edited: Mar 10, 2016
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    $p->getInventory()->getItemOnHand();
    No need to use PlayerItemHeldEvent ;)
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    correction : $p->getInventory()->getItemInHand();
  4. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    Thankyou!
  5. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    setCustomName() isn't working to set the item's name. Any Ideas?
    Last edited: Mar 5, 2016
  6. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    there is a way to set the ItemName using NBT tags, but I don't know how. Any Help?
  7. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    What's the error(if any)?
  8. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    It just won't change the item's name. and there is no error output.
  9. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    Here's the code that isn't working:
    PHP:
    $sender->getInventory()->getItemInHand()->setCustomName($args[0]); //doesn't work
    $ItemName $sender->getInventory()->getItemInHand()->getName();
    $sender->sendMessage(TF::BOLD.TF::GREEN."[Item Renamer] ".TF::RESET.TF::GREEN."The Item's Name Changed to: \n".TF::GREEN.$ItemName);
    return 
    true;
  10. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Just a question, why don't you just use $args[0] instead of $itemName?
  11. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    This will each time write to the Console e.g. [ItemRenamer] The Item's Name Changed to: Stone Sword.
    Use getCustomName() instead of getName()

    Does the player see customName in-game?
    applqpak and PocketKiller like this.
  12. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    PHP:
    Public function onHand(PlayerItemHeldEvent $event){
    If(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() == $item){
    $event->getPlayer()->sendPopup("Hello !");
     }
    }
  13. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    I don't because by using $itemname it ensures that the item's name is changed.
  14. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    I would like to do what I am trying without the use of events
    applqpak likes this.
  15. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    You can't do this without event :/
  16. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    Dang, I was really hoping... :(
  17. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Try setting the custom Name before putting the item into the inventory.
    Read before replying..
    PocketKiller likes this.
  18. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    The issue with your method is that the item's name is still the same. You just added a popup to overshadow it. What I am trying to do is rename the item so that it can be given to another player and keep the name with the NBT tag
    Last edited: Mar 11, 2016
  19. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why did you quote my post?
  20. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    sorry, didnt mean to

Share This Page

Advertisement