Sending a certain player a message on join event.

Discussion in 'Plugin Development' started by CBaer4848, Oct 30, 2014.

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

    CBaer4848

    So I've been trying to send a certain player a message when they join. Say their in game name is "Testing123", how would I send them a message on the player join event? :confused:
     
  2. Offline

    Gnat008

    CBaer4848
    Easy. Check if their name is a certain name in an if statement.
    Code:
    if (event.getPlayer().getName().equals("aName")) {
        // Do stuff
    }
     
  3. Offline

    CBaer4848

    Thanks, I was using this and it wasn't working :p
    Code:
    if(event.getPlayer().getName() == ("name") {
    // do shiz
     
  4. Offline

    OffLuffy

    Don't use ==, use .equalsIgnoreCase() or .equals() if you need the case-sensitivity. There IS a difference. The '==' checks if non primitive data types are exactly the same object.
     
    Gnat008 likes this.
  5. Offline

    Gnat008

    CBaer4848
    You cannot compare Strings like that because they are Objects. This StackOverFlow thread might say it better than I can. In short, don't use '==' to compare Objects, only primitive data types and enums.
     
    OffLuffy likes this.
Thread Status:
Not open for further replies.

Share This Page