Different ChatColor

Discussion in 'Plugin Development' started by badboysteee98, Apr 6, 2014.

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

    badboysteee98

    Hello everyone,

    I was just wondering on adding into my plugin that if a player has a certain permission say like *chatcolor.green* if I could make it so when they speak in chat there ChatColor will be green all the time. I'm doing this so Admins/Mods stand out more in Chat

    I'm sorry if I'm being dumb about this ahah if you want to point me in the right direction please feel free or any bukkit docs for this will help aswell :D
     
  2. Offline

    GodzOfMadness

    Use "AsyncPlayerChatEvent"

    Code:
    if(player.hasPermission("chatcolor.green")){
                event.setMessage(ChatColor.GREEN + event.getMessage());
            }
     
    badboysteee98 likes this.
  3. Offline

    badboysteee98

    GodzOfMadness thanks :D

    GodzOfMadness I can't put a p.haspermission inside the event can I?

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

    GodzOfMadness

    The event has a method called "getPlayer()" which returns the player sending the message.
    So it is something like Player player = event.getPlayer();
     
  5. Offline

    badboysteee98

    GodzOfMadness

    Ermm...

    Code:java
    1. @EventHandler
    2. public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent e) {
    3.  
    4. Player p = (Player) e.getPlayer();
    5.  
    6. if(p.hasPermission("chatcolour.green")) {
    7. //Do something
    8. }
    9. }


    the p.hasPermission is underlined red
     
  6. Offline

    GodzOfMadness

    badboysteee98 You don't need to cast (Player) onto it. It is already a player
     
  7. Offline

    badboysteee98

  8. Offline

    GodzOfMadness

    What is the error?
     
    badboysteee98 likes this.
  9. Offline

    badboysteee98

    GodzOfMadness Oh got it, it was because my class was called Player also so it was fetching the class instead of the org.bukkit....

    GodzOfMadness I have no error it just doesn't seem to work?

    EDIT: Doesn't matter wrong Plugin.yml

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

    GodzOfMadness

  11. Offline

    badboysteee98

    GodzOfMadness just one more question if the users is OP they get the ChatColor.Mod permission but because they are Owner I want them to have ChatColor.Owner permission how do I Override this?
     
  12. Offline

    GodzOfMadness

    badboysteee98 Make the if statements HIGHEST RANK to LOWEST RANK and then all the colors after
     
  13. Offline

    badboysteee98

  14. Offline

    GodzOfMadness

    badboysteee98

    Code:
    if(player.hasPermission("chatcolor.owner")){
                //do stuff
            }else if(player.hasPermission("chatcolor.mod")){
                //do stuff
            }else if(player.hasPermission("chatcolor.green")){
                //do stuff
            }
     
  15. Offline

    badboysteee98

    GodzOfMadness when a user is op the Color is the same as the Owner even though my Admin have OP I don't want them to have the same Colour as Owner anyway around this?
     
  16. Offline

    GodzOfMadness

    badboysteee98 Not unless you go one step further and not have your chat system fully permission based.
     
    badboysteee98 likes this.
  17. Offline

    badboysteee98

    GodzOfMadness have it based on what then?

    GodzOfMadness Don't worry found away add the permission - -ChatColor.Owner to the Admins to disable it :D

    Thanks for all your help though :)

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

    GodzOfMadness

    badboysteee98 Use a permission plugin and check the group they are in. So if they are in group "Owner" then add the owner tag or if they are in group "Admin" add the admin tag.
     
Thread Status:
Not open for further replies.

Share This Page