.replaceAll - MyPlayerListener

Discussion in 'Spigot Plugin Development' started by ChazzaPlays, Jun 12, 2015.

  1. Hello,
    Im wanting to have a player listener with a join message, that would be broadcasted to every one, it has a config and i want to replace a variable %p with the players name from the config. I have tried to do this however i get:
    1. Use String#replace(String, String) rather than String#replaceAll(String, String)
    2. Use Player#getName() rather than Player.
    • Like Like x 1
  2. Thanks it worked,i just want to replace %p in the config with te plyers name but wont work.
    Code (Text):
                Player player = event.getPlayer();
                String joinmessage = Main.getPlugin().getConfig().getString("joinmessage").replace("&" , "§");
                if (player.hasPermission("testplugin.joinmessage")); {
                    Bukkit.broadcastMessage(joinmessage.replace("%p", player.getName()));
    • Use ChatColor.translateAlternateColorCodes('&', yourString) rather than replace('&', 'section sign').
    • The ; behind your if statement renders the if statement useless - it will always broadcast regardless whether the player has the permission or nog.
    • Have you registered your Listeners?