onPlayerJoin waiting after startup messages

Discussion in 'Plugin Development' started by jdawgerj515, Jun 17, 2013.

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

    jdawgerj515

    How do you wait until all of the playerjoin messages have been displayed by server and other plugins.

    I am trying to notify a player but it shows the message before all of the other garbage so you don't really see it for that long and it isn't that noticeable.
     
  2. Offline

    MCForger

    jdawgerj515
    Make a scheduler that runs once after a set delay of your connivence. (This code would be used with the PlayerJoinEvent)
     
  3. Offline

    slayr288

  4. Offline

    jdawgerj515

    @MCForger and @slayr288
    Ok so I have never had to delay tasks on Java before, and from looking at examples I am very confused. I keep on either getting an IllegalMonitorStateException. And when I am not getting errors it pauses the execution of the entire thread so that when a player joins they have to wait 10 seconds which is what I set it to at the "Joining Screen"
    Here is my code:

    Code:java
    1. package me.jdawgerj515.KingdomWarfare;
    2.  
    3. import java.util.Iterator;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11.  
    12. public class AllyNotify implements Listener {
    13.  
    14. public KingdomWarfare plugin;
    15.  
    16. public AllyNotify(KingdomWarfare instance)
    17. {
    18. plugin = instance;
    19. }
    20.  
    21.  
    22. @EventHandler
    23. public void notify (PlayerJoinEvent e) throws InterruptedException
    24. {
    25. Player player = e.getPlayer();
    26. String kingdom = KingdomWarfare.players.getString(player.getName() + ".Kingdom");
    27. //Sending ally request notification to King/Queen\\
    28. List<String> allyRequest = KingdomWarfare.kingdoms.getStringList(kingdom + ".AllyRequests");
    29. if (player.hasPermission("kw.kingdom.leader") && allyRequest != null)
    30. {
    31. Iterator<String> allyIT = allyRequest.listIterator();
    32.  
    33. synchronized (allyIT)
    34. {
    35. allyIT.wait(10000);
    36. }
    37. while (allyIT.hasNext() == true)
    38. {
    39. player.sendMessage(allyIT.next() + " has requested an alliance.");
    40. player.sendMessage(ChatColor.BLUE + "/kw kingdom ally [accept/deny] [KINGDOM]");
    41. }
    42. }
    43. }
    44.  
    45.  
    46.  
    47.  


    Bump. Please help guys :*(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  5. Offline

    bitWolfy

    jdawgerj515 It's really simple.
    Code:
    long delayTicks = 20L * 5;
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
        @Override
        public void run() {
           // Delayed action
        }
    }, delayTicks);
    The code above will delay the task by 5 seconds.
     
Thread Status:
Not open for further replies.

Share This Page