HashMap only Saves 3 EntityTypes

Discussion in 'Plugin Development' started by Bennetx3, Apr 15, 2018.

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

    Bennetx3

    Hey there!

    Im currently programming a Plugin with Wave-System for a Event.
    Everything just works fine, accept the Mobspawning. It just only saves 3 Types of Entities, that i load from the Config.

    Code (open)

    Code:
    while(true) {
                if(config.contains("Waves.Wave" + w)) {
                    HashMap<Integer, EntityType> mobsOfWave = new HashMap<Integer, EntityType>();
                    for(EntityType et : EntityType.values()) {
                        String confpath = "Waves.Wave" + w + ".Mobs." + et.toString();
                        if(config.contains(confpath)) {
                            System.out.println("Mob: " + et.toString() + ", Num: " + config.getInt(confpath));
                            mobsOfWave.put(config.getInt(confpath), et); // This is going to the Wave Class
                        }
                    }
                    // DEBUG
                    for(Entry<Integer, EntityType> test : mobsOfWave.entrySet()) {
                        System.out.println("DEBUG: " + test.getValue().toString() + " " + test.getKey());
                    }
    }
    

    Config (open)

    Code:
    Wave1:
        Mobs:
          SKELETON: 3
          CREEPER: 2
          SPIDER: 3
          HUSK: 2
          SILVERFISH: 4
        BreakTime: 15
        isBossWave: false
    

    CONSOLE Output (open)

    Code:
    [17:16:00 INFO]: [BossEvent] Enabling BossEvent v0.0.1
    [17:16:00 INFO]: Mob: HUSK, Num: 2
    [17:16:00 INFO]: Mob: CREEPER, Num: 2
    [17:16:00 INFO]: Mob: SKELETON, Num: 3
    [17:16:00 INFO]: Mob: SPIDER, Num: 3
    [17:16:00 INFO]: Mob: SILVERFISH, Num: 4
    [17:16:00 INFO]: DEBUG: CREEPER 2
    [17:16:00 INFO]: DEBUG: SPIDER 3
    [17:16:00 INFO]: DEBUG: SILVERFISH 4
    


    Its running in the main thread!
    No Errors in Console :/

    Java Version: 1.8.0_161

    Thanks for your help :)
     
    Last edited: Apr 15, 2018
  2. Offline

    MightyOne

    Haha :D you are using ints as key vlaues. What do you think, how often can you use '2' as key? Correct, just one time. The same with 3, 4 and 5. But since you want to save values for unique EntityTypes just create a HashMap<EntityType, Integer>.

    Second thing i wanted to say is that iterating through all EntityTypes to get just a few in your config is not necessary. ConfigurationSection#getKeys(false) will return you all main nodes of a section. You could use this method in every wave section to simply get the EbtityType keys saved there.
     
Thread Status:
Not open for further replies.

Share This Page