Solved Inventory Check

Discussion in 'Plugin Development' started by tovd1234, Oct 25, 2014.

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

    tovd1234

    Hello everybody, I'm making a plugin atm. If you type in /block it will convert all your items that can be crafted into a block in a block. FE If you have 9 diamonds and execute /block, you'll get 1 diamond block. I'm stuck at checking if the player has an certaint item (Diamond, iron, gold etc.).

    Code:java
    1. package nl.tovd1234.blocker;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Main extends JavaPlugin implements Listener {
    10.  
    11. public void onEnable() {
    12. getServer().getPluginManager().registerEvents(this, this);
    13. getLogger().info("Blocker Plugin Enabled! - By tovd1234");
    14. }
    15.  
    16. @Override
    17. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    18. Player player = (Player) sender;
    19. if (cmd.getName().equalsIgnoreCase("block")) {
    20. if (player.hasPermission("b.block"))
    21. player.getInventory();
    22. if (Player) //I'm stuck here
    23. }
    24. return false;
    25. }
    26. }
    27.  


    Does anyone know how I can check the players inventory for a certaint block and craft them into blocks?

    Thanks.
     
  2. Offline

    CraftCreeper6

    tovd1234
    if(p.getInventory().hasAtLeast(myItem,...)){
    // Do this
    }
     
  3. Offline

    tovd1234

    CraftCreeper6

    I already found out how to do it. Its very easy. Thanks for the help though!

    Code:java
    1. if (player.getInventory().contains(Material.DIAMOND)){
    2.  
    3. }
     
Thread Status:
Not open for further replies.

Share This Page