Hey guys! So basically what I am trying to do is make items with certain names not dropable.
So for example if an item had the name ''&5Golden Apple'' it wouldn't be possible to drop it by pressing Q. I've tried to make it work but got stuck. It'd mean alot if someone could feed me with some code that checks the name of the item, if it is the name ''&5Golden Apple'' cancel the drop event.
The code I currently have is:
So for example if an item had the name ''&5Golden Apple'' it wouldn't be possible to drop it by pressing Q. I've tried to make it work but got stuck. It'd mean alot if someone could feed me with some code that checks the name of the item, if it is the name ''&5Golden Apple'' cancel the drop event.
The code I currently have is:
Code:
}
String apple = e.getItemDrop().getItemStack().getItemMeta().getDisplayName();
if(apple.equalsIgnoreCase("&5Golden Apple")){
e.setCancelled(true);
}
}
public String getItemName(ItemStack item) {
String name = null;
if (item.hasItemMeta()) {
ItemMeta im = item.getItemMeta();
name = im.getDisplayName().replaceAll("§", "&");
}
if (name == null) { name = item.getType().toString().toLowerCase().replace("_", " "); }
return name;
}
}
