Solved PlayerInteractEvent isn't working at some point?

Discussion in 'Spigot Plugin Development' started by OfirTIM, May 10, 2017.

Thread Status:
Not open for further replies.
  1. Hello spigot fellows, i've been stucked in a situation i am getting really tired of and i dont understand some of it to be honest, i am firing the event and checking on some items and i get to some point where my code isn't working at all:
    Code (Text):
        @EventHandler
        public void onClickEvent(PlayerInteractEvent event) {
            Player e = event.getPlayer();
            if (event.getAction().name().toLowerCase().contains("click")) {
                //works here
                if (event.hasItem()) {
                    //works here aswell
                    ItemStack kitselector = ItemDecoder.stringToItem(KronusKits.getInstance().getConfig().getString("kitselector-item.item"));
                    System.out.println(kitselector);
                    System.out.println(event.getItem());
                    //both those print out to see if there's diffrenece between the items.
                    if (kitselector == event.getItem()) {
                        //i reach to this point where it doesn't work at all
                        //i tried e.getItemInHand() aswell, didn't work at all.
                        System.out.println("Debug");
                        KitSelector.OpenKitSelector(e);
                    }
                }
            }
        }
    here's my Console Output from those 2 System.out.println commands:
    Code (Text):
    [20:33:25 INFO]: ItemStack{SLIME_BALL x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name=ºaºlKit Selector, lore=[º7Click on me to, º7open the kits menu!]}}
    [20:33:25 INFO]: ItemStack{SLIME_BALL x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name=ºaºlKit Selector, lore=[º7Click on me to, º7open the kits menu!]}}
    both are the same right? no difference at all!
    my minecraft version 1.8 Spigot.
    i dont see the point why does it happens...
    if anyone can help i would be more then glad!
    thanks for answers!
     
  2. You have to use .equals() to compare the items here. '==' checks whether they are they same instance (at the same place in memory; read this).

    In your case you could also use .isSimilar()
     
    • Useful Useful x 1
  3. i never knew that! i thought '==' works just as Equals()! i read some about java books and i never noticed! thank you
     
Thread Status:
Not open for further replies.