Help with getting and replacing chars/words

Discussion in 'Plugin Development' started by Lewishjames, Dec 30, 2014.

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

    Lewishjames

    This is my code where I attempt to make a plugin pick up a word/char and replace it for a unicode such as the love heart which can be indicated by the \u2764

    This is my code:
    Code:
    package me.lewishjames;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    public class Emoji implements Listener{
       
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e) {
            String[] SYMBOLS = {"<3"};
            // This replaces every punctuation symbol except @ by a space
            String message = e.getMessage().toLowerCase().replaceAll("@", "a").replaceAll("\\p{Punct}", " ");
    
            for(String word : SYMBOLS){
                char heart = '\u2764';
              if(message.matches("(.* )?"+word+"( .*)?")) {
                // There has been a swear word in the message
                e.setMessage(e.getMessage().[COLOR=#ff0000]replaceAll[/COLOR](word, heart));
              } else {
                // The current swear word was not found in the message.
              }
            }
        }
    }
    And then I get an error where the red is
     
  2. Offline

    TheMintyMate

    @Lewishjames

    Change this:
    Code:
    e.setMessage(e.getMessage().[COLOR=#ff0000]replaceAll[/COLOR](word, heart));
    
    To this:
    Code:
    e.setMessage(e.getMessage.replaceAll(word,ChatColor.RED+heart));
    
    Hope this helped,
    - Minty

    *Untested code
     
Thread Status:
Not open for further replies.

Share This Page