1.8.8 Check if player inventory has a stained glass

Discussion in 'Spigot Plugin Development' started by Jooppe, Jun 4, 2021.

  1. Hey, I have a litle problem while doing shop system to 1.8.8 -version.

    The problem is, how should I check if player has stained glass or something else colored in their inventory?

    Heres the code (https://pastebin.com/CyzsPNqN)
     
  2. In the code I have two different ways to check the player inventory, but they aren't working so..
     
  3. not containsAtLeast use equals
     
  4. Umm, how should I use it then? I haven't never tried it.
     
  5. The Problem in 1.8 is, that you cant just say white_stained_glass or red_wool. You have to define it in an other way but I forgot how to do it (I didnĀ“t make many 1.8 Plugins), sorry mate!
     
  6. You're making a brand new ItemStack and comparing it to what's in the player's inventory. I assume that since the Java objects are different, it won't work. I would loop through the player's inventory, check the material type, and then check the data (color) value.
     
  7. Maybe iterate through the inventory?
    Code (Java):

    for (ItemStack i : p.getInventory()) {
        if (i.getType() == Material.STAINED_GLASS) {
            // do your thing
        }
    }
     
    P.S. Not tested, probably it's p.getInventory().getContents().
     
    #7 ZBLL, Jun 5, 2021
    Last edited: Jun 5, 2021
    • Agree Agree x 1