Easiest way to do first join action

Discussion in 'Plugin Development' started by Wingas, Aug 1, 2014.

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

    Wingas

    easiest way to make like, if new player joins the server bukkit.broadcast("Hello, " + e.getplayer);
    otherwise, if curently joined before, bukkit.broadcast("welcome back "+e.getplayer);

    Thanks
     
  2. Offline

    TheMcScavenger

  3. Offline

    Giraffeknee

    Listen to PlayerJoinEvent and check if they've played before using event.getPlayer().hasPlayedBefore(). Wingas
     
    Wingas likes this.
  4. Offline

    B3N909

    Code:java
    1. @EventHandler
    2. public void Join(PlayerJoinEvent e){
    3. Player p = e.getPlayer();
    4. if(p.hasPlayedBefore()){
    5. Bukkit.broadcast("Welcome " + p);
    6. }else{
    7. Bukkit.broadcast("Welcome back " + p);
    8. }
     
    Wingas likes this.
  5. Offline

    TheMcScavenger

    B3N909 I wish they'd add a dislike feature for spoon feeding.

    EDIT: It's also not functioning... First you call your event "e", then refer to it as "event".
     
  6. Offline

    B3N909

    TheMcScavenger , just trying to give someone some code that maybe is new to this. Also I messed up on the event... I did not proof read :p
     
  7. Offline

    TheMcScavenger

    Yes, but the problem with that is the fact that they rarely learn from it. Most new people either know how to write it, but don't know which functions to use, or copy & paste code and don't learn from it.
     
  8. Offline

    B3N909

    TheMcScavenger its all about how the person learns.... Some people like to learn from reading for example the Java docs and Bukkit docs. I for one use examples people post in the forums for help because I learn that way, it lets me understand it better than reading something,
     
  9. Offline

    FabeGabeMC

    B3N909 why not instead of broadcasting the message, you set the Join message?
     
    Wingas and AoH_Ruthless like this.
  10. Offline

    B3N909

    FabeGabeMC Its what the guy wanted was it to be broadcasted. You could also do that!
     
  11. Offline

    AoH_Ruthless

    B3N909
    PlayerJoinEvent#setJoinMessage() is a lot better. If you are outside of the main class, Bukkit#broadcastMessage(String) is not thread-safe and could lead to future errors. But, what nobody else has pointed out is that your code is flat-out-wrong. Besides TheMcScavenger 's point, Bukkit#broadcast() requires two String parameters: the message and a permission; you are giving out wrong code because of your failure to "proof-read". When you help people, try to make sure your code actually doesn't have syntax errors in them :)
     
    Wingas likes this.
  12. Offline

    B3N909

    :( **
     
  13. Offline

    Wingas

  14. Offline

    AoH_Ruthless

Thread Status:
Not open for further replies.

Share This Page