Solved Replacing player's name in chat.

Discussion in 'Plugin Development' started by q8minecraft, Nov 6, 2015.

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


    I've been trying to replace the player's name in chat when the player gets called. For example

    Player1: Player2 How are you?

    This is what I got so far..
        public void onchat(PlayerChatEvent e) {
            String msg = e.getMessage();
            String name = e.getPlayer().getName();
            for(Player player : Bukkit.getOnlinePlayers()){
                    msg.replace(player.getName(), ChatColor.YELLOW + player.getName() + ChatColor.WHITE);
                    player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1F, 1F);
    Thanks in advance!
  2. Offline


    So, what's your problem? Does your code not work? Did you debug?

    If this is a post that is basically asking "hows it look", then you posted in the wrong section.
  3. Offline


    @Zombie_Striker I can hear the sound, but the text itself isn't changing color.
  4. Offline


    You have to actually set it. String#replace will return a new string.
    edit: e.setMessage(e.getMessage().replace("123", "456"));
    q8minecraft likes this.
  5. Offline


    @Hawktasard oh, I thought I only needed to replace it, silly me :p
  6. Offline


    If your problem is resolved, edit the title of your thread and mark it as solved, thanks
    q8minecraft likes this.
  7. Offline


    @Scimiguy I sincerely apologize, forgot to do that. Thanks!
Thread Status:
Not open for further replies.

Share This Page