Solved solved

Discussion in 'Spigot Plugin Development' started by hasanas, May 28, 2017.

  1. solved
     
    #1 hasanas, May 28, 2017
    Last edited: Aug 7, 2017
  2. You would have to give the entity a name before you can check for one, Or else It returns null
     
    • Funny Funny x 1
  3. That's obviously not the problem, his IDE its telling him that there is no getName method in the entity class. Also, you don't have to set the entity's name before accessing it.
     
  4. Do what your IDE is telling you.

    There is no getName() method in the Entity class (thats what getDamager() returns, an Entity). Cast it to Player since you already did an instanceof check.

    Code (Text):
    ((Player)e.getDamager()).getName()
     
    • Agree Agree x 1
  5. Yup
     
  6. Mas

    Mas

    Entity does in fact have a getName() method, so the OP maybe using an outdated version.

    If you are really new to Java you should probably learn the language first before attempting to use a Java api. It will help a lot, trust me.
     
  7. Actually, no. It doesn't. It comes from CommandSender which Entity now extends in recent versions of the API.
     
  8. Right now he is learning, one of the best ways to learn is just do it.
     
    • Optimistic Optimistic x 1
  9. Mas

    Mas

    Exactly - so the OP should be able to use #getName() on the entity.
     
  10. Not everyone uses the most up-to-date API. For all you know he's making a plugin for 1.7, so don't assume, and make sure you give correct answers. The answer you keep poking at is the correct answer because his IDE obviously is telling him there is no method there, and is forward compatible so nothing breaks in the newer APIs. ;)