Solved Get entity dropped

Discussion in 'Spigot Plugin Development' started by MrStreeet, Jun 12, 2021.

  1. Hello! I'm actually learning how to code Minecraft plugins and I want to learn how to get the ID of a dropped item and put in the chat a message something like "You've dropped: (Item x64)"
    Actually I have this one but it doesn't works as I want.
    Hope that someone can help me ^^ upload_2021-6-12_18-25-49.png
  2. This will send a message for every items on the ground, you realize that right? If you only want the current dropped item you can use event.getItemDrop() and if you want the material name (the localized item name is a bit more complex to obtain) you can use event.getItemDrop().getItemstack().getType().toString(). I’m on my phone but I’m pretty sure it works
  3. You can just do:
    Code (Java):
    ItemStack item = event.getItemDrop().getItemStack();

    String id = item.getType().toString();
    int amount = item.getAmount();

    event.getPlayer().sendMessage(id + "(" + amount + "x)");
    I wrote it on phone, so it might be a miss somewhere, but it should work.
    • Agree Agree x 2
  4. It worked! Thank you so much ^^
    • Like Like x 1