HashMaps Checking if player is in hashmap

Discussion in 'Plugin Development' started by ZaneBaney, Apr 27, 2014.

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


    Hi there. I have a command to check the team and to leave the team, however it appears my if statement is not working or something? Have I used the incorrect syntax for hashmaps?

    Code: http://pastebin.com/B0XrzGL2

    There are no console errors when I type the command and nothing comes up in game :/
  2. You should only use hashmaps if you want to store extra data about a specific object. (e.g. player, death amount) In this case, you should use a List<Player> (or ArrayList), or use a List<String> to save memory space.
  3. Offline


    Store their UUID's in the map instead.

  4. You shouldn't use a map unless you're going to store extra data, or , in the case of the new UUID thing in 1.8, then you could store the players's UUID as the String and check if it contains it in the ArrayList with 'player.getUniqueId().toString()'

    1. ArrayList<String> red = new ArrayList<String>();
    2. ArrayList<String> blue = new ArrayList<String>();
    3. if (cmd.getName().equalsIgnoreCase("whatteam") && sender instanceof Player) {
    4. if (red.contains(player.getName())) {
    5. player.sendMessage(ChatColor.RED + "You are in team Red!");
    6. } else if (blue.contains(player.getName())) {
    7. player.sendMessage(ChatColor.BLUE + "You are in team Blue!");
    8. } else
    9. player.sendMessage("You are in no teams!");
    10. }
    11. if (cmd.getName().equalsIgnoreCase("leaveteam")) {
    12. if (red.contains(player.getName())) {
    13. player.sendMessage(ChatColor.RED + "You have left your team!");
    14. red.remove(player);
    15. }
    16. if (blue.contains(player.getName())) {
    17. blue.remove(player);
    18. player.sendMessage(ChatColor.BLUE + "You have left your team!");
    19. }
Thread Status:
Not open for further replies.

Share This Page