Getting a player's group through Vault

Discussion in 'Plugin Development' started by UnpeeledBanana1, Nov 9, 2015.

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

    UnpeeledBanana1

    So, I'm basically trying to setup chat in my plugin, and making it format depending on the player's group. I'm using Vault to get the player's group.
    The imports for Vault permissions are all fine, they work as they should do.
    I'm just stuck on seeing what group a player is in.
    Here's the code:

    Code:
    public class Chat extends JavaPlugin implements Listener {
    
        public static Economy econ = null;
        public static Permission perms = null;
    
        public void onEnable() {
            if (!setupEconomy() ) {
                Bukkit.getConsoleSender().sendMessage("§cVault needed mate...");
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
            setupPermissions();
            }
    
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }
    
        @EventHandler
        public void chatFormat(AsyncPlayerChatEvent event) {
    
          Player player = event.getPlayer();
    
          if ((perms.getPrimaryGroup(player) == (perms.getPrimaryGroup(player)))) {
              event.setFormat("§8[Member] §7" + player.getDisplayName() + ":§7 " + event.getMessage());
    
          } else {
              event.setFormat("§7" + player.getDisplayName() + " §8:" + event.getMessage());
          }
    }
    I realize that this finds the player's group:
    Code:
    perms.getPrimaryGroup(player)
    But I just get stuck when i'm trying to find if it's equal to another group.
    Any solutions out there?

    Thanks :)
     
  2. Offline

    Scimiguy

  3. Offline

    mcdorli

    if((perms.getPrimaryGroup(player)==(perms.getPrimaryGroup(player))))

    ???

    Let's do some math with this "equality"

    Code:
    (perms.getPrimaryGroup(player)==(perms.getPrimaryGroup(player)))
    
    You can divide it by (perms.getPrimaryGroup(player)), vecause either side has it, you get

    Code:
    1 == 1
    
    This means, that this is always true, so you don't need that if statement.
     
  4. Offline

    UnpeeledBanana1

    @mcdorli I know that... It's just there temporarily until I can find a solution.
    Plus, they are exactly the same. Isn't that a bit obvious to point out?
     
  5. Offline

    Scimiguy

    @UnpeeledBanana1
    If it's that obvious, why have it at all?
    Even temporarily?

    For any reason?
    What reason?
     
  6. Offline

    UnpeeledBanana1

    @Scimiguy Just personal preference.

    I came here for help, not criticism :l

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

    mythbusterma

    @UnpeeledBanana1

    You asked for help about comparing the group and he pointed out that you have a completely pointless comparison concerning the player's group. That's pretty relevant, I would think.
     
Thread Status:
Not open for further replies.

Share This Page