[REQ] Automatically replace words

Discussion in 'Archived: Plugin Requests' started by MrCobayo, Feb 19, 2012.

  1. Offline

    MrCobayo

    For example, i write "OMG" and the chat shows "OH MY GOD".
    And could add colors "&3OH &3MY &3GOD"

    Is a great idea!

    Sorry for my english. Greetings for Argentina <3
     
  2. Offline

    dillyg10

    iChat might actually do this...
     
  3. Offline

    JJJollyjim

    I actually made a custom thing exactly like this for my old server, although I can't seem to find it, and the words were hard-coded in.

    I'll have a try if I have any spare time!
     
  4. Offline

    notrodash

    I dont have the time to code this plugin right now, but you can try this EventHandler
    Code:
    @EventHandler
    public void playerChat(PlayerChatEvent event)
    {
    event.setMessage(event.getMessage().replaceAll("OMG", "Oh My God, like TOTALLY!"));
    }
    
    Just make it read the words of a YML file or hard code them in :D
    Sadly though it doesnt ignore the case... yet.
     
  5. Offline

    Wolfy9247

    So if you had a config like:
    Code:
    AutoReplace:
        Replace Words:
            - 'omg'
        Replacements:
            - '&5Oh. My. Gosh!'
    
    You'd want something like:
    Code:java
    1.  
    2. public class AutoReplaceListener implements Listener {
    3.  
    4. public String processPrint(String printout) {
    5.  
    6. String temp = printout;
    7.  
    8. index = temp.indexOf("&");
    9.  
    10. if(index != -1) {
    11. temp = convertToColor(temp);
    12. /* The convertToColor method comes from the 'Colors' plugin. It's open-source on
    13.   * GitHub. You just have to tweak it a bit to fit your needs here.
    14.   */
    15. }
    16. return temp;
    17. }
    18.  
    19. @EventHandler
    20. public void onPlayerChat(PlayerChatEvent e) {
    21. String message = e.getMessage();
    22. Object[] replaceWords = config.getList("AutoReplace.Replace Words").toArray();
    23. Object[] replacements = config.getList("AutoReplace.Replacements").toArray();
    24. for(int i = 0; i < replaceWords; i++) {
    25. if(message.equalsIgnoreCase(replaceWords.toString())) {
    26. e.setMessage(message.replaceAll(replaceWords.toString(), processPrint(replacements.toString())));
    27. break;
    28. }
    29. }
    30. }
    31. }
    32. [I][/I]


    Keep in mind: I'm not an expert at Java in any way, so some things with the lists and calls may be wrong, but this is the type of format you'd basically be looking at.
     

Share This Page