Factions and custom chat format

Discussion in 'Plugin Development' started by plisov, Aug 29, 2017.

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

    plisov

    Hi, I'm trying to add Faction names to my chat format. I have the actual name of the faction showing in chat when players chat, however it doesnt show the player's role in the faction as it usually does without a format nor does it color the names depending on the Faction's relationship with another faction. Here is what I have currently.

    Code:
    Faction faction = null;
    
            MPlayer uplayer = MPlayer.get(player);
            faction = uplayer.getFaction();
    
            tag = ChatColor.DARK_GRAY + "[" + ChatColor.RESET + faction.getName() + ChatColor.DARK_GRAY + "] ";
    
            if (player.hasPermission("chat.staff") || player.hasPermission("chat.donator")
                    || player.hasPermission("chat.builder")
                    || player.hasPermission("chat.admin") && !player.getName().equals("plisov")) {
    
                event.setFormat(tag + rank.replaceAll("&", "§") + donatorRank.replaceAll("&", "§") + ChatColor.RESET
                        + player.getDisplayName() + ChatColor.YELLOW + " » " + ChatColor.GRAY + chatColor
                        + event.getMessage());
    
            } else if (player.getName().equals("plisov")) {
    
                event.setFormat(tag + rank.replaceAll("&", "§") + donatorRank.replaceAll("&", "§") + ChatColor.RESET
                        + player.getDisplayName() + ChatColor.YELLOW + " » " + ChatColor.GRAY + chatColor
                        + event.getMessage());
            } else {
    
                event.setFormat(tag + rank.replaceAll("&", "§") + donatorRank.replaceAll("&", "§") + ChatColor.RESET
                        + player.getDisplayName() + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + chatColor
                        + event.getMessage());
            }
        }
    Yes, I looked at the Factions developer page. Didn't really help.

    Any help is much appreciated,
    plisov
     
  2. Offline

    timtower Administrator Administrator Moderator

    @plisov You don't add the message and displayname to the format.
    You use "%s" twice, first one will be the displayname, second one will be the message.
     
  3. Offline

    ThePandaPlayer

    @plisov
    Where is this 'event' variable coming from? Is this an AsyncPlayerChatEvent?
    Also, player.setDisplayName(name) does not work for players. The only way to change it is to use a scoreboard prefix.
     
  4. Offline

    plisov

    @timtower @ThePandaPlayer The chat itself is working the way I need it to however the Faction name isnt. All it shows it the faction name without relationship color and player roles.
     
  5. Offline

    ThePandaPlayer

    @plisov
    I asked if this is an AsyncPlayerChatEvent because you can just do this:
    Code:
    @EventHandler
    public void onChat(AsyncPlayerChatEvent e) {
        if(e.getPlayer().hasPermission(/*permission here*/) {
            e.setMessage(/*how you want the message to go*/);
        }
    }
     
  6. Offline

    plisov

    Yes it is however I need to change the format itself. I have the format changed but the faction name doeasnt show relationship colors and player roles in the faction.
     
  7. Offline

    ThePandaPlayer

    @plisov
    What I'm saying is, you don't need to change the chat format. You just add if statements checking for permissions and change the message accordingly.
     
Thread Status:
Not open for further replies.

Share This Page