Solved Using Hashmaps

Discussion in 'Plugin Development' started by Mindfulhacker, Jul 13, 2013.

Thread Status:
Not open for further replies.
  1. Hey,

    I'm rather new to programming bukkit. Ive tried to create a plugin that will allow you to hide yourself. It uses hashmaps. Just one thing. How can I hide the people in the hashmap when another player joins?




    This is my code for creating the hashmap
    Code:java
    1. HashMap<String, Boolean> hidden = new HashMap<String, Boolean>();



    And I'm hiding the user like this:
    Code:java
    1. for(Player online : Bukkit.getOnlinePlayers()){
    2. online.sendMessage(ChatColor.YELLOW + player.getName() + " left the game.");
    3. online.hidePlayer(player);
    4. }






    So basicly, how can I automaticaly hide the users who are in the hashmap when someone joins the game?
     
  2. Offline

    Alxlre

    You should use a HashSet.

    Listen for PlayerJoinEvent and then hide all the players in the set from that player.
     
  3. How do i create a suitable hashset
     
  4. Offline

    Alxlre

    Mindfulhacker Please tag me so I can come to help you!

    Declare the HashSet first:
    Code:java
    1. private Set<Players> hidden;

    Then in the constructor, initialize the HashSet like this:
    Code:java
    1. hidden = new HashSet<>();

    Now you can add and remove players from the HashSet:
    Code:java
    1. hidden.add(player);
    2. hidden.remove(player);

    You can also check if the HashSet contains a value:
    Code:java
    1. if (hidden.contains(player)) {
    2. // Do something
    3. }
     
  5. Offline

    xTrollxDudex

  6. Do you mean

    Code:java
    1. for(Player online : Bukkit.getOnlinePlayers()){
    2. online.sendMessage(ChatColor.YELLOW + player.getName() + " left the game.");
    3. online.hidePlayer(player);
    4. }


    Thats what executes when the command is given

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page