How to Remove Durability from the Current Durability

Discussion in 'Spigot Plugin Development' started by Th3Wh1teG0d, Jan 8, 2020.

  1. Hello, I am trying to remove 1 Durability from the Current Durability of an Item but I fail...

    Im using:
    Code (Java):
     itemInHand.setDurability((short) (itemInHand.getDurability() -1));
    Any idea how i can fix this ?

    Im using 1.12.2
  2. i think durability should count upwards, iE the more durability you have the closer the item is to breaking.
  3. Without the - Eclipse tell me thats not going to work
  4. Why don't you read the Javadoc and see why the method is deprecated. Use the alternatives.
    Don't know about the durability (deprecated), but with damage (not deprecated) it's correct.
    • Like Like x 1
  5. Where i can find this Javadoc or can you tell me some code ?
  6. This is for 1.15.1 and im using 1.12.2 i dont think thats going to work
  7. This interface was already present a long time ago. So this works.

    Edit: Wow was the API shitty before flattening. Forgot that since it is multiple years ago.
    #8 ysl3000, Jan 8, 2020
    Last edited: Jan 8, 2020
  8. I think it should work.
    If it doesn't, the method was probably not deprecated at the time and @Blutkrone's point is what you're looking for.
    (Or you have an issue with the code)
  9. When im doing:

    Code (Java):
     final Damageable dmg = (Damageable) itemInHand.getItemMeta()

    ((EntityDamageEvent) dmg).setDamage(((EntityDamageEvent) dmg).getDamage() - 1);
    im getting this error:

    Code (Text):

    [12:27:17 ERROR]: Could not pass event PlayerInteractEvent to Airsoft v1.0
    org.bukkit.event.EventException: null
            at$1.execute( ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$ [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at java.util.concurrent.Executors$ Source) [?:1.8.0_231]
            at Source) [?:1.8.0_231]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C( [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at Source) [?:1.8.0_231]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem cannot be cast to org.bukkit.entity.Damageable
            at de.th3wh1teg0d.guns.Weapon.onInteract( ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at$1.execute( ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
            ... 18 more
  10. You're importing the wrong interface. There are two named Damagable
  11. I can only import import org.bukkit.entity.Damageable;
  12. What do i have to do with this ?
  13. This is the class you need.
    1.12 is not supported by spigot, and no one here is going to dig for old methods to do it in 1.12.
    If you want to use a long outdated version, you will have to do the research on your own.
    There are some websites that hold outdated javadocs.
    • Agree Agree x 1
  14. It is not long outdated... Many people are still using the 1.8.9 ...
  15. The fact that people are using even older versions doesn't mean 1.12 isn't outdated, it's from 2+ years now and much has changed.
    • Agree Agree x 1
    • Optimistic Optimistic x 1