Solved getDisplayName() error

Discussion in 'Plugin Development' started by bronzzze, Feb 26, 2015.

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

    bronzzze

    Plugin is working fine but sometimes write this error in console

    And this is my 83 Line in Events:
    Code:
    package me.bronzzze.wardrobe;
    
    
    
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryType.SlotType;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    
    public class Events implements Listener{
       
       
        private final Main main;
       
    
    
    
        public Events(Main main) {
            this.main = main;
            // TODO Auto-generated constructor stub
        }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        ArmourGUI i = ArmourGUI.getInstance();
        HatGUI i2 = HatGUI.getInstance();
        MainGUI i3 = MainGUI.getInstance();
       
    
    
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            final Player p = (Player) e.getWhoClicked();
           
    
           
       
        if(e.getSlotType() == SlotType.ARMOR) {
            if(!(e.getWhoClicked().getGameMode() == GameMode.CREATIVE || e.getWhoClicked().isOp()))
            e.setCancelled(true);
        }
            if (e.getInventory()
                    .getName()
                    .equalsIgnoreCase("" + ChatColor.DARK_PURPLE + ChatColor.BOLD +  "Main Menu")) {
                if (e.getCurrentItem() == null) {
                    return;
                   
                }
                e.setCancelled(true);
                if (e.getCurrentItem().getType() == Material.LEATHER_CHESTPLATE) {
                    p.closeInventory();
                    i.openInventory(p);
                   
                   
                }
               
                if (e.getCurrentItem()
                        .getItemMeta()
                        .getDisplayName()
                        .contains("" + ChatColor.GOLD + ChatColor.BOLD
                                + "Hat Selector")) {
                    p.closeInventory();
                    i2.openInventory(p);
    
     
  2. Offline

    stormneo7

    Check the following before continuing...
    Code:
    e.getCurrentItem().hasItemMeta()
    e.getCurrentItem().getItemMeta().hasDisplayName()
     
  3. Offline

    mine-care

    Also getCurrentItem might return null :3
     
  4. Offline

    bronzzze

    Can you explain more. I dont understand you. sorry i am new with this
     
  5. Offline

    teej107

  6. Offline

    bronzzze

    I know its in line 83 and its something wrong with e.getCurrentItem().getItemMeta().hasDisplayName()
     
  7. Offline

    SuperOriginal

     
    mine-care likes this.
  8. Offline

    bronzzze

    superoriginal

    Can u explain please
     
  9. Offline

    SuperOriginal

  10. Offline

    bronzzze

    Ok when i click outside inventory i get this error

    Superoriginal do you mean this?

    Code:
     if (e.getCurrentItem() == null) {
                    return;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  11. Offline

    SuperOriginal

    have you tried it?
     
  12. Offline

    bronzzze

    Nvm now its working ty all.

    i forgot to add
    Code:
    e.getCurrentItem().hasItemMeta()
    e.getCurrentItem().getItemMeta().hasDisplayName()
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  13. Offline

    mine-care

    @bronzzze still want me and SupperOriginal are trying to say is that if the clicked item is nothing then you will get this error.... Also if you click out of da inv you'll get it... So, pay some effort and see when something turns to null, what hAppends in java, it will only take few minutes to read or watch a tutorial explaining it. There are plenty out there.
     
Thread Status:
Not open for further replies.

Share This Page