Solved Quick Doubt about PlayerJoinEvent

Discussion in 'Spigot Plugin Development' started by miguelrebolo, Jul 19, 2021.

  1. Hello I am trying to send two different messages.
    Player 1: "Welcome %player%"
    Player 2: "%player% Enter"
    But i get the two messages.I want:
    Player 1 receive the welcome message
    Player 2 receive the enter message but no the welcome message

    Attached Files:

  2. Code here:
    Code (Text):
    public void onPlayerJoin(PlayerJoinEvent e) {
    String join
    =Main.getInstance().getConfig().getString("Joinmsg").replace("%player%", player.getName().replace("&", "&"));
    Player player = e.getPlayer();
    for(Player p : Bukkit.getOnlinePlayers()){
    String join
    =Main.getInstance().getConfig().getString("Entermsg").replace("%player%", player.getName().replace("&", "&"));
  3. You are doing a p.sendMessage to all players.
  4. You looping over all players, even the player that joined, so you have to test if the other players is not equal to the player that joined
    Code (Java):
    for(Player otherPlayer : Bukkit.getOnlinePlayers()) {
        if(!otherPlayer.equal(player)) otherPlayer.sendMessage("Message");
  5. Thanks man, i Don't found nothing like This. It works!
  6. yo what is that code indentation