Solved Config placeholders?

Discussion in 'Spigot Plugin Development' started by Waldxn, Apr 24, 2017.

  1. Having some trouble figuring out where to add the #replace("%player%", player.toString()) method. Any help?

    Code (Text):
     public void onJoin(PlayerJoinEvent e) {
           
            Player player = e.getPlayer();

            for (int i = 0; i < this.plugin.getConfig().getStringList("Welcome Messages").size(); i++) {

                player.sendMessage(ChatColor.translateAlternateColorCodes('&',
                        this.plugin.getConfig().getStringList("Welcome Messages").get(i)));
                e.setJoinMessage(null);


            }
        }
     
  2. I'm still having issues with this!
     
  3. you could use java 8 stream api:

    Code (Java):

    getStringList("example").stream().map(s -> s.replace("%var%", varValue).collect(Collectors.toList()).forEach(s -> player.sendMessage(s));
     
    • Like Like x 1
  4. Put it right after the get(i)


    Code (Text):
            for (int i = 0; i < this.plugin.getConfig().getStringList("Welcome Messages").size(); i++) {

                player.sendMessage(ChatColor.translateAlternateColorCodes('&',
                        this.plugin.getConfig().getStringList("Welcome Messages").get(i)));
                e.setJoinMessage(null);


            }
    You do realize that you're setting the join message to null every single time you loop, right? you should consider moving that outside of your Forloop.
     
    • Useful Useful x 2
  5. FrostedSnowman

    Resource Staff

    you're a fucking legend :O

    i need to learn the stream api
     
  6. Thanks for the help!!!
     
  7. FrostedSnowman

    Resource Staff

    did u use @ChefJava 's method? it really would be the most suitable
     
  8. Not yet. May switch to the Java 8 API in a later date. Want to stay with what I'm most comfortable with for now. Once I start looking into the Java 8 API more I will go back over this