PlayerDropItemEvent <> Need coding help <>

Status
This thread has been locked.

vPixelZ

Feedback score
0
Posts
316
Reactions
101
Resources
0
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:
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;
        }
      }
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Ark9026

Accepting Plugin Orders!
Premium
Feedback score
6
Posts
64
Reactions
60
Resources
0
Rather than checking
Code:
if(apple.equalsIgnoreCase("&5Golden Apple")) {
, check
Code:
if(apple.equalsIgnoreCase(ChatColor.PURPLE + "Golden Apple")) {
That should fix your issue :)
 

vPixelZ

Feedback score
0
Posts
316
Reactions
101
Resources
0
Rather than checking
Code:
if(apple.equalsIgnoreCase("&5Golden Apple")) {
, check
Code:
if(apple.equalsIgnoreCase(ChatColor.PURPLE + "Golden Apple")) {
That should fix your issue :)
Will try thanks!

EDIT: Worked!! Thank you so much!
 
Status
This thread has been locked.
Top