Solved Why doesn't my plugin work?

Discussion in 'Plugin Development' started by Voidisms, Mar 22, 2021.

Thread Status:
Not open for further replies.
  1. Offline


    So I have a code where it checks a player's inventories for Bedrock, if it finds bedrock it will remove it. When I tested the plugin it did say in the console it loaded successfully but when attempting to test it out by giving myself one bedrock it didn't work. I checked all possible solutions I checked my YAML folder and it was fine. What went wrong? There was also no errors or anything that has the unused warning
    for(ItemStack itemStack : player.getInventory().getContents()) {
                  if( itemStack != null && itemStack.getType() == Material.BEDROCK) {
  2. Offline


    @Voidisms You should remove the item, not set the amount to 0. I would loop the slots.
    1. // Loop the inventory slots
    2. for (int i = 0; i < inventory.getSize(); i++) {
    3. // Get the item in the current iteration's slot
    4. ItemStack item = inventory.getItem(i);
    6. // Make sure the slot is not empty and is bedrock
    7. if (item == null || item.getType() != Material.BEDROCK) continue;
    9. // Set the slot to be empty
    10. inventory.setItem(i, null);
    11. }
    Last edited: Mar 23, 2021
    davidclue likes this.
  3. Offline


    Agreed, but it should be inventory.setItem(i, null); at the end there.
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page