Unbreakable tools revisited

Discussion in 'Spigot Plugin Development' started by spinnekoppie, May 29, 2016.

  1. I have been searching for a way to make an unbreakable sword. It seems that it should be quite easy with the following code:
    Code (Text):

             ItemStack sword = new ItemStack(Material.IRON_SWORD);
             ItemMeta meta = sword.getItemMeta();
             meta.spigot().setUnbreakable(true);
             meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
     
    However, spigot() seems to be undefined. Can someone perhaps give me some advice? I'm obviously missing out something here but I don't know what.
     
  2. Won't it work if you just set the Item Durability to maybe 99999?
    That's the first thing I could think of.
     
  3. If you're building against the spigot api or server jar it should be there. o_O
     
  4. Attach the server jar to the buildpath instead of the api
     
  5. Not gonna be worth your time to mess with it
    Code (Text):

      public static class Spigot
      {
          public void setUnbreakable(boolean unbreakable)
          {
              throw new UnsupportedOperationException("Not supported yet.");
          }
     
          public boolean isUnbreakable()
          {
              throw new UnsupportedOperationException("Not supported yet.");
          }
      }
     
     
  6. I found the problem. I had the spigot source code for 1.9.2 and the external jar for 1.9.4, not realising that the source code takes priority! I removed the source code and now it is okay. Thanks for all your help though. Can kick myself ...
     
  7. Code (Text):
    ItemStack stack = new ItemStack(Material.DIAMOND_SWORD);

                        stack.getItemMeta().spigot().setUnbreakable(true);
    I don't test it, but i think it work!