Solved Group Checks (Vault)

Discussion in 'Plugin Development' started by ebear, Oct 24, 2014.

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

    ebear

    How would I check if a player is in a certain group, with or without Vault.

    I want to check if they are in a group. If they are, it'll set their Chat Format to one thing. If not, it'll remain default.

    Can someone tell me how to do this?

    Thanks.
     
  2. Offline

    acer5999

    http://milkbowl.github.io/VaultAPI/
    You can look there, but the method you would want is getPrimaryGroup() which returns a string.
    The pseudo for that would be something like

    Code:
    player joins
     
    if player is in group X
     
    add them to arraylist y
     
     
     
    player chat event
     
    if player is in arraylist y
     
    Change player message
    or if you want a separate chat colour for each group

    Code:
    player joins
     
    if player is in group X
     
    add to hashmap x with name and their group as a string
     
    if player is in group y
     
    add to hashmap x with name and their group as a string
     
     
     
    player chat event
     
    if player is in hashmap
     
    if value of player in hashmap is group x
     
    change message color
     
    if value of player in hashmap is group y
     
    change message to different color
     
    
    No spoonfeeding today!
     
    FerusGrim likes this.
  3. Offline

    ebear


    Thanks. Although, I'm trying to make it so my plugin figures out if a player is in a group.

    That leads me to think to use an if statement. The only problem is, I'm completely clueless as far as the parameters of the if statement. I want it to check if a player is in a group. If they are, it'll do the code. If not, it'll do something else.

    That's why when I saw the playerInGroup method, I thought that would work. I just don't know how to use it.
     
  4. Offline

    acer5999

    Alright, so the method getPrimaryGroup() returns a string, so what you would do with Vault is go
    Code:java
    1. if(getPrimaryGroup(null,player).equals("groupname") {
    2. //Do stuff
    3. }

    I am not super experienced with Vault but that should work.
     
  5. Offline

    ebear


    So I added
    Code:java
    1. public String getPrimaryGroup(String world, org.bukkit.OfflinePlayer player) {
    2. return getPrimaryGroup(world, player.getName());
    3. }

    And getPrimaryGroup in the return statement tells me there's something wrong with it. It says "The method getPrimaryGroup(String, OfflinePlayer) in the type Main is not applicable for the arguments (String, String)"

    Though, I did add the code you sent and that works fine. But the method for getPrimaryGroup has issues.
     
  6. Offline

    acer5999

    No, import the vault jar as you would with bukkit, no need to create a method.
     
  7. Offline

    ebear


    I did...

    So I didn't let it make a method, I have this code:
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e) {
    3. Player p = e.getPlayer();
    4. e.setMessage(colorize(e.getMessage()));
    5.  
    6. if(getPrimaryGroup(null, p).equals("Apex")) {
    7.  
    8. e.setFormat("§f§l[§c§oApex§f§l] §f" + p.getName() + "§d§l> §7"
    9. + e.getMessage());
    10. }


    The getPrimaryGroup in the if statement is said to be wrong. The error is "The method getPrimaryGroup(null, Player) is undefined for the type Main". That leads me to think I actually do need a Method...?
     
  8. Offline

    acer5999

    Yeah, I just tried, this is actually rather confusing... You could try importing with maven instead of importing the Jar.
     
  9. Offline

    ebear


    I'm just beyond... It's so stupid. I'm trying playerInGroup now. Though everything works and builds without errors, my console gives me this: http://pastebin.com/BzartKM0

    It just doesn't like to work.
     
  10. Offline

    acer5999

    That is a massive stack trace... It seems to not like playerInGroup, the best alternative would be just to check if player has a certain permission.
     
  11. Offline

    ebear


    Alright. Turns out the return statement kept returning the method so it pretty much sh*t itself.

    Good to know.

    The return statement should've been
    Code:java
    1. return perms.playerInGroup(player, group);
     
Thread Status:
Not open for further replies.

Share This Page