Solved Scheduler causes disconnect.genericReason

Discussion in 'Plugin Development' started by Metal Julien, Mar 16, 2013.

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

    Metal Julien

    Hi, I'm trying to make a afk plugin. Player should be AFK whenever he doesn't move for 30 secs. Now, everytime I move, I get kicked. Console: lost connection: disconnect.genericReason.

    PHP:
     
       HashMap
    <PlayerBukkitTaskmap = new HashMap();
     
     
    On p move...
     
     
            if (
    map.get(p) != null) {
                 
                
    map.get(p).cancel();
                }
             
                
    BukkitTask bt Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                    public 
    void run() {
                        
    sp.sendMessage(ChatColor.DARK_RED "You're now away from keyboard.");
                        
    sp.setTitle(ChatColor.DARK_RED "AFK");
             
     
                     
                     
                    }
                }, 
    600);
                
    map.put(pbt);
             
                
     
  2. Offline

    LudicrousYoshi

    what version of craftbukkit are you using?
     
  3. Offline

    Metal Julien

    1.4.7-R1.0
     
  4. Offline

    LudicrousYoshi

    Does the console give you any error messages aside from the generic disconnect?
     
  5. Offline

    Metal Julien

  6. Offline

    Sagacious_Zed Bukkit Docs

    More context may help in identifying the issue.
     
  7. Offline

    LudicrousYoshi

    ok since I can't see anything directly wrong with what you have, I'd like you to try this diagnosing technique I use.

    Put a log.info message after every single line just with like a number 1 through n and see how many numbers the console prints before it disconnects you. This way you can see what line is actually the cause of the disconnect, or at least rule out the lines after the disconnect.

    Another thing, it probably isnt, but i wouldnt discount trying to run it with a 1.5 dev server in case 1.4.7 R1 has some random unknown error nobody has noticed yet.
     
  8. Offline

    Metal Julien

    Code:
    Bukkit.broadcastMessage("0");
                if (map.get(p) != null) {
               
               
                map.get(p).cancel();
                }
               
                Bukkit.broadcastMessage("1");
                BukkitTask bt = Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                   
                    public void run() {
                        sp.sendMessage(ChatColor.DARK_RED + "You're now away from keyboard.");
                        sp.setTitle(ChatColor.DARK_RED + "AFK");
               
     
                       
                       
                  }
                }, 600);
                Bukkit.broadcastMessage("2");
                map.put(p, bt);
                Bukkit.broadcastMessage("3");
    Console goes prints 0 1 2 3
    Connection reset
    Metal_Julien lost con... genericReason
    LudicrousYoshi
     
  9. Offline

    LudicrousYoshi

    Humor me and try it on a 1.5 server xD

    It would also be nice if you could post more of the class since the problem doesnt appear to be directly in the block of code you posted. I'm also assuming this is the only plugin running at the moment, correct?
     
  10. Offline

    Metal Julien

    1. I can't, the sense of the plugin is changing the player title with spout, and there's no spoutplugin 1.5 build.
    2. Its with spout and another plugin by me the only one.
    3.
    Code:
    package me.metaljulien.bukkit.QuestsSpout;
     
    import java.util.HashMap;
     
    import net.minecraft.server.v1_4_R1.Packet70Bed;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitTask;
    import org.getspout.spoutapi.SpoutManager;
    import org.getspout.spoutapi.player.SpoutPlayer;
     
    public class Move implements Listener {
        public int ox;
        public int oz;
        private JavaPlugin plugin;
       
        public Move(JavaPlugin plugin) {
            this.plugin = plugin;
        }
        HashMap<Player, BukkitTask> map = new HashMap();
       
       
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
           
       
           
           
           
       
           
           
            Location loc = e.getPlayer().getLocation();
            Player p = e.getPlayer();
     
       
            Location left = loc.clone();
            Location right = loc.clone();
            Location sbloc = loc.clone();
            sbloc.setY(loc.getY()-1);
            left.setY(loc.getY()-1);
            right.setY(loc.getY()-1);
           
       
            if (((int) loc.getX()) != ox ||((int) loc.getZ()) != oz) {
           
               
               
                ox = (int) loc.getX();
                oz = (int) loc.getZ();
               
                /*
                final SpoutPlayer sp = (SpoutPlayer) p;
                sp.setTitle(null);
               
               
                if (map.get(p) != null) {
               
               
                map.get(p).cancel();
                }
               
           
                BukkitTask bt = Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                   
                    public void run() {
                        sp.sendMessage(ChatColor.DARK_RED + "You're now away from keyboard.");
                        sp.setTitle(ChatColor.DARK_RED + "AFK");
               
     
                       
                       
                  }
                }, 600);
               
                map.put(p, bt);
           
                */
               
               
               
            }
           
           
           
           
        }
       
       
     
       
       
    }
    
     
  11. Offline

    LudicrousYoshi

    Alright try my diagnosing thing again but put a broadcast before every block code in the onMove. There should probably be about 10 or more; the more you have the more precise you can be about what is happening. The reason I'm asking you to do it with the whole event is because I want to see if the problem might be happening halfway through the second call and this will help you see if it is actually even making it to a second call.

    PS- will be gone for a few hours, sorry if I don't respond quickly next time.
     
    Metal Julien likes this.
  12. Offline

    Metal Julien

    LudicrousYoshi , Every line get called before kicking me.
    Code:
    package me.metaljulien.bukkit.QuestsSpout;
     
    import java.util.HashMap;
     
    import net.minecraft.server.v1_4_R1.Packet70Bed;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitTask;
    import org.getspout.spoutapi.SpoutManager;
    import org.getspout.spoutapi.player.SpoutPlayer;
     
    public class Move implements Listener {
        public int ox;
        public int oz;
        private JavaPlugin plugin;
       
        public Move(JavaPlugin plugin) {
            this.plugin = plugin;
            Bukkit.broadcastMessage("0");
        }
        HashMap<Player, BukkitTask> map = new HashMap();
       
     
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Bukkit.broadcastMessage("1");
     
       
           
           
           
       
           
           
            Location loc = e.getPlayer().getLocation();
            Bukkit.broadcastMessage("2");
            Player p = e.getPlayer();
            Bukkit.broadcastMessage("3");
     
       
            Location left = loc.clone();
            Location right = loc.clone();
            Location sbloc = loc.clone();
            sbloc.setY(loc.getY()-1);
            left.setY(loc.getY()-1);
            right.setY(loc.getY()-1);
            Bukkit.broadcastMessage("4");
       
            if (((int) loc.getX()) != ox ||((int) loc.getZ()) != oz) {
                Bukkit.broadcastMessage("5");
               
               
                ox = (int) loc.getX();
                oz = (int) loc.getZ();
                Bukkit.broadcastMessage("6");
               
               
                final SpoutPlayer sp = (SpoutPlayer) p;
                Bukkit.broadcastMessage("7");
                sp.setTitle(null);
                Bukkit.broadcastMessage("8");
               
               
                if (map.get(p) != null) {
                    Bukkit.broadcastMessage("9");
               
               
                map.get(p).cancel();
                Bukkit.broadcastMessage("10");
                }
               
                Bukkit.broadcastMessage("11");
                BukkitTask bt = Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                   
                    public void run() {
                        Bukkit.broadcastMessage("12");
                        sp.sendMessage(ChatColor.DARK_RED + "You're now away from keyboard.");
                        sp.setTitle(ChatColor.DARK_RED + "AFK");
               
     
                       
                       
                  }
                }, 600);
                Bukkit.broadcastMessage("13");
                map.put(p, bt);
                Bukkit.broadcastMessage("14");
               
               
               
               
            }
            Bukkit.broadcastMessage("15");
           
           
           
        }
       
       
     
       
       
    }
    
    LudicrousYoshi I found the mistake! Players title cannot be null, it needs to be "". Thank you really much for your help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  13. Offline

    LudicrousYoshi

    Not sure if I actually helped that much haha, but you're welcome! :D
     
Thread Status:
Not open for further replies.

Share This Page