localIterator Problem

Discussion in 'Plugin Development' started by beaudigi, Sep 13, 2014.

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

    beaudigi

    Well heres the code:
    Code:
        private TeamCommand getCommand(String key) {
        TeamCommand c;
        label65:
            for (Iterator localIterator = this.commands.values().iterator(); localIterator.hasNext(); return c){
                c = (TeamCommand)localIterator.next();
                if (c.name().equalsIgnoreCase(key)) {
                    return c;}
                if ((c.alias() == null) || (!c.alias().equalsIgnoreCase(key))) {
                    break label65;
                }
            }
            return null;
        }
    }
    

    for (Iterator localIterator = this.commands.values().iterator(); localIterator.hasNext(); return c){
    The return C is coming up with replace "return" with "++" Except this also dosen't work. Any help?
     
  2. You don't have to use an iterator, you can put this.commands.values() in a for loop.
    With this setup you can move
    Code:java
    1. c = (TeamCommand)localIterator.next();

    to where 'return c' is.
     
  3. Offline

    mythbusterma

    beaudigi

    Why do you have a label there that isn't correctly indented? You don't need a label there, a simple "break;" will break it out of the loop. You should also use enhanced for-loops instead of that iterator, for increased readability.
     
  4. Offline

    beaudigi

    I tried that
    However in game it makes the commands just do /t t (not what its meant to do)
     
  5. I don't think the problem is in the quoted section. Btw, you didn't make it clear what you want to achieve nor posted code for this method's usage.
     
Thread Status:
Not open for further replies.

Share This Page