How to exempt players with all permissions to not have a certain permission?

Discussion in 'Plugin Development' started by PerezHD, Nov 14, 2014.

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

    PerezHD

    Hey guys, what I am trying to do is make a prefix/suffix plugin right now. I am trying to make it so owners (me) or players with all permissions (*) be exempt from the prefix/suffix's meaning not have the prefix or suffix?

    CODE:
    Code:java
    1. package me.perezhd.prefixsuffix;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.AsyncPlayerChatEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin implements Listener {
    11.  
    12. public void onEnable(){
    13. getServer().getPluginManager().registerEvents(this, this);
    14. }
    15.  
    16. @EventHandler
    17. public void onChat(AsyncPlayerChatEvent event){
    18. if(event.getPlayer().hasPermission("chat.normal")){
    19. event.setFormat(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s");
    20. }
    21. }
    22. }
     
  2. Offline

    Mr. Mister Man

    Use if(!player.hasPermission("perm"){
    //if they dont have the permission do this.
    }
     
  3. Offline

    PerezHD

    But the permission * means all permissions, so wouldn't players with all permissions be able to have the prefix/suffix though still?
     
  4. Offline

    Mr. Mister Man

    You can check if they are op or not? Or hook into pex and see if they are owner/some rank?
     
  5. Offline

    Skionz

    PerezHD Have you tried it? Try before asking.
     
  6. Offline

    PerezHD

    Eh I will, I just know that players will still be able to have that permission. But I have a feeling it won't due to the (!)
     
  7. Offline

    Mr. Mister Man

    Like I said before check if they are op. PEX and some permissions plugin assign those with * OP by default I believe.
     
  8. Offline

    PerezHD

    Ill try, and I am also using groupmanager ;/
     
  9. Offline

    Mr. Mister Man

    Remember to post back here with results :)
     
  10. Offline

    PerezHD

    Ok, I fixed it. I did not need to do anything you guys said XD, I just did
    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent event){
    3. Player player = event.getPlayer();
    4. String chatFormat = event.getFormat();
    5. if ((chatFormat.contains(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s")) && (player.hasPermission("flexrank.exempt"))){
    6. event.setFormat(event.getFormat().replace(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s", ""));
    7.  
    8. return;
    9. }
    10. if (chatFormat.contains(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s")){
    11. }
    12. if (player.hasPermission("flexrank.exempt")){
    13. event.setFormat(event.getFormat().replace(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s", ""));
    14.  
    15. return;
    16. }
    17.  
    18. if (player.hasPermission("flexrank.test")){
    19. event.setFormat(ChatColor.LIGHT_PURPLE + "%s" + ChatColor.DARK_AQUA + " > " + ChatColor.GREEN + "%s");
    20. }
    21. }
    22. }


    Which is basically exempting the players with all perms not to have the prefix/suffix.

    Close Please.

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

Share This Page