Java Bukkit API Test for item name -


i want test if item player holding has name. if want following:

egg egg = player.getworld().spawn(player.geteyelocation(), egg.class);             egg.setvelocity(player.getlocation().getdirection().multiply(1.5));             egg.setshooter(player);              player.getworld().playsound(player.getlocation(), sound.dig_wool, 15, 15); 

if doesn't should return "wrong name!"

bukkit has method called getiteminhand() on playerinventory can use item in hand. playerinventory, can call getinventory on player object.

you can checks on returned object, checking if null, , checking type:

itemstack item = player.getinventory().getiteminhand(); if(item != null && item.gettype() == material.egg) {     if(item.hasitemmeta() &&         item.getitemmeta().hasdisplayname() &&         item.getitemmeta().getdisplayname().equals("partyegg")) {         ....     } } 

Comments