Set players to be invisible to only some players

Discussion in 'Plugin Development' started by SaxSalute, Mar 31, 2014.

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

    SaxSalute

    Part of my plugin requires selective invisibility. Say we have players 1-10 and they are in the same room for a free-for-all. I would want players 1-5 to see each other and 6-10 to see each other. How would I go about this?
     
  2. Offline

    Cloaking_Ocean

    Well the way I'd go about it first creating a Hashmap to contain all the players and then add Strings so you know what number they are. Such as, Hashmap<Player, String> players = new Hashmap<Player, String>(); Then when in your plugin as your setting the players 1-10 just add them into this hashmap. Afterwards when you want to make them invisible get the players 1-5 out of the hash map and then set the 6-10 players invisible. Probably using a loop like this.

    Code:
    for(Player p : listofplayers1-5){
        p.setCanSeePlayer(targetplayer);
    }
    Idk something like that. If you need more help you can ask me when I get back home and can actually use eclipse to compile the code.
     
  3. Offline

    JRL1004

    Cloaking_Ocean Never store a player instance. Do HashMap<String, String> players = new HashMap<String, String>(); where one string is the players' names.
     
  4. Offline

    Cloaking_Ocean

    Okay yeah sure, if you want xD
     
  5. Offline

    SaxSalute

    Is it bad to store a player instance even if that instance is only going to be stored until the user logs out?
     
  6. Offline

    Codex Arcanum

    Shouldn't be. People's concern is that lingering instance of Player objects prevent the Java Garbage Collector from removing instances of players who logged out. Shouldn't be a problem if you remove them from the collection on logout.
     
Thread Status:
Not open for further replies.

Share This Page