Looping through HashMap

Discussion in 'Plugin Development' started by elementalgodz11, Apr 26, 2014.

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

    elementalgodz11

    I am trying to make a clearlag plugin, when you type /clearlag:

    Code:java
    1. World world = Bukkit.getServer().getWorld(Environment.NORMAL.name());
    2.  
    3. for (Entity entities : world.getEntities()) {
    4.  
    5. if (entities instanceof Boat) {
    6. Count++;
    7. entitieList.put(entities.getType().toString(), Count);
    8. entities.remove();
    9. Count = 0;
    10. }
    11.  
    12. if (entities instanceof Wolf) {
    13. Count++;
    14. entitieList.put(entities.getType().toString(), Count);
    15. entities.remove();
    16. Count = 0;
    17. }
    18.  
    19. }
    20.  
    21. player.sendMessage(ChatColor.GOLD + "< ClearLag >");
    22. player.sendMessage("(EntityType) entities has been removed.");


    This is my code, I want it to say for example:
    10 wolves have been removed
    2 boats have been removed

    How would I be able to do this?

    Thanks
     
  2. Offline

    DxDy

    You'd propably use a Map<String, Integer> to count it, as I suppose you do already (entitieList). But you need to get the count from the map before you increment it ;)
     
  3. for (String entityType : entitiesList.getKeys(false)) {
    int boatCount;
    if (entityType.equalsIgnoreCase("Boat") {
    boatCount++;
    }
    p.sendMessage("Boats: " + String.valueOf(boatCount));
    }
     
Thread Status:
Not open for further replies.

Share This Page