Solved Checking for two Permissions...

Discussion in 'Plugin Development' started by TheLexoPlexx, Aug 17, 2014.

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

    TheLexoPlexx

    Hey there,

    so, I'm currently creating a Chat-Formatting-Plugin and I need to check for two Permissions. I'm implementing the AsyncPlayerChatEvent and blah blah.. So now the Prefixes depend on Permissions. If the Player has the Permissions. chatrevo.developer AND chatrevo.webdeveloper the Prefix should look like this: (coloured obviously)
    But if the Player has only the chatrevo.webdeveloper permission, the Prefix should look like this: (also coloured)
     
  2. Offline

    TopTobster5

    Write an if statement looking for the web dev perm, as this is the common one. Inside that, look for if they have the dev perm. If they do, set their prefix to [Dev/Web]. If not, set it to [Dev]
     
    DinosParkour likes this.
  3. Offline

    PixeledCow

    By the way, if you op player's they will have all those permissions. Then your plugin will malfunction.
     
  4. Offline

    DinosParkour

  5. Offline

    Necrodoom

  6. Offline

    TopTobster5

    PixeledCow I may be wrong with this, but I thought if you use player.hasPermission("permission"), it would ignore if they had op. Again, I could be wrong though.
     
  7. Offline

    Necrodoom

    TopTobster5 if the node is tagged as default: true or default: op, will return true unless specifically negated.
     
  8. Offline

    PandazNWafflez

    Necrodoom Also depends on the permissions system, doesn't it? Some of them will return true for every permission if the player is op, others won't.
     
  9. Offline

    TheLexoPlexx

    I thought about that sure. But I thought there's an easier Way of making 45 Different Prefix combinations. Okay then... :/

    So I need to register all Permissions in the plugin.yml setting the default-op node to false?

    lol :DD Didn't think about that :D thanks


    I kinda comment-spammed now, sorry for that. Could a Mod please Merge these 3 Posts? I couldn't Edit the Posts for whatever reason :confused:

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

    TopTobster5

    TheLexoPlexx I dont think there is an easier way to do it. I guess using switch statements might make the code look a bit simpler and easier to read, but there is no easy and fast way to do it.
     
  11. Offline

    xTigerRebornx

    TopTobster5 TheLexoPlexx
    What about a Map<String, String>, where the key is the permission, and the value is the prefix applied? Then, you can simply iterate over either the entry or the keySet and append the value if the person has the permission.
     
  12. Offline

    TopTobster5

    xTigerRebornx That could work, but if someone has multiple permissions, it could break if it is not set up in the correct order.
     
  13. Offline

    xTigerRebornx

    TopTobster5 There are ordered maps that keep the order things were put in, just use one of those and put them in the correct order.
     
  14. Offline

    TopTobster5

    xTigerRebornx As I said before, it could work if done properly. I just feel like it would be easier to break if not set up correctly.
     
  15. Offline

    xTigerRebornx

    TopTobster5 It would break just as easy as if he had ordered his switch/if statements wrong, only using a Map would provide more legibility and scalibility.
     
  16. Offline

    TheLexoPlexx

    I did it a bit different. For everyboy who is wondering how it works, heres a Part of the Code:
    Code:
        @EventHandler
        public void onChat(AsyncPlayerChatEvent e) {
            String prefix = groupPrefix(e.getPlayer());
            e.setMessage(prefix + " " + e.getPlayer().getDisplayName() + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + e.getMessage());
        }
     
        private String groupPrefix(Player p) {
            List<String> ls = new ArrayList<String>();
            if (p.hasPermission("chatrevo.headadmin")) {
                ls.add(ChatColor.DARK_RED + "Head-Admin");
            }
            if (ls.size() == 0) {
                ls.add(ChatColor.GRAY + "Member");
            }
            String end = ChatColor.DARK_GRAY + "[";
            boolean first = true;
            if (ls.size() > 4) {
                end += ChatColor.COLOR_CHAR + "Wither";
            } else {
                for (String s : ls) {
                    if (!first) {
                        end += ChatColor.DARK_GRAY + "/" + s;
                    } else {
                        end += s;
                        first = false;
                    }
                }
            }
            end += ChatColor.DARK_GRAY + "]";
            return end;
        }
    }
    Oh and you obviously need to set the "default-to-op" node in the plugin.yml to false.
     
Thread Status:
Not open for further replies.

Share This Page