Question about determining Entity Type

Discussion in 'Plugin Development' started by Taien, Mar 24, 2012.

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

    Taien

    I have a work system I'm developing for my server where some types of creatures killed can reward work credit. The problem I'm having is that I'd like to store list list of creatures for each work type in a Map, but I can't find a way to easily represent different Entity types in a list like that. Anyone have any insights or ideas?
     
  2. Offline

    Darkman2412

    Do you mean the enum EntityType? :)
     
  3. Offline

    Eegabooga

    It sounds like an Enum would be what you are looking for. With Enums in Java you can have method calls with them, so your program could have an Enum that looks something like:
    Code:java
    1. public enum EntityPoints {
    2. int points;
    3.  
    4. ZOMBIE(5),
    5. CREEPER(10),
    6. // other entities
    7.  
    8. public EntityPoints(int points) {
    9. this.points = points;
    10. }
    11.  
    12. public int getPoints() {
    13. return points;
    14. }
    15. }


    And then that way you can just simply get the amount of points for an Entity like this:
    Code:java
    1. public int getPoints(EntityPoints entity) {
    2. return entity.getPoints();
    3. }
     
  4. Offline

    Taien

    This is exactly what I was looking for.
    Another good way to do it :) Thanks
     
Thread Status:
Not open for further replies.

Share This Page