Solved Replacing words

Discussion in 'Plugin Development' started by Garnet638, May 2, 2015.

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

    Garnet638

    I am trying to make a plugin that adds "emojis" by replacing words with the corresponding symbol, but when I try it, it does this:
    [​IMG]
    [.] is supposed to make •, [radioactive] is supposed to make ☢, ect.
    The code is here
    Show Spoiler

    ChatEmojis.java
    Code:
    package io.github.garnet638;
    
    import java.util.List;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ChatEmojis extends JavaPlugin{
       
        @Override
        public void onEnable(){
        this.saveDefaultConfig();
        }
       
        @Override
        public void onDisable(){
           
        }
       
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            String message = e.getMessage();
            List<String> shortcut = ChatEmojis.this.getConfig().getStringList("shortcut");
            List<String> emoji = ChatEmojis.this.getConfig().getStringList("emoji");
            int listlength = shortcut.size();
            for(int i=1; i<listlength; i++){
               
                message = e.getMessage().replace(shortcut.get(i), emoji.get(i));
               
            }
            e.setMessage(message);
        }
    }
    
    config.yml
    Code:
    #In the first list, put the shortcut
    #In the second list, put the "emoji" corresponding to the shortcut
    #ex
    #shortcut:
    #  - [.]
    #  - [radioactive]
    #emoji:
    #  - •
    #  - ☢
    #
    #REMEMBER TO SAVE AS UTF-8
    #OR ELSE IT WILL NOT WORK
    #
    shortcut:
      - [:)]
      - [.]
      - [radioacive]
      - [biohazard]
      - [whiteflag]
      - [sun]
      - [check]
    emoji:
      - ☺
      - •
      - ☢
      - ☣
      - ⚐
      - ☀
      - ✔
    

    There are no permissions, and all of the symbols have worked pasted into MC
     
  2. Offline

    Konato_K

    The brackets are a special character in YML, try putting them in quotes.
     
  3. In case you are not using yml, it also isn't supported in replaceAll, put 2 backslashes before each [ and ]
     
  4. Offline

    Evaluations

    You also aren't registering your events.
     
    Konato_K likes this.
  5. And your class doesn't implement Listener

    he's using .replace, not replaceAll

    why not just
    Code:
    getConfig()
     
  6. Offline

    Garnetty

    Extremely off topic but you're the first "other" Garnet that I've ever seen in my life
     
  7. @FisheyLP
    Yeh I didn't notice the code spoiler first :p so I didn't see his code
     
Thread Status:
Not open for further replies.

Share This Page