.getType() not working?

Discussion in 'Plugin Development' started by ScottieD, Mar 1, 2012.

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

    ScottieD

    Nothing i do can ever get it to work, and as far as i know I am using it properly.
     
  2. Offline

    stelar7

    give an example of how you use it?
     
  3. Offline

    ScottieD

    When I replace the code with true, everything works fine, except it effects all entities.
    All imports are as should be.
    Code:
    for (Entity e : player.getNearbyEntities(50d, 50d, 50d)) {
                    if (e.getType() == EntityType.SLIME) {  //code that works fine}}
     
  4. Offline

    stelar7

    this should work fine...
    Code:java
    1. for (Entity e : player.getNearbyEntities(50d, 50d, 50d)) {
    2. if (e.getType() == EntityType.SLIME) {
    3. player.sendMessage("There is a Slime near you!");
    4. }
    5. }
     
  5. Offline

    ScottieD

    It's the same code i posted.
    e.getType() just doesn't want to work.
     
  6. Offline

    acuddlyheadcrab

    Funny enough, there's no getType() method under the Entity.class. It's kind of annoying.

    Using entity.toString() may work well enough. Besides that, try getEntityId().
     
  7. Offline

    stelar7

    It is, look @ the JavaDocs
     
  8. Offline

    acuddlyheadcrab

    Yeah.. that's true. It should be working, but on my computer's eclipse, Entity e does not define getType()... It's been like that for me for a while.. I'll check the actual class files in my Bukkit API jar
     
  9. Offline

    stelar7

  10. Offline

    ScottieD

    Anytime I use getType(), it explodes.
     
  11. Offline

    acuddlyheadcrab

    Yup, only the newer API versions have getType() in the Entity.class file. I checked the Entity.class in Bukkit 1.1 R4 and it didn't have it.
     
  12. Offline

    JayEffKay

    ScottieD
    Yeah that's right, I had to make a workaround function to make this work on R4, but I'm certainly not the first one who did this. I guess it'll be fixed soon. Here's the preview thread.

    For now you can use this, but this will miss the new creatures of the next update, so add those or replace this with the new function (if it's working by then).
    Code:
        private Enum <CreatureType> getCreatureType(Entity e) {
            if (e instanceof Blaze) return CreatureType.BLAZE;
            if (e instanceof CaveSpider) return CreatureType.CAVE_SPIDER;
            if (e instanceof Chicken) return CreatureType.CHICKEN;
            if (e instanceof Cow) return CreatureType.COW;
            if (e instanceof Creeper) return CreatureType.CREEPER;
            if (e instanceof EnderDragon) return CreatureType.ENDER_DRAGON;
            if (e instanceof Enderman) return CreatureType.ENDERMAN;
            if (e instanceof Ghast) return CreatureType.GHAST;
            if (e instanceof Giant) return CreatureType.GIANT;
            if (e instanceof MagmaCube) return CreatureType.MAGMA_CUBE;
            if (e instanceof MushroomCow) return CreatureType.MUSHROOM_COW;
            if (e instanceof Pig) return CreatureType.PIG;
            if (e instanceof PigZombie) return CreatureType.PIG_ZOMBIE;
            if (e instanceof Sheep) return CreatureType.SHEEP;
            if (e instanceof Silverfish) return CreatureType.SILVERFISH;
            if (e instanceof Skeleton) return CreatureType.SKELETON;
            if (e instanceof Slime) return CreatureType.SLIME;
            if (e instanceof Snowman) return CreatureType.SNOWMAN;
            if (e instanceof Spider) return CreatureType.SPIDER;
            if (e instanceof Squid) return CreatureType.SQUID;
            if (e instanceof Villager) return CreatureType.VILLAGER;
            if (e instanceof Wolf) return CreatureType.WOLF;
            if (e instanceof Zombie) return CreatureType.ZOMBIE;
            return null;
        }
    
    edit: suggest you add the word 'creature' to the topic for future reference
    edit2: I mean 'entity', I'm afraid I misunderstood, although the principle should be the same
     
Thread Status:
Not open for further replies.

Share This Page