PlayerJoinEvent not sending before MOTD?

Discussion in 'Spigot Plugin Development' started by Moderance, May 21, 2016.

  1. So basically, I want it so the PlayerJoinEvent sends the message of the day, here is what I have done so far:

    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            //So this sends first, at the moment it is sending this AFTER the 'welcome back.. ' part.
            event.setJoinMessage(ChatColor.GREEN + "+" + ChatColor.GRAY +  player.getName());
           
            //motd
            player.sendMessage("Welcome back" + player.getName());
        }
     
  2. Inkzzz

    Resource Staff

    Just add a Scheduled Delayed Task
     
    • Agree Agree x 1
  3. Put a BukkitRunnable around your sendMessage line,

    Code (Text):
           
            new BukkitRunnable() {
               
                @Override
                public void run() {
                    // TODO send message
                }
            }.runTask(plugin);
    Should do the job :)
     
  4. Sorry - another question why can't I do this:

    Code (Text):
    player.sendMessage(ChatColor.GOLD + ChatColor.STRIKETHROUGH + ChatColor.BOLD + "================================");
    I this error: The operator + is undefined for the type of arguement(s)
     
  5. Inkzzz

    Resource Staff

    ChatColor.GOLD + ChatColor.STRIKETHROUGH.toString() + ChatColor.BOLD
     
    • Agree Agree x 1
  6. Code (Text):
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5&m&l=============================="));
    ?
     
    • Useful Useful x 1
  7. Thanks

    Will this work..?

    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            event.setJoinMessage(ChatColor.GREEN + "+ " + ChatColor.GRAY +  player.getName());
       
            new BukkitRunnable() {
               
                @Override
                public void run() {
                    player.sendMessage(ChatColor.GOLD + ChatColor.STRIKETHROUGH.toString() + ChatColor.BOLD + "================================");
                }
            };
        }
     
  8. No, you forgot .runTask(plugin); as shown in my example :p
     
  9. Sorry, where would I put it in mine?
     
  10. Code (Text):
    new BukkitRunnable() {
               
                @Override
                public void run() {
                    player.sendMessage(ChatColor.GOLD + ChatColor.STRIKETHROUGH.toString() + ChatColor.BOLD + "================================");
                }
            }.runTask(plugin);
     
  11. Where do I get the (plugin) from, at the moment its underlined red?
     
  12. Inkzzz

    Resource Staff

    Your class that extends JavaPlugin
     
  13. Er..?

    Code (Text):
    public class PlayerListener extends JavaPlugin {

    //code

    }.runTask(PlayerListener);
    Still underlined red.
     
  14. Inkzzz

    Resource Staff

    Perhaps java should be concentrated on before application interference programs'.
     
  15. @Moderance
    Code (Java):
    ChatColor.GOLD + "" + ChatColor.BOLD;
    is also edible

    but if you want some short way

    Code (Java):
    ChatColor.translateAlternateColorCodes('&', String message);

     
  16. Yes, I noticed \n doesn't work now I am using the .translateAlternateColorCodes do you know what I can use instead?
     
  17. hmm same problem with me but I did
    Code (Java):
    .replace("%n", \n);
    now perfectly works I'm not sure if it would work to you.