Solved Run event after player joins

Discussion in 'Plugin Development' started by MasterDoctor, Feb 25, 2016.

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

    MasterDoctor

    I want to run something after a player has joined and logged into the server.
    How can I do it?
    I tried running it in the PlayerJoinEvent code but it didn't work because it ran before the player logged in.
     
  2. Offline

    mythbusterma

    @MasterDoctor

    PlayerJoinEvent runs after the player is spawned into the world. What's your issue?
     
  3. Offline

    MasterDoctor

    It doesn't. It runs before. The player is not shown as logged in and the terrain is not loaded.
     
  4. Offline

    teej107

    @MasterDoctor whether it runs before or after doesn't matter. Run it in a task!
     
  5. Offline

    MasterDoctor

    How? What is running something in a task?
     
  6. Offline

    Zombie_Striker

  7. Offline

    teej107

  8. Offline

    MasterDoctor

    Thanks for your help @teej107 ! I managed to finish it myself and for anyone else out there who might find this useful, here's how I did it:
    Code:
    BukkitScheduler sch = Bukkit.getServer().getScheduler();
    /*
    Asynchronously because it runs it separately (allowing other things to run) but the task must not use any Bukkit methods...
    I suppose this is important for a minigame lobby xD
    */
    sch.runTaskLaterAsynchronously(plugin, new JoinTask(), 20L);
    Then I just suppress depreciation warnings:
    Code:
    @SuppressWarnings("deprecation")
    and for anyone who comes across this thread and wants more help, here's my JoinTask class:
    Code:
    package com.goldblockstudios.masterdoctor.onevsone.util;
    
    import org.bukkit.ChatColor;
    import org.bukkit.scheduler.BukkitRunnable;
    
    import com.goldblockstudios.masterdoctor.onevsone.Main;
    
    public class JoinTask extends BukkitRunnable {
    
        public JoinTask(){
        
        }
    
        @Override
        public void run(){
            XpBar xpBar = new XpBar();
            xpBar.runXpCountdown(20, Main.plugin);
            Title title = new Title("Please wait...","You are being teleported to the arena...");
            title.setTitleColor(ChatColor.GREEN);
            title.setSubtitleColor(ChatColor.GREEN);
            title.setFadeOutTime(5);
            title.broadcast();
        }
    
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Feb 25, 2016
  9. Offline

    teej107

    @MasterDoctor Just pointing out that indeed your code doesn't look like its running Bukkit methods, if that code in your code is running Bukkit methods then it is still calling those methods asynchronously and therefore you should run it on the main thread.
     
    MasterDoctor likes this.
  10. Offline

    MasterDoctor

    OK, Thanks
     
Thread Status:
Not open for further replies.

Share This Page