1.16.5 Checking player name doesnt work?

Discussion in 'Spigot Plugin Development' started by Bluehawk409, May 7, 2021.

  1. Im trying to make a plugin that only works for a specific player, SprayPaynt (me). I want it to send me a message when I sneak, but when I sneak the message meant specifically for me does not send. Here is the code:

    Code (Text):
    public void onPlayerToggleSneakEvent(PlayerToggleSneakEvent event) {
    Player player = event.getPlayer();
            player.sendMessage("Hello you!");
            if (player.getName() == "SprayPaynt") {
                player.sendMessage("HI me!");
            }

    }
    My username is SprayPaynt, when I sneak, it sends me the "Hello You" message but not the "Hi Me" message. What do I do?
     
  2. String equality is checked with .equals() or .equalsIgnoreCase(), not with '==' in java
     
    • Agree Agree x 1
  3. Thanks!
     
  4. Tipp: If you wan't to compare to a exact Player, don't compare their names. The Users are able to change it. Use their UUID
    Player#getUniqueId
    and
    UUID.fromString("uuid of your player")

    You can find the UUID of players on pages like this:
    https://namemc.com/profile/SprayPaynt.1
     
    • Like Like x 1