Update: Can't remove custom dye from inventory

Discussion in 'Spigot Plugin Development' started by FlawlessGaming, Jun 27, 2016.

  1. I want to remove green dye (Marijuana) from players inventory when they die but i can't find green dye in material. how do i remove it from there inventory?
  2. Materials only represent item IDs, not Item IDs and their data. You need to create a new ItemStack with the desired data value and remove that from their inventoey
  3. http://lmgtfy.com/?q=How+to+get+dye+color+bukkit
    But well here you go, *not spoonfeeding*
    Code (Text):
    ItemStack itemStack = new ItemStack(Material.INK_SAC, 1, 1); //in undamageable items the damage argument is the data. so this would be 35:1
    You'll have to figure out yourself what green dye has for data :O
  4. Green dye is technically an ink sac with a different durability value, so the item stack equivalent would be
    Code (Text):
    ItemStack is = new ItemStack(Material.INK_SAC, 1, (short)10)
    (10 being the durability value for lime dye. Full list here)
  5. Try removing the item by searching for marijuana has its display name.. :)
  6. @Ender_Coder

    How so? I've never tried that before.
  7. Code (Text):
        //remove the item

  8. Code (Text):
        public void onPlayerDeath(PlayerDeathEvent e) {
            if(item.getItemMeta().getDisplayName().equals("┬žaWeek Marijuana")){
    Ok, i've tried your item now how to i register item to the dropped item
  9. I told you how to get all instances of any sort of dye, why are you beating around the bush?
  10. I don't fully understand what if there is more then 1 cactus green in the inventory?
  11. Is this a server where inventory contents are highly controlled and there is no chance that the player would have cactus green that isn't marijuana? If it isn't you could combine both my and @Ender_Coder's methods to make sure that you remove only cactus greens named weak marijuana
  12. So the code should look like
    Code (Text):
        public void onPlayerDeath(PlayerDeathEvent e) {
            e.getDrops().contains(ItemStack is = new ItemStack(Material.INK_SACK, 1, (short)2){
    And no, the server isn't highly controlled.
  13. The first if statement A. doesn't have 'if' and isn't made correctly
    Iterate through the list of drops provided by the event, and compare it to an ItemStack with the exact ItemMeta and data that you want. If they match exactly, remove the ItemStack from the drops
  14. What do you mean?
  15. @FlawlessGaming gj, you completely skipped the first 3 comments which all solved your question.
    • Agree Agree x 1
  16. All this talk about using magic numbers...

    Dye is a MeterialData. You can get MaterialData from an ItemStack.


    Code (Text):

    MaterialData data = itemstack.getData();
    if (!(data instanceof Dye)) {
        return; // not a dyeable itemstack
    Dye dye = (Dye) data;
    if (dye.getColor() != DyeColor.GREEN) {
        return; // not dyed green
    // do something here with green itemstack
    • Agree Agree x 1