Solved Can't cast Entity to Guardian

Discussion in 'Plugin Help/Development/Requests' started by Dyukusi, Jan 14, 2015.

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

    Dyukusi

    I tried to cast Entity to Guardian to check wether it is elder guardian or not but it seems doesn't cast correctly.

    Code:
    @EventHandler
        void EntitySpawn(CreatureSpawnEvent event) {
           
            if (event.getEntityType().equals(EntityType.GUARDIAN)) {
                Guardian g = (Guardian) event.getEntity();
               
                if(g.isElder()){
                    //blah blah
                }
               
            }
        }
    
    When Guardians are spawned, I got this error message.

    Code:
    java.lang.NoSuchMethodError: org.bukkit.entity.Guardian.isElder()Z
    I think this means the instance of Guardian doesn't implemented isElder() method.
    However, the entity is definitely Guardian because I checked first as you can see.
    Does anybody have an idea?

    Sorry for if my English awful, I'm not native English speaker.
    Thank you for help.
     
  2. Offline

    Skionz

    @Dyukusi Is your IDE notifying you of a syntax error? Are you using the same version of Bukkit as your server is?
     
  3. Offline

    Dyukusi

    There is no syntax error notification and I'm using same version of Bukkit with my server.
    Thank you for replying.
     
  4. Offline

    nverdier

    @Dyukusi I think you would check the Variation of the Guardian if it's elder... Not really sure though.
     
  5. Offline

    Dyukusi

    hmm.. you mean maybe there is other ways to check wether elder or not by see the variations between guardian and elder guardian?
     
  6. Offline

    nverdier

    @Dyukusi Take a look at this. Debug, see what #isElder() is returning.
     
  7. Offline

    Dyukusi

    It'll return boolean that just means that the instance is elder guardian or normal guardian.
    It's not a return variable problem but the Guardian instance doesn't implement isElder() method so I cant even check the return value.
     
  8. Offline

    nverdier

    @Dyukusi Why don't you think it implements it? Have you tested?
     
  9. Offline

    Dyukusi

    You mean isElder() method may possibly haven't been implemented yet?
    I haven't think about that and haven't test.
    hmm...I wanna check that but I have no idea because I guess it also needs to cast Entity to Guardian to check the method is wether valid or not.

    Thank you for the idea.
     
  10. Offline

    nverdier

    @Dyukusi I'm assuming you're using a 1.8 library? isElder is implemented if you're using a 1.8 library. What's the problem with casting?
     
  11. Offline

    Dyukusi

    Yeah I'm using 1.8 Library.

    Code:
    <repository>
        <id>spigot-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
    </repository>
    
    <dependency>
        <groupId>org.bukkit</groupId>
        <artifactId>bukkit</artifactId>
        <version>1.8-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    And I know it's 1.8 server by executing /version command in my server.
    Code:
    This server is running CraftBukkit version git-Bukkit-"8110f51" (MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT)
    There is no error to cast Entity to Guardian but when isElder() method executed,
    Code:
    java.lang.NoSuchMethodError: org.bukkit.entity.Guardian.isElder()Z
    this error is occurred.

    Guardian class is just interface class so I guess this means the Entity instance doesn't implement isElder method even though the Entity is Guardian. : q
    Can you cast Entity to Guardian and use isElder method in your server?
     
  12. Offline

    Avygeil

    @Dyukusi Guardian API was implemented on December 12th, so chances are that your server's version is way behind your API version. Update Spigot and tell us if you still get the error. :)
     
  13. Offline

    Dyukusi

    I see, I had thought my server is latest version.
    I'll try to update it and check this problem.
    Thank you for the idea.

    If solved, I'll post again.

    It seems work well after update server.
    Sorry I was stupid. : q

    Skionz, nverdier, Avygeil.
    Thank you for help.
    Really helpful for me.

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

Share This Page