Prefix in chat

Discussion in 'Plugin Development' started by TheCupOfTea, Jun 25, 2018.

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

    TheCupOfTea

    How do I add PermissionsEx prefix to my chat plugin?
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    TheCupOfTea

    Ok I made class Chat and pasted that code in there. Can you give an example how to add prefix?

    EDIT:
    Its already changed in my plugin:
    Code:
        @EventHandler
        public void onChatOrMute(AsyncPlayerChatEvent e) {
            Player player = e.getPlayer();
            StringBuilder str = new StringBuilder();
            str.append(e.getMessage() + " ");
            e.getFormat();
            e.setFormat(ChatColor.GREEN + player.getDisplayName() + ChatColor.DARK_GRAY + " » " + ChatColor.RESET
                    + ChatColor.translateAlternateColorCodes('&', "" + str.toString().trim()));
            if (mute.contains(player)) {
                e.setCancelled(true);
                player.sendMessage(ChatColor.RED + "Tu esi užtildytas");
            }
        }
     
    Last edited: Jun 25, 2018
  4. Offline

    timtower Administrator Administrator Moderator

    You need to change the format of the chat message for that.
     
  5. Offline

    TheCupOfTea

    Its already changed in my plugin:

    Code:
        @EventHandler
        public void onChatOrMute(AsyncPlayerChatEvent e) {
            Player player = e.getPlayer();
            StringBuilder str = new StringBuilder();
            str.append(e.getMessage() + " ");
            e.getFormat();
            e.setFormat(ChatColor.GREEN + player.getDisplayName() + ChatColor.DARK_GRAY + " » " + ChatColor.RESET
                    + ChatColor.translateAlternateColorCodes('&', "" + str.toString().trim()));
            if (mute.contains(player)) {
                e.setCancelled(true);
                player.sendMessage(ChatColor.RED + "Tu esi užtildytas");
            }
        }
     
  6. Offline

    timtower Administrator Administrator Moderator

    @TheCupOfTea Don't set the displayname or the message in there.
    Format requires two times %s
    String formatting, first one will be the displayname, second one the message. That is not something that you need to do.
     
  7. Offline

    TheCupOfTea

    Can you give me an example?
     
  8. Offline

    timtower Administrator Administrator Moderator

    e.setFormat("%s says %s")
     
  9. Offline

    TheCupOfTea

    I changed this:
    Code:
            e.setFormat(Vault ChatColor.GREEN + player.getDisplayName() + ChatColor.DARK_GRAY + " » " + ChatColor.RESET
                    + ChatColor.translateAlternateColorCodes('&', "" + str.toString().trim()));
    To this:
    Code:
            e.setFormat("%s says %s");
    
     
  10. Offline

    CommonSenze

    @TheCupOfTea
    You can still add color codes and even your " » " just make sure to have your two %s symbols in the format string.
     
  11. Offline

    TheCupOfTea

    Now color codes doesn't work
     
  12. Offline

    CommonSenze

Thread Status:
Not open for further replies.

Share This Page