Giving a player Armour and forcing them to wear it

Discussion in 'Plugin Development' started by skipperguy12, Sep 23, 2012.

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

    skipperguy12

    How do I automatically give a player Armour that automatically goes on?
    What if I also want it to be enchanted?

    Lets say I have:

    Code:
    if(args[0] == "heavy"){
                                              player.sendMessage(ChatColor.AQUA + "[Kit]" + ChatColor.RED + "You are now a Heavy!");
                                              //Give stuff...
                                          }
    Where it says: //Give stuff, how do I give them diamond Armour and a diamond sword and force the Armour on?

    Also, there will be multiple kits, so what do I do to clear their Armour and sword when they choose another kit?
     
  2. Offline

    skipperguy12

  3. Offline

    Zidkon

    You need help with that or you need to learn Java?

    Plz specify wich help...
     
    tommycake50, ferrybig and d33k40 like this.
  4. Offline

    d33k40

    I made this plugin a while, but I'm not going to post the code because I do not agree with the copy paste without learning, ferrybig show you the way to do that and your answer was that... when all the necesary is in that place.

    Learn Java and when you learn the basics come back.

    good luck
     
  5. Offline

    MYCRAFTisbest

    (Player (<sender>)).getPlayer().getHelmet().setType(Material.DIAMOND_HELMET);

    this should give a player a diamond helmet in the helmet slot
    if u cant figure it out from this, i wish you good luck then
     
  6. Offline

    skipperguy12

    Thanks! Also, I know the basics of java, just I suck at figuring out what to do with the Java docs :p
     
  7. Offline

    MYCRAFTisbest

    lol well im glad i helped. As for enchantment though i am unsure. I am still trying to figure that out. I actually made a seprate post to give a player an enchanted sword. If you find out before me, just tell me.
     
  8. Offline

    skipperguy12

    I got it, but I can't add enchantments... Like:


    player.getInventory().addItem(new ItemStack(Material.BOW,1).addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 2));

    Error:
    The method addItem(ItemStack...) in the type Inventory is not applicable for the arguments (void)

    Oh sorry... I asked the question without refreshing the page. I will wait until you or someone else help me. :D

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

    MYCRAFTisbest

    lol. I hope someone helps soon.
     
  10. Offline

    MCForger

    Idea. You could make an item like when making a crafting recipe be enchanted and you give it in a quantity. I will post code here as soon as I try it.
     
  11. Offline

    MYCRAFTisbest

    someone posted that on my page
     
  12. Offline

    MCForger

    Yes I did this for adding stuff like this.
    Code:
    ItemStack shovel = new ItemStack(Material.GOLD_SPADE, 1);
    shovel.addEnchantment(Enchantment.DURABILITY, 3);
     
  13. Offline

    MYCRAFTisbest

    Ik how to do that. That isn't what we want
     
  14. Offline

    MCForger

    No but that is an example on how to do it. I have code that uses this and applies enchanted amour to the playere with what I stated above except it isnt using a shovel but instead a leather chestplate.
     
  15. Offline

    MYCRAFTisbest

    Yes and i have this: http://dev.bukkit.org/server-mods/realisticchat/

    Which gives gold helmets the enchantment digspeed altogether. Plus i think i figured it out now

    Will reply if works

    i did it! here is my code!

    Code:
    public class BukKitPVP extends JavaPlugin implements Listener {
        final private static Enchantment SHARPNESS = Enchantment.DAMAGE_ALL;
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("PVP")){
               
            if (player.getPlayer().hasPermission("kit.used")){
                player.sendMessage(ChatColor.YELLOW + "You already chose your kit.");
                }
            else{
                ItemStack swordItem = new ItemStack(Material.DIAMOND_SWORD, 1);
                swordItem.addEnchantment(SHARPNESS, 1);
                player.getPlayer().setItemInHand(swordItem);
                //player.getPlayer().getItemInHand().setType(Material.DIAMOND_SWORD);
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " 282 27");
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + player.getName() + " add kit.used");
            }
        }
           
     
            return true;
            }
    That will give u 1 diamond sword with sharpness 1

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

    Zidkon

    Let's give a little help, at the Player class you can find a method that is called getInventory(), that returns a PlayerInventory object, that PlayerInventory class have a methods called setArmorContents(ItemStack[] stack).

    So you can basically create an ItemStack[3] and put all the things inside, I believe the first one (the 0 index value on the list), goes to the head, and the last (the 3 index value on the list) one goes to the boots.

    What you create at the ItemStacks is up to u.

    Ok I did your homework, but u should do it yourself if u will public this plugin for others to use, u don't want anybody to use a mess plugin that can probably mess up their servers or their other plugins, common.....
     
  17. Offline

    MYCRAFTisbest

    I just noticed that this is probably wrong. It should be
    (Player (<sender>)).getPlayer().getInventory.getHelmet().setType(Material.DIAMOND_HELMET);
     
  18. Offline

    skipperguy12

    Yea, it was, but I got it after a few minutes anyways :p

    Actually, that's wrong too... Its:

    Code:
    player.getPlayer().getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  19. Offline

    Zidkon

    I love you are studying :D
     
  20. Offline

    MYCRAFTisbest

    sry, i am tired lol
     
  21. Offline

    Codex Arcanum

    I know you are doing other things right now, but if you want to stop the player from removing his armor, you should listen for the InventoryClickEvent, and do event.setCancelled(true) if event.getSlotType() == SlotType.ARMOR.
     
  22. Offline

    shmkane

    Player player = (Player) sender;
    ItemStack Helm = new ItemStack(Material.IRON_HELMET);
    player.getInventory().setHelmet(Helm);
    Nuff Said
     
  23. Offline

    skipperguy12

    shmkane
    Dude, this is OLD.

    Also, that's 3 lines, I one line'd it:
    player.getPlayer().getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    By the way, i've gotten much better at Java since this, I am now into Java game development.
     
    russjr08 and kreashenz like this.
Thread Status:
Not open for further replies.

Share This Page