Return type incompatible with Damageable

Discussion in 'Plugin Development' started by EnvisionRed, Nov 12, 2013.

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

    EnvisionRed

    Right now I'm digging into CraftBukkit and nms code to create some custom entities, but I'm encountering a very strange error. I've created an interface that extends EntityLiving in the format as shown here: http://pastebin.com/VHBv6Nw6

    I've then created a class that implements it and extends CraftLivingEntity, here's the relevant source snippet for that: http://pastebin.com/7KhwuNp7

    Eclipse is telling me that the return types for my implemented methods (declared in a bukkit interface -- why would they be wrong?) is incompatible with the Damageable superinterface. The strange thing is that Damageable does in fact have the same return types as I am listing in my method definitions (which should when I have the method body as a wrapped call to the CraftLivingEntity superclass, or if I casted "this" to Damageable and called the methods directly).

    I've tried it with a few seperate Craftbukkit builds but to no avail. If anyone can shed some insight on this manner, that would be great.


    UPDATE: I decompiled the Damageable class from the craftbukkit build I'm referencing (1.6.4-R2.0) and the source looks like this:
    Code:java
    1. package org.bukkit.entity;
    2.  
    3. public abstract interface Damageable
    4. extends Entity
    5. {
    6. public abstract void damage(double paramDouble);
    7.  
    8. @Deprecated
    9. public abstract void damage(int paramInt);
    10.  
    11. public abstract void damage(double paramDouble, Entity paramEntity);
    12.  
    13. @Deprecated
    14. public abstract void damage(int paramInt, Entity paramEntity);
    15.  
    16. public abstract double getHealth();
    17.  
    18. @Deprecated
    19. public abstract int getHealth();
    20.  
    21. public abstract void setHealth(double paramDouble);
    22.  
    23. @Deprecated
    24. public abstract void setHealth(int paramInt);
    25.  
    26. public abstract double getMaxHealth();
    27.  
    28. @Deprecated
    29. public abstract int getMaxHealth();
    30.  
    31. public abstract void setMaxHealth(double paramDouble);
    32.  
    33. @Deprecated
    34. public abstract void setMaxHealth(int paramInt);
    35.  
    36. public abstract void resetMaxHealth();
    37. }
    38.  


    I'm not seeing the return type incompatibility, and I don't know why eclipse is.
     
  2. Offline

    Xacero

    EnvisionRed
    Can we see the method where you call getLastDamage() ?
    Also you can paste code here and have syntax highlighted using

    Code:java
    1. [syntax=java] /*oh look some code */ [/syntax]
     
  3. Offline

    EnvisionRed



    It's not that I would be calling the function (in all honesty, I probably wouldn't) but I need to implement it since I'm using LivingEntity as a superinterface. I can't compile my project because I'm running into an Eclipse/compiler error, not a runtime error as your question would suggest.
     
  4. Offline

    Xacero

    EnvisionRed
    Code:java
    1. public double getLastDamage() {
    2. return super.getLastDamage();
    3. }
    4.  
    5. public int getLastDamage() {
    6. return super.getLastDamage();
    7. }


    Try this?
     
  5. Offline

    EnvisionRed


    Doesn't work. Together, it complains of a duplicate function and a wrong return type on the double version. With the int version on its own, it tells me to change the return type to double.
     
  6. Offline

    Xacero

    EnvisionRed
    [​IMG]

    I see what you mean... That's very strange, not sure why that's happening.
    I even tried getting the value myself from the handle and when that didn't work tried returning a constant value instead of the super function ... All had the same issue...
     
  7. Offline

    EnvisionRed

    It's not only getLastDamage(), but also getHealth() and getMaxHealth(). I'm thinking of creating a maven script and building w/ that instead to see if it fixes the issue.
     
  8. Offline

    Xacero

    EnvisionRed
    Code:java
    1.  
    2. public double getLastDamageCustom() {
    3. return super.getLastDamage();
    4. }


    Depending on what you'll be doing with the class that might also be a viable solution, I'm sorry I couldn't be of more assistance. :(
     
  9. Offline

    EnvisionRed

    Nope, it's not. Technically I shouldn't have to implement those functions at all (since they're implemented publically in a superclass) and the only reason I have to override them at all is because the compiler's getting antsy about nothing.

    I found something of a fix: reference both the bukkit and craftbukkit.jars and use something like 7-zip to delete all bukkit classes and packages from the craftbukkit.jar

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page