PermissionsEx Chat Manager Question

Discussion in 'Plugin Development' started by MineStein, Mar 27, 2016.

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

    MineStein

    Hi everyone, quick question. I'm currently programming a chat manager to work with PEX as I couldn't find one that allowed me to all prefixes attached to the player through groups.

    This is my current code:

    Code:
    @EventHandler
        public void onChat(final AsyncPlayerChatEvent event) {
            final Player player = event.getPlayer();
            final String[] groups = PermissionsEx.getUser(player).getGroupNames();
    
            StringBuilder concatenatedGroups = new StringBuilder();
    
            for (String group : groups) {
                concatenatedGroups.append(group).append(" ");
            }
    
            String str = concatenatedGroups.toString().trim();
    
            event.setFormat(str + " " + player.getName() + " " + event.getMessage());
        }
    I want to grab each of the group's attached prefixes and display them with color before the name, but the PermissionGroup object doesn't have any attached accessors/mutators.

    Thank you.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @MineStein Why not hook into Vault instead and manage all of them?
     
  3. Offline

    MineStein

    How might I do that? I'm new to hooking into PEX and Vault.
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    MineStein

  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    MineStein

    Last edited by a moderator: Mar 28, 2016
  8. Offline

    timtower Administrator Administrator Moderator

    @MineStein Then it probably is the chat class.
     
  9. Offline

    MineStein

    I managed to get it working with the Chat class. Here's what I did:
    Code:
    @EventHandler
        public void onChat(final AsyncPlayerChatEvent event) {
            final Player player = event.getPlayer();
            Chat chat = plugin.getChat();
            StringBuilder builder = new StringBuilder();
    
            for (String groupName : PermissionsEx.getUser(player).getGroupNames()) {
                builder.append(chat.getGroupPrefix("", groupName)).append(" ");
            }
    
            String str = builder.toString().trim();
    
            event.setFormat(ChatColor.translateAlternateColorCodes('&', str + " " + player.getName() + " " + event.getMessage()));
        }
     
  10. Offline

    timtower Administrator Administrator Moderator

    @MineStein Never set the name and message in that event. Always use the placeholders %s, first one is the name, second one is the message.
    This is so that other plugins can also modify it.
     
Thread Status:
Not open for further replies.

Share This Page