Solved Giving ItemStacks

Discussion in 'Plugin Development' started by xXRobbie21Xx, Aug 20, 2014.

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

    xXRobbie21Xx

    Okay, despite how shameful writing these are, I am in need of some help. I am writing a guns plugin and i have come to the point in which I need to give specific itemstacks to players.
    So i made an itemstack:
    Code:
    ItemStack bullet = new ItemStack(Material.GHAST_TEAR, 1);
        ItemMeta md = bullet.getItemMeta();
    However when i want to give the player some bullets upon using the custom crafting recipe:
    Code:
    ShapedRecipe basicBullet = new ShapedRecipe(bullet)
                    .shape(" c ", "igi", " r ").setIngredient('c', Material.COAL)
                    .setIngredient('i', Material.IRON_INGOT)
                    .setIngredient('g', Material.SULPHUR)
                    .setIngredient('r', Material.REDSTONE);
            getServer().addRecipe(basicBullet);
        
    I must give them 8 bullets, however you may be wondering why i dont just change the amount in the itemstack. I would do that but i not only need to remove only one bullet upon fireing but i also need to give the player 64 bullets upon executing a command.
    Seen here:
    Code:
    if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getType() == Material.DIAMOND_HOE) {
                    if (p.getInventory().contains(bullet)) {
     
                        if (System.currentTimeMillis() - lastUsed >= coolDownMillis) {
                            cantFire.put(p.getUniqueId(),System.currentTimeMillis());
     
                            Snowball snowball = (p.launchProjectile(Snowball.class));
                            snowball.setVelocity(snowball.getVelocity().multiply(2));
                            p.sendMessage("Works");
           
                            p.getInventory().removeItem(bullet);
                            p.updateInventory();
    
    ... and here:
    Code:
    Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player) sender;
            if (sender instanceof Player) {
                if (commandLabel.equalsIgnoreCase("AmmoStock")) {
                    p.sendMessage("You recieved an ammo drop off!");
                    p.getInventory().addItem(bullet);
                }
            }
           
            return false;
        }
    So, whilst giving the player the itemstack, is it possible to change how much it is depending on the situation? Or does someone know a way around this?
    I would be open to creating multiple itemstacks but in order to keep it fluent im pretty sure i have to only have one (in order for it to work together)
    Any answers are appreciated and if you think you need the whole class, just let me know and ill post it :D
     
  2. Offline

    fandemangas42

    bullet.setAmount(amount);
     
    xXRobbie21Xx likes this.
  3. Offline

    xXRobbie21Xx

    *facepalm*
    Thank you sooo much, haha i should of known it was something small like that but, ya live ya learn
     
Thread Status:
Not open for further replies.

Share This Page