Solved Sign Armor

Discussion in 'Plugin Development' started by King_Amun_Ra, Dec 1, 2013.

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

    King_Amun_Ra

    Can anyone tell me why this will not work. the setchestplate ext. will not work but I can give Items though just not set there armor
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3.  
    4. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5.  
    6. Block block = event.getClickedBlock();
    7.  
    8. if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
    9.  
    10. Sign sign = (Sign) block.getState();
    11. String[] line = sign.getLines();
    12. if(line[0].equalsIgnoreCase("§fIron Golem")){
    13. if(event.getPlayer().hasPermission("pvp")) {
    14. event.getPlayer().getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    15. event.getPlayer().getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    16. event.getPlayer().getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    17. event.getPlayer().getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    18.  
    19. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 10000000, 1000000));
    20. event.getPlayer().sendMessage(ChatColor.GOLD + "You have been given a kit!");
    21. }
    22. }
    23. }
    24. }
    25.  
    26.  
    27. }
    28.  
     
  2. Offline

    masons123456

    King_Amun_Ra
    Is it erroring, and are you sure the code is running?
     
  3. Offline

    _Skyden_

    Have you tried updating the player's inventory? It would also be a good idea to store the player in a variable so you don't need to keep getting the player.
     
  4. Offline

    King_Amun_Ra

    Yeah updating the inventory worked. Is there a way I don't need to make them update it. also I did have it as a variable but this was before I cleaned up my code a little. But its basically the same it just you can read it a little better.
     
  5. Offline

    MrGermanrain

    Code:java
    1. //Shouldn't this work:
    2.  
    3. p.getInventory.add(new ItemStack(item, amount));
    4.  
    5. //or an array:
    6.  
    7. ItemStack[] items = {new ItemStack(item), new ItemStack(item)};
    8. player.getInventory().addItem(items);
     
  6. Offline

    King_Amun_Ra

    @MrGermanraid No I need help updating there
    No I just need help updating there inventory
     
  7. Offline

    iiHeroo


    Define this:
    Code:
    Player p = event.getPlayer();
    then add the armor with p.getInventory()

    and after you add all the armor do

    Code:
    p.updateInventory();
    It's deprecated but works.
     
  8. Offline

    MrGermanrain

    p.updateInventory();

    It is deprecated but should still work.

    haha... Posted same minute ;)

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

    King_Amun_Ra

    Ok I never even saw the player update
     
  10. Offline

    iiHeroo


    Solved then :D?
     
  11. Offline

    King_Amun_Ra

    Yep Thanks
     
  12. Offline

    Garris0n

    For the record, you should use ChatColor, not § color codes.
     
Thread Status:
Not open for further replies.

Share This Page