Setting player's nametags with permissions [TagAPI]

Discussion in 'Plugin Development' started by born2kill_, Jul 13, 2014.

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

    born2kill_

    Can someone help me change nametags?

    I'm using TagAPI.

    So what I'm looking for is to change nametags for operators, and players who have the permissions "wkits.tag.default, wkits.tag.mod".
    So if they're an operator, they get a red nametag.
    If they have the permission wkits.tag.default, they get a grey nametag.
    If they have the permission wkits.tag.mod, they get a darkpurple nametag.

    I've already tried but it just sets everyone's name to one person.
    Here's the code I have currently:
    Code:
    for(OfflinePlayer offlinePlayer : Bukkit.getOperators()) {
      if(event.getNamedPlayer().getName().equals(offlinePlayer.getName())) {
        event.setTag(ChatColor.RED + offlinePlayer.getName());
      }
      }
      for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
      if(event.getNamedPlayer().hasPermission("wkits.tag.default")) {
        event.setTag(ChatColor.GRAY + onlinePlayer.getName());
      }else
      if(event.getNamedPlayer().hasPermission("wkits.tag.mod")) {
        event.setTag(ChatColor.DARK_PURPLE + onlinePlayer.getName());
      }
      }
    Thanks
     
  2. Offline

    Tecno_Wizard

    born2kill_
    By one person do you mean that everyone has the same name tag,or that it only one person gets a tag?

    Also, I already see a problem. You need to set the basic tag first, them mod, then op, or everyone but mods will have gray tags.
     
  3. Offline

    born2kill_


    Code:
     public void onNameTag(AsyncPlayerReceiveNameTagEvent event) {
      // All operators get red name tag
      event.setTag(ChatColor.GRAY + event.getNamedPlayer().getName());
      for(OfflinePlayer offlinePlayer : Bukkit.getOperators()) {
      if(event.getNamedPlayer().getName().equals(offlinePlayer.getName())) {
        event.setTag(ChatColor.RED + offlinePlayer.getName());
      }
      }
    }
    So this is my code right now, I added a base nametag, and anyone who isn't op [Including moderators] have a grey nametag. So I just want to set these moderators to have a darkpurple nametag, could you give me a piece of code to add to help me do so?

    Also by one person I meant that everyone has the same nametag and skin.
     
  4. Offline

    Tecno_Wizard

    born2kill_
    I have personally had a TON of difficulties with scoreboards and name tags.

    The second code you sent me here is the event for adding a name tag, right?
    Well, to me this seems like a duplicate code if you are implementing both of these, although i'll assume this is a replacement.
    Also, I believe the for loop might not be necessary, you can get the player from the event.
    As for as why this does not work, I have no clue. Any other more experienced coders see anything?
     
  5. Offline

    born2kill_


    Everything in that code is working, I am just confused on how to make it so that mods get a purple nametag.
    And yes it is a replacement to the older code.
     
  6. Offline

    Tecno_Wizard

    born2kill_ That I can fix. So far you have OPs red and normal gray. What kind of group management system are you using, because MODS differ based on your settings. You would have to find a way to assess the player's group, and I have never dealt with that before.
     
  7. Offline

    ChipDev

    Code:java
    1. public void onNameTag(AsyncPlayerReceiveNameTagEvent event) {
    2. for(Player allPlayers : getServer().getOnlinePlayers()) {
    3. if(allPlayers.isOp()) {
    4. event.setTag(ChatColor.RED + allPlayers.getName());
    5. }
    6. }
    7. }

    If the player is op, give them a red name tag.
     
Thread Status:
Not open for further replies.

Share This Page