Solved What is the java code needed for armour repair in my hand with a command?

Discussion in 'Plugin Development' started by Tyler Christensen, Dec 7, 2013.

Thread Status:
Not open for further replies.
  1. Im writing a plugin that heals, feeds, and repairs armour, does anyone know what is needed for the java code in eclipse to repair armour? wether it be in your hand, or on your body?
     
  2. Offline

    Wolfey

    You want to repair everything in your inventory and your equipment? If so here it is:
    PS: Haven't tested it out yet, doing it right now.
    Code:java
    1.  
    2. public void repairAll(Player p) {
    3. for(ItemStack items : p.getInventory().getContents()) {
    4. if(items instanceof Repairable) {
    5. items.setDurability((short)0);
    6. }
    7. }
    8. for(ItemStack items : p.getEquipment().getArmorContents()) {
    9. if(items instanceof Repairable) {
    10. items.setDurability((short)0);
    11. }
    12. }
    13. }
    14.  
     
    Jomens235 likes this.
  3. Thanks :D

    the repairAll after public void on line 2 is not a proper void type

    repairAll in line 2 is not a void type, and how would i hook it into a command?

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

    Jentagh

    Code:java
    1. import org.bukkit.command.Command;
    2. import org.bukkit.command.CommandSender;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.inventory.ItemStack;
    5. import org.bukkit.inventory.meta.Repairable;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public final class YourPlugin extends JavaPlugin
    9. {
    10. @Override
    11. public void onEnable()
    12. {
    13. getLogger().info("Enabled");
    14. }
    15. @Override
    16. public void onDisable()
    17. {
    18. getLogger().info("Disabled");
    19. }
    20.  
    21.  
    22. public void repairAll(Player p) {
    23. for(ItemStack items : p.getInventory().getContents()) {
    24. if(items instanceof Repairable) {
    25. items.setDurability((short)0);
    26. }
    27. }
    28. for(ItemStack items : p.getEquipment().getArmorContents()) {
    29. if(items instanceof Repairable) {
    30. items.setDurability((short)0);
    31. }
    32. }
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    36. if(sender instanceof Player) {
    37. Player player = (Player) sender;
    38. if(cmd.getName().equalsIgnoreCase("yourcommand")) {
    39. repairAll(player);
    40. }
    41. }
    42. return false;
    43. }
    44. }
     
    Tyler Christensen likes this.
  5. Jentagh YOUR AWESOME! Thanks man!
     
  6. Offline

    Wolfey

    But... I wrote the code :(

    Jking, I'm not that greedy, have fun with future plugin making!
     
  7. Thanks,! if you wanna know whats its for, its a plugin call renewal, u can feed, and heal yourself, and repair your armour, this is my first plugin i have ever made, and i think its turning out well :D i just wasnt sure of how to put the coding since this is only my 4th time writing somthing in java language.

    Thanks for all the help :D
     
  8. Offline

    Jentagh

    No problem Tyler Christensen . Glad I could help. Sorry Wolfey , I was just implementing it into a simple little plugin thingy :D Kudos to you for making the simple yet efficient method!
     
Thread Status:
Not open for further replies.

Share This Page