Questions

Discussion in 'Plugin Development' started by Crafted Evil, Jan 11, 2014.

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

    Crafted Evil

    Hello, I'm making a plugin that when you execute a command your inventory is set with armour and your given some potions and weapons, but I don't exactly know how to give a player potions (not the effects)
    Here is my code so far:
    Code:java
    1. if(args.length == 1) {
    2. if(args[0].equalsIgnoreCase("medic")) {
    3. if(p.hasPermission("kitpvp.kit.medic")) {
    4. p.getInventory().clear();
    5. p.getInventory().setArmorContents(null);
    6. p.getInventory().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
    7. p.getInventory().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
    8. p.getInventory().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
    9. p.getInventory().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
    10. Potion pt = new Potion(PotionType.INSTANT_HEAL, 2);
    11. ItemStack item = pt.toItemStack(1);
    12. p.updateInventory();
    13. } else {
    14. p.sendMessage(prefix + ChatColor.RED + "Sorry, you don't have permission to use this kit!");
    15. }
    16. }
    17. }
    18.  
    19. return false;
    20. }
    21. }
    22.  
     
  2. Offline

    Minecrell

    Crafted Evil
    Add the potion item stack to the inventory?
    Code:java
    1. p.getInventory().addItem(item);
     
  3. Offline

    Crafted Evil

  4. Offline

    Minecrell

    Where did you add it?
     
  5. Offline

    Crafted Evil

    Minecrell
    Code:java
    1. Potion pt = new Potion(PotionType.INSTANT_HEAL, 1);
    2. Potion pt1 = new Potion(PotionType.INSTANT_HEAL, 2);
    3. ItemStack item = pt.toItemStack(2);
    4. ItemStack item1 = pt1.toItemStack(1);
    5. p.getInventory().addItem(item);
    6. p.getInventory().addItem(item1);
    7. p.updateInventory();
     
  6. Offline

    Minecrell

    Crafted Evil
    And that's not working? :O
    It should work actually... Do you get the armor added to your inventory?
     
  7. Offline

    Crafted Evil

    Minecrell Yeah it adds the armor but not the potions.
     
  8. Offline

    Maurdekye

    p.updateInventory() is deprecated, by the way. See if getting rid of that helps.
     
  9. Offline

    Crafted Evil

    What do you mean? Remove p.updateInventory() ?
     
  10. Offline

    Blingdaddy1

  11. Offline

    Crafted Evil

    Blingdaddy1 Well p.updateInventory() is used to update inventory because some of the time the items won't display in inventory, so how does that exactly work? Wouldn't that be a negative on it?
     
  12. Offline

    Maurdekye

    No, it's integrated into the inventory functions now, there's no need to use it. Just remove the line.
     
  13. Offline

    Drkmaster83

    Meeeeeeeh. I wouldn't say 'integrated.' It's a good habit to use it, even though it may not necessarily perform its functions. Inventories can be really glitchy.

    There's literally no reason why it shouldn't add the potion to your inventory (unless the Potion.toItemStack() method doesn't work).
     
Thread Status:
Not open for further replies.

Share This Page