[help needed fast please] its about if a player has a item and a x amount of that item then do

Discussion in 'Plugin Development' started by xguysprison, Jul 19, 2014.

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

    xguysprison

    ok so i have this code (this is only some of it but ) i want to have that if the player has the permisson that i added then if the player has 320 or more tnt in hes inventory then he can do the command or it will say "you need 5 stacks or more of tnt in your inventory to peform this command"

    heres the code :
    Code:java
    1. package me.casper.tntdispen;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.block.Block;
    9. import org.bukkit.block.Dispenser;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class TnT extends JavaPlugin
    18. {
    19. public void onEnable(){
    20.  
    21. }
    22. private int radius = 20;
    23. List<Block> blocks = new ArrayList<Block>();
    24. int tnt = 0;
    25. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    26. if (sender instanceof Player){
    27. Player player = (Player) sender;
    28. if (cmd.getName().equalsIgnoreCase("disp") || cmd.getName().equalsIgnoreCase("dispense")){
    29. if (player.hasPermission("tnttools.disp")){
    30. Block block = player.getWorld().getBlockAt(player.getLocation()), relative;
    31. for (int x = -radius; x < radius; x++) {
    32. for (int y = -radius; y < radius; y++) {
    33. for (int z = -radius; z < radius; z++) {
    34. relative = block.getRelative(x, y, z);
    35. if (relative.getType() == Material.DISPENSER) {
    36. blocks.add(relative);
    37. }
    38. }
    39. }
    40. }


    Traks _LB @Gamesareme @jimuskin ? please i need a way to fix this

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    Traks

    How about this method?
     
  3. Offline

    xmarinusx

    xguysprison
    What is not working?
    What are you trying to do in the code you showed us? It doesn't look like it has anything to do with an inventory...
     
    1Rogue likes this.
  4. Offline

    xguysprison

    xmarinusx what the problem is that i want a way to add it to the code so when a player do /disp if they have to have 5stacks or more of tnt in the players inventory

    so all i baiscly want is someone to give me a code that i can add in so when someone do /disp they need to have 5 stacks or more of tnt to do it

    Traks can you explain it ? like give me a code to add into my code and a way to add it into the code ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    xguysprison Do not tag random forum members, thanks.
     
    _LB likes this.
  6. Offline

    xguysprison

    mbaxter oh sorry but they are not random they all helped me before
     
  7. Offline

    Traks

    The method I linked to returns true if the Inventory object it is invoked on contains at least the input amount of the input material. (input as in, used as parameter for the method) And no, I'm not going to spoon-feed you :)
     
  8. Offline

    xguysprison

    Traks can i do something like this ?
    Code:java
    1. if public boolean contains(TNT, int 320) throws IllegalArgumentException;


    oh and Traks i like spoon-feeding

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    xguysprison

    Traks i cant find a way to connect them after i tryed this like 27 times please help me i cant seem to find a way to connect it to the code
     
  10. Offline

    Traks

    I dislike spoon-feeding for these reasons.
    Anyhow, just invoke Inventory#contains(Material, int) on the object returned by Player#getInventory()... Player would be the CommandSender parameter, the material Material.TNT and the amount 320. It kind of startles me that you were capable of writing the piece of code in the original post, while not being able to correctly invoke a method shown in a file on Github...
     
Thread Status:
Not open for further replies.

Share This Page