String replaceAll Help

Discussion in 'Plugin Development' started by CONTREKEE, Mar 5, 2015.

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

    CONTREKEE

    So, when the First_Join_Message gets sent, only the color codes get translated. The "%" doesn't get switched to "Test". Can anyone help?

    Here is the code.
    Code:
        private String colorize(String input) {
            return ChatColor.translateAlternateColorCodes('&', input);
        }
    
        @EventHandler
        public void Inmate(PlayerJoinEvent e) {
           
            Player player = e.getPlayer();
           
            if(player.hasPlayedBefore()) {
               
                getConfig().set("Inmates", getConfig().getInt("Inmates") + 1);
               
                getConfig().addDefault(player.getName(), getConfig().getInt("Inmates"));
                saveConfig();
                getConfig().getString("First_Join_Message").replaceAll("%", "Test");
                e.setJoinMessage(colorize(getConfig().getString("First_Join_Message")));
            }
           
        }
     
  2. Offline

    Skionz

    Use String#replace()
     
  3. Offline

    CONTREKEE

    @Skionz Here is the updated code. Still doesn't seem to work though.

    Code:
        private String colorize(String input) {
            return ChatColor.translateAlternateColorCodes('&', input);
        }
    
        @EventHandler
        public void Inmate(PlayerJoinEvent e) {
           
            Player player = e.getPlayer();
           
            if(player.hasPlayedBefore()) {
               
                getConfig().set("Inmates", getConfig().getInt("Inmates") + 1);
               
                getConfig().addDefault(player.getName(), getConfig().getInt("Inmates"));
                saveConfig();
                getConfig().getString("First_Join_Message").replace("%", "Test");
                e.setJoinMessage(colorize(getConfig().getString("First_Join_Message")));
            }
           
        }
     
  4. Offline

    Skionz

  5. Offline

    fireblast709

    @CONTREKEE replace returns the String with the values replaced. Assign the returned value to a local variable and use that in setJoinMessage
     
    Konato_K likes this.
  6. Offline

    CONTREKEE

    @fireblast709 Example?

    @fireblast709 Nvm, I got it. Thank you very much!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    Flaps

    Bruh, just do e.setJoinMessage(colorize(getConfig().getString("First_Join_Message").replace(("%", "Test")));
     
  8. Offline

    teej107

    @CONTREKEE The replace method doesn't change the String value. It returns a new String with the characters replaced.
     
  9. Offline

    CONTREKEE

Thread Status:
Not open for further replies.

Share This Page