Item Display Name

Discussion in 'Plugin Development' started by mydeblob, Sep 16, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    mydeblob

    Not sure what I'm doing wrong. I have never messed with item names or lores, so sorry for any nooby mistakes.
    This is the listener class where I tried to add a display name/lore. I know how to put it in someone inventory so don't tell me that, what I need to know how to do is to make this display name/lore "globalize" so for example, if I grew wheat and I broke the wheat the wheat that I grew would also have the display name/lore of "weed" Thanks!
    Code:java
    1. import java.util.ArrayList;
    2. import java.util.List;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15.  
    16. public class DrugListener implements Listener{
    17. public void ItemLores(){
    18. ItemStack item = new ItemStack(Material.WHEAT);
    19. ItemMeta im = item.getItemMeta();
    20. im.setDisplayName(ChatColor.DARK_GREEN + "Weed");
    21. List<String> loreList = new ArrayList<String>();
    22. loreList.add(ChatColor.GREEN + "Right click to smoke!");//This is the first line of lore
    23. im.setLore(loreList);
    24. item.setItemMeta(im);
    25. Bukkit.broadcastMessage("ItemLores method is working!");
    26.  
    27. }
    28.  
    29. @EventHandler
    30. public void onDrugUse(PlayerInteractEvent event){
    31. ItemLores();
    32. Player player = (Player) event.getPlayer();
    33. if(player.getItemInHand().getType() == Material.WHEAT){
    34. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    35. player.sendMessage(ChatColor.RED + "This is a test! :D");
    36.  
    37. }
    38. }
    39. }
    40. }
     
  2. afaik, there is no way to "globalize" it like you want. What i do for my vineyard plugin: get the block break evet, get the drops and replace it with my custom itemstack with the correct name(or lore)
     
  3. Offline

    mydeblob

    mollekake Hmm ok thanks. I will do that!
     
  4. Offline

    DevRosemberg

    mollekake There IS a way. Making a custom bukkit build.
     
  5. DevRosemberg But i assume that is a lot harder than simply replacing the drops
     
  6. Offline

    silentdojo

  7. Offline

    alexlyn1

    Hi, i am mydes friend and because? Whats the fun of downloading a plugin, the fun is about making it urself and be happy. That u actually made something thats cool urself. Btw myde ill write some code for u

    Sorry man, couldnt figure it outD:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    silentdojo

    Well the plugin in question was written by my friend meiskam (maker of PlayerHeads). That's why I suggested it. Oh well.
     
Thread Status:
Not open for further replies.

Share This Page