Checking if item has certian name

Discussion in 'Plugin Development' started by revivedbear, Nov 21, 2017.

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

    revivedbear

    So here is what I want; I want a player to click a nether star with an item and if that item is called "police application" then I want to change the items name. I have debugged the code and the code is recognising the item name, however, if I check it, even if it is the right item name, the if statement doesn't return true.
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onInventoryClick(InventoryClickEvent event) {
            HumanEntity human = event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
            ItemStack cursor = event.getCursor();
    
            if(human instanceof Player && event.getAction() == InventoryAction.SWAP_WITH_CURSOR) {
                if(cursor.getType() == Material.NETHER_STAR) {
                    event.setCancelled(true);
                }
             
                if(current.getType() == Material.NETHER_STAR) {
           
                    List<String> list = new ArrayList<String>();
                    ItemMeta itemmeta = cursor.getItemMeta();
                   
                    human.sendMessage(ChatColor.BLUE+ itemmeta.getDisplayName());
                    if(itemmeta.hasDisplayName()){
                        if(itemmeta.getDisplayName().equalsIgnoreCase("police application")){
                            System.out.println("test");
                            list.add("certificate");
                            itemmeta.setDisplayName("police certificate");
                            itemmeta.setLore(list);
                            cursor.setItemMeta(itemmeta);
    
    Even if the item is called "police application", it doesnt return true.
     
    Last edited by a moderator: Nov 21, 2017
  2. Offline

    MightyOne

    Show where you name the nether star. and why is there this ChatColor.BLUE?
     
  3. Offline

    timtower Administrator Administrator Moderator

    That is a sendmessage, probably debug
     
  4. Offline

    Blares

    well you aren't supposed to do a human entity, instead cast it to a "player" ex: Player p = (Player) e.getWhoClicked();
    I had this error so i hope it works:

    Code:
    
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onInventoryClick(InventoryClickEvent event) {
    Player p = (Player) e.getWhoClicked();
    ItemStack current = event.getCurrentItem();
    ItemStack cursor = event.getCursor();
    
    if(event.getAction() == InventoryAction.SWAP_WITH_CURSOR) {
    if(cursor.getType() == Material.NETHER_STAR) {
    event.setCancelled(true);
    }
    
    if(e.getItemInHand().getType() == Material.NETHER_STAR) {
    
    List<String> list = new ArrayList<String>();
    
    //your things
     
  5. Offline

    revivedbear

    chat color blue for no reason and the nether start is just the default name, its the name of the paper that I am checking

    'e' is undefined here isnt it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 22, 2017
  6. Offline

    Blares

    ar
    are you serious. I think he knows what I mean.
     
Thread Status:
Not open for further replies.

Share This Page