GetType() equivalent for Entity?

Discussion in 'Plugin Development' started by Reil, Feb 28, 2011.

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

    Reil

    I have a plugin which hooks entity events. Blocks have a getType function which returns a convenient enumeration result. Do entities have the equivalent? I can't seem to find it buried in the javadocs. The enumeration exists, but there isn't a function to find the value of any field that would be in an entity...
     
  2. Offline

    LRFLEW

    Not really, but there is an alternative. All entity types, including the broad type entity, are all interfaces, so an entity is an interface of all the other types. Use
    Code:
    if (Entity instanceof EntityType)
    to find if it's of a type and
    Code:
    (EntityType)Entity
    to cast it as the type it is.
     
  3. Offline

    Reil

    I found an interesting, if hackish way of getting a mob's name without relying on ugly cascading ifs!

    Code:
    String targeter = entity.getClass().getName();
    targeter = targeter.substring(targeter.lastIndexOf("Craft") + "Craft".length());
    The getClass().getName() combo returns something like:
    org.bukkit.craftbukkit.entity.CraftCreeper.CraftCreeper

    The second line cuts off everything before the mob name!

    Code is in use in new MonsterTriggers plugin.
     
Thread Status:
Not open for further replies.

Share This Page