ConfigurationSection issues with incompatible types

Discussion in 'Plugin Development' started by tappestry, May 9, 2016.

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

    tappestry

    Code:
        this.protections.clear();
    
    1    for (ConfigurationSection blockSection = worldBlockData.entrySet().iterator(); blockSection.hasNext();
    2      worldSection.hasNext())
        {
    3      Map.Entry worldData = (Map.Entry)blockSection.next();
          String worldName = (String)worldData.getKey();
    4     worldSection = ((Map)worldData.getValue()).values().iterator(); continue; BlockData blockData = (BlockData)worldSection.next();
          this.protections.addProtection(worldName, blockData);
        }
    number one and four are both incompatible errors. 2 and 3 are results of the errors I believe... Thing is this compiled before 1.9 and now this is causing something to go haywire. I'm not the best programmer but I am trying to repair an old broken plugin. Could anyone help with some advice here?
     
    Last edited: May 9, 2016
  2. Offline

    Zombie_Striker

    1. So you are setting a configuration section equal to an iterator? This would never work.
    2. You are saying "blockSection is a itorater, if it has next, then do if it has next". The third parameter is what would should happen.

    1. You are treating an Entity to a Map. Don't just ignore errors and blindly click things.
    2. The continue forces the for loop to skip the rest of the code and move to the next value.
    3. You are trying to get two values inside one loop. Only get one per loop.
     
  3. ? He's treating an entry as a map, I suppose he has a map which has maps as values.



    @tappestry
    If you are trying to learn how to do/fix plugins, or have more plugins to fix, LEARN JAVA before getting into bukkit, this is not like saying: hey, some of these words are similar to english, I think I can do this in a first try :p.

    If you don't want to learn (open)
    If you just want to fix this code in this plugin, and no matter how it is fixed, you simple want it to be fixed, then replace that code with this:
    Warning

    Code:
            this.protections.clear();
           
            Iterator worldSection = null;
            Iterator blockSection = worldBlockData.entrySet().iterator();
           
            while (blockSection.hasNext()) {
                Map.Entry worldData = (Map.Entry)blockSection.next();
                String worldName = (String)worldData.getKey();
                worldSection = ((Map)worldData.getValue()).values().iterator();
                while (worldSection.hasNext()) {
                    BlockData blockData = (BlockData)worldSection.next();
                    this.protections.addProtection(worldName, blockData);
                }
            }
    Can't promise that will sit to your needings, as you haven't given enough information to make a clear idea on what you are trying to do.
     
Thread Status:
Not open for further replies.

Share This Page