Solved Sending a message to everyone in the Hashmap

Discussion in 'Plugin Development' started by Eggspurt, Apr 19, 2015.

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

    Eggspurt

    Really confused on how to do this... This is what I have so far..
    Code:
        public HashMap<String, Integer> toggle = new HashMap<String, Integer>();
    
            if(cmd.getName().equalsIgnoreCase("toggle")) {
                if (toggle.containsKey(player.getName())) {
                toggle.remove(player.getName());
                MMC.displayMessage("You will no longer be notified!", player.getPlayer());
                } else {
                toggle.put(player.getName(), 1);
                MMC.displayMessage("You are now being notified!", player.getPlayer());
                   }
    }
    
    @EventHandler
    public void JoinEvent(PlayerJoinEvent e) {
    if(PlayersHaveItToggled) {
    sendMessage("Our friend "+e.getPlayer.getName()+" has joined the server!");
    } else {
    }
    }

    Something like that.

    I don't know how to send a message to all of the players on the Hashmap.... Any advice would be appreciated :)
     
  2. Offline

    xMrPoi

    use the .getKeys() method and use that to loop through all keys in the hashmap.
     
  3. Offline

    Eggspurt

    Would you happen to have an example? I am new with Hashmaps :)
     
  4. Offline

    xMrPoi

    Looping isn't only for hashmaps. You could use a for-each loop.

    This is how a for-each loop looks
    Code:java
    1. for(Object obj : myObjects){}
     
  5. Offline

    Eggspurt


    I tried using arrays now I have this

    for(Player online : Bukkit.getOnlinePlayers()) {
    if(c.toggle.contains(online.getName())) {
    online.sendMessage("You are in the list!");
    }

    I don't know why this wouldn't work :p
     
    Last edited: Apr 19, 2015
Thread Status:
Not open for further replies.

Share This Page