Solved Equip Armour error

Discussion in 'Plugin Development' started by Techno, Mar 21, 2014.

Thread Status:
Not open for further replies.
  1. I am making it so that when a player right clicks a sign saying "[Equip]", it will equip Iron Armour on them.

    Code:java
    1.  
    2. package noah.plugins.armourequip;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. public void onEnable() {
    18. // Register
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. public void onDisable() {
    23.  
    24. }
    25.  
    26. // Main
    27. @EventHandler
    28. public void equipS(PlayerInteractEvent equip) {
    29. Player p = equip.getPlayer();
    30.  
    31. if (equip.getClickedBlock() != null) {
    32. if (equip.getClickedBlock().getType() == Material.WALL_SIGN || equip.getClickedBlock().getType() == Material.SIGN_POST || equip.getClickedBlock().getType() == Material.SIGN) {
    33. Sign block = (Sign) equip.getClickedBlock().getState();
    34.  
    35. if (block.getLine(0).equalsIgnoreCase("[Equip]")) {
    36.  
    37. p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    38. p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    39. p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    40.  
    41. p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    42.  
    43. p.sendMessage(ChatColor.RED + "[" + ChatColor.GREEN + "EquipArmour" + ChatColor.RED + "] " + ChatColor.YELLOW + "Armour has been equipped!");
    44.  
    45. }
    46. }
    47. }
    48.  
    49. if (!(p.hasPermission("ArmourEquip.equipsign"))) {
    50. p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You dont have permission!");
    51. }
    52.  
    53. }
    54.  
    55. }
    56.  
     
  2. Offline

    adam753

    Looks fine. What's the error?
     
  3. adam753
    So, I right click the sign and it sends the message, then I hit F5, no armour on me...
     
  4. Offline

    Barinade

    Try p.updateInventory()?
     
    drtshock likes this.
  5. Offline

    Barinade

    Doesn't mean it won't work, deprecation means there is either a better method or it is suggested to not use it, and I'm pretty sure in this case it's deprecated because it's not always needed, only for aesthetics, so it's waste of performance

    I may be wrong, that's just my guess

    Deprecated. This method should not be relied upon as it is a temporary work-around for a larger, more complicated issue.
     
Thread Status:
Not open for further replies.

Share This Page