[Solved]Little problem with enums

Discussion in 'Plugin Development' started by blackwolf12333, Aug 19, 2012.

Thread Status:
Not open for further replies.
  1. Hi all,
    I have an enum called Events, it contains a few events like BREAK, PLACE, etc.
    All these events have a name given in the constructor, and that name variable also has it's getters and setters.
    Now what i wanted was a method to get the event from it's name, so i wrote this method:
    Code:java
    1.  
    2. public static Events getEvent(String name) {
    3. for(Events event : Events.values()) {
    4. if(event.getEventName().equals(name.trim())) {
    5. return event;
    6. } else {
    7. continue;
    8. }
    9. }
    10.  
    11. return null;
    12. }

    And it works for BREAK and PLACE, but i also have two called WATER and LAVA, the names that are passed in the constructor for them are "[BUCKET_LAVA_EMPTY" and "[BUCKET_WATER_EMPTY".
    But for those this function doesn't work, i have verified that the variable passed in the function is equal to these event names. So, why doesn't it work?

    greetz blackwolf12333

    Lol, i fail, it had to be "[BUCKET_LAVA_EMPTY]" and "[BUCKET_WATER_EMPTY]"

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

Share This Page