Looking for way to list online staff members

Discussion in 'Plugin Development' started by qaman6, Aug 22, 2013.

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

    qaman6

    Hi! I'm relatively new to coding, and this is what I have. http://pastebin.com/Py6hw79D
    That works fine, but then I thought, "Maybe I could have this, but then under the message where it prints out the staff members, I could add a feature of the ONLINE staff members?" I'd love to incorporate this into my plugin. I just don't know where to start, or how to do this. Any ideas? ;)
     
  2. Offline

    CubieX

    You could use the players permission group for this. And/or the chat prefix.
    You can then list all online players with a particular group like "Admin", "Mod" or whatever.

    Getting the players group can be done by using your permission systems API. (for example the PEX API)
    or if you want this to be a bit more generic for other server owners, you could use "Vault" to
    get the group. This will then work for every supported permissions plugin without you having to change your code.
    And Vault supports many of them.

    "Essentials" for example does the same thing, if the option for sorting the online player list by ranks is activated.
     
  3. Offline

    qaman6

    CubieX How would I go about doing this? I'm sort of confused on which methods to use, and where to put it.


    If I do this,
    if(player.hasPermission("mcore.group.moderators")
    and give that group the permission, would that be a method of this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    CasparW

    You just listed the staff you wan't i would do it like

    Code:
    player.sendMessage(ChatColor.GOLD + Bukkit.getOperators());
    
     
  5. Offline

    qaman6

    Yes, here is what I'm trying to do:

    Current staff: Qaman6, Jdzag24, MangekyoS, Ruqiee, Moyaboya, kingcards, and Skylord_Kason
    Online Staff: <online staff members will go here>
     
  6. Offline

    smcerm

    So you already know who the staff members are? Just check if each of them are online. Of course you'll have to change the code if the staff changes.
     
  7. Offline

    qaman6

    Yes, I know I will have to change the code. I'm planning on using a config file for that, but right now, I'd like to get this working. I'd like to make it so everyone that has the said permission, will appear in the list. Again I'm new at this, so it's sort of confusing. ;)
    I'm thinking maybe something like this, but how would I make it so it does what I want?

    Code:
    if(player.hasPermission("mcore.group.moderators"))
                            Arrays.asList(Bukkit.getServer().getOnlinePlayers());
     
  8. Offline

    KingNyuels

    Code:java
    1. public String getStaff() {
    2. List<String> onlineStaff = new ArrayList<String>();
    3. List<String> offlineStaff = new ArrayList<String>();
    4. OfflinePlayer offplayer[] = Bukkit.getOfflinePlayers();
    5. for (int i = 0; i == (offplayer.length - 1); i++) {
    6. PermissionUser user = PermissionsEx.getUser(offplayer[i].getName());
    7. if (user.inGroup("Admin")) {
    8. if (offplayer[i].isOnline()) {
    9. onlineStaff.add(offplayer[i].getName());
    10. } else {
    11. offlineStaff.add(offplayer[i].getName());
    12. }
    13. }
    14. }
    15. String paste = "Online Staff: ";
    16. boolean FirstOnline = true;
    17. for (int i = 0; i == (onlineStaff.size() - 1); i++) {
    18. if (FirstOnline) {
    19. FirstOnline = false;
    20. paste = paste + onlineStaff.get(i);
    21. } else {
    22. paste = paste + " , " + onlineStaff.get(i);
    23. }
    24. }
    25. boolean FirstOffline = true;
    26. for (int i = 0; i == (offlineStaff.size() - 1); i++) {
    27. if (FirstOffline) {
    28. FirstOffline = false;
    29. paste = paste + "\n Offline Staff: " + offlineStaff.get(i);
    30. } else {
    31. paste = paste + " , " + onlineStaff.get(i);
    32. }
    33. }
    34. return paste;
    35. }[/i][/i][/i][/i]


    onCommand just send the player per player.sendMessage(getStaff())!
     
  9. Offline

    qaman6


    Whereabouts could I put this?
     
  10. Offline

    KingNyuels

    Maybe in the same class in which the onCommand is. In your case in the main class ...

    KingNyuels
     
  11. Offline

    qaman6

    All right, and how would I signify a player as a staff member?
     
  12. Offline

    KingNyuels

    You can query every group you want. Just add an line with this:
    Code:java
    1. if (user.inGroup("Admin")) {
    2.  
    3. if (offplayer[i].isOnline()) {
    4.  
    5. onlineStaff.add(offplayer[i].getName());
    6.  
    7. } else {
    8.  
    9. offlineStaff.add(offplayer[i].getName());
    10.  
    11. }
    12.  
    13. }[/i][/i][/i]


    Code:java
    1. if (user.inGroup("Owner")) {
    2. if (offplayer[i].isOnline()) {
    3. onlineStaff.add(offplayer[i].getName());
    4. } else {
    5. offlineStaff.add(offplayer[i].getName());
    6. }
    7. }[/i][/i][/i]
     
  13. Offline

    qaman6

    I see now. Config file...
     
  14. qaman6 Here is some working code based off one of my plugins
    Code:java
    1. StringBuilder str = new StringBuilder();
    2. for (int i = 0; i < args.length; i++){
    3. str.append(args[i] + " ");
    4. }
    5.  
    6. String staff = str.toString();
    7.  
    8. List<Player> ops = new ArrayList();
    9. for(Player play : Bukkit.getOnlinePlayers()){
    10. if(play.hasPermission("permission to allow player to be added to list")){
    11. ops.add(play);
    12. if (commandLabel.equalsIgnoreCase("staff")){ //working
    13. if (args.length > 0){
    14. if (sender.hasPermission("some permission")){
    15. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Staff")));
    16. }
    17. }
    18. }
    19.  
    20. if (commandLabel.equalsIgnoreCase("staffadd")){
    21. getConfig().set("Staff", staff);
    22. sender.sendMessage(ChatColor.WHITE + "Set staff list to: " + ChatColor.translateAlternateColorCodes('&', getConfig().getString("Staff")));
    23. }[/i]


    qaman6 Ignore the "working" comment on line 12. I just copied and pasted it from my code and forgot to remove that when I posted it. Also ignore the [/i] on line 23. Idk why that's there :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  15. Offline

    qaman6

    So let me try to decode what that code is...
    That makes a command named "/staff", which will list the ops. There is a command named "/staffadd" which will add someone to the list. After that, it puts it in the config, or retrieves from the config.
    Am I correct? I'm just testing my knowledge.
     
  16. First things first, make sure to reply to me or tag me, otherwise I won't see your comment. Here is the code with comments this time:


    Code:java
    1. StringBuilder str = new StringBuilder();
    2. for (int i = 0; i < args.length; i++){
    3. str.append(args[i] + " "); //this whole thing here essentially allows you to get a bunch of text and set it as one string
    4. }
    5.  
    6. String staff = str.toString(); //creates a string using the above method
    7.  
    8. List<Player> ops = new ArrayList();
    9. for(Player play : Bukkit.getOnlinePlayers()){
    10. if(play.hasPermission("permission to allow player to be added to list")){
    11. ops.add(play); //everything above this gets players if they have a certain permission and adds them to an array list
    12. if (commandLabel.equalsIgnoreCase("staff")){ //command to use everything above
    13. if (sender.hasPermission("some permission")){ //if the sender has a certain permission...
    14. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Staff")));
    15. //^gets the info from the config. This stuff will be created in the command below
    16. }
    17. }
    18.  
    19. if (commandLabel.equalsIgnoreCase("staffadd")){
    20. if (args.length > 0){ //makes sure that you have more than one arguement
    21. getConfig().set("Staff", staff); //creates a string in the config named "Staff" and adds everything after "staffadd" to the list.
    22. sender.sendMessage(ChatColor.WHITE + "Set staff list to: " + ChatColor.translateAlternateColorCodes('&', getConfig().getString("Staff"))); //sends the sender a message showing everyone that they added to the list
    23. }[/i]



    Also, I made a small mistake in my previous comment. Use this code instead :)
     
Thread Status:
Not open for further replies.

Share This Page