Change Location on Disconnect

Discussion in 'Plugin Development' started by SteppingHat, Jun 30, 2012.

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

    SteppingHat

    So, I'm making a plugin where a user teleports to one player and is teleported back after a set amount of time. Everything works fine but there's an exploit. Upon disconnect, the timer stops and the user stays where they are on reconnect and aren't teleported back.

    So is there a way where I can make it so that when they disconnect, their last location which has been saved to a variable is made their location when they log back in?

    The code for the timer portion of the plugin is below
    Code:
    this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
        int userseconds = getConfig().getInt("teleporttime");
        int halfseconds = configseconds / 2;
        int quarterseconds = configseconds / 4;
        public void run() {
            if(userseconds != -1) {
                if(userseconds != 0) {
                    if(userseconds == halfseconds) {
                        player.sendMessage(ChatColor.YELLOW + "" + userseconds + ChatColor.RED + " seconds left");
                    }
                    if(userseconds == quarterseconds) {
                        player.sendMessage(ChatColor.YELLOW + "" + userseconds + ChatColor.RED + " seconds left");
                    }
                    if(userseconds == 3) {
                        player.sendMessage(ChatColor.YELLOW + "" + userseconds + ChatColor.RED + " seconds left");
                    }
                    userseconds--;
                } else {
                    player.teleport(originalPlayerLocation);
                    userseconds--;
                    player.sendMessage(ChatColor.RED + "Your time has expired and you have been teleported back");
                }
            }
        }
    }, 0L, 20L);
    Thanks in advance for all your help!
     
  2. Offline

    nehuskerfan2

    Make it so onPlayerQuit(PlayerQuitEvent event) OR WHATEVER ITS CALLED will set their location to the originalPlayerLocation.
     
  3. Offline

    SteppingHat

    How can I do this? I've already got a listener set up:
    Code:
    package com.gmail.steppinghat;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerQuitEvent;
     
    public class PlayerListener implements Listener {
     
        @EventHandler
        public void onPlayerDisconnect(PlayerQuitEvent event) {
            //something I don't know goes here
        }
     
    }
    and in the main class:
    Code:
    ...
    public final PlayerListener pl = new PlayerListener();
     
    @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.pl, this);
    ...
    so what do I need to do and if I have done something wrong, what is it?

    I appreciate all your help. Thanks heaps!
     
  4. Hmmm you could just teleport them when they quit?
     
  5. you can try an hacky methode, do player.saveData() after the teleport, but another exploit wil be, logging in before the teleport is
     
  6. Offline

    SteppingHat

    Can't I just get it to save the player name to a hashmap if they are in the process of a countdown? That way when they log in, it checks if they were in the process before disconnect and will teleport them to their original location?

    I've tried to get this to work too but I'm having trouble sharing variables and hashmap data between the two different classes (TempTeleport.class and PlayerListener.class)
     
Thread Status:
Not open for further replies.

Share This Page