Solved TP is breaking.

Discussion in 'Plugin Development' started by Twisted_Panda, Aug 12, 2013.

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

    Twisted_Panda

    So im making it where if you do /home near another player you have to wait 10 seconds. But when a player moves his tp doesent break.

    The actully wait part.
    Code:
            public void breaktp(Player player, TeleportQuePVPplugin tpq) {
                player.sendMessage(ChatColor.RED + "Cancelled");
                tpq.setTp(false);
                tpq.cancel();
                tplist.remove(tpq);
            }
           
            public TeleportQuePVPplugin getTP(Player player) {
                if (tplist.size() > 0) {
                    for (int i = 0; i<tplist.size(); i++) {
                        if (tplist.get(i).getPlayer().getName().equals(player.getName())) {
                            return tplist.get(i);
                        }
                    }
                }
                return null;
            }
           
            public void waittp(Player player, Location loc) {
                TeleportQuePVPplugin tpq = new TeleportQuePVPplugin(player, loc, player.getLocation());
                Timer tptimer = new Timer();
                tptimer.schedule(tpq, 10000);
                tplist.add(tpq);
            }
        }
    TeleQuePvPplugin timer.
    Code:
    public class TeleportQuePVPplugin extends TimerTask {
        Player player = null;
        Location loc = null;
        Location baseloc = null;
        boolean canTp = true;
       
        public void setTp(boolean bool) {
            canTp = bool;
        }
       
        public Player getPlayer() {
            return player;
        }
       
        public Location getBaseLocation() {
            return baseloc;
        }
       
        public TeleportQuePVPplugin(Player player, Location loc, Location baseloc) {
            this.player = player;
            this.loc = loc;
            this.baseloc = baseloc;
        }
       
        public void run() {
            try {       
                if (canTp) {
                    player.teleport(loc);
                }
                canTp = false;
                this.cancel();
            }catch(Exception ex){
                System.out.println(ex.getMessage());
            }
        }
    }
    Any suggestions on what I need to do to help me out?
     
  2. Offline

    Twisted_Panda



    Tpq
     
  3. Offline

    metalhedd

    you should be using the Bukkit scheduler instead of a TimerTask. also, You're not showing any code which calls 'breaktp' breaktp is the method that would cancel the teleport. so if you're not showing us the code where breaktp is called, then we can't tell you why it isn't working, but we HAVE to assume that it isn't being called, because you haven't demonstrated otherwise.

    Either way, I would suggest starting from scratch using the bukkit scheduler, which was made for this kind of stuff.
     
  4. Offline

    Twisted_Panda

    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            TeleportQuePVPplugin tpq = plugin.getTP(player);
            if (tpq != null) {
                if (player.getLocation().getBlockX() != tpq.getBaseLocation().getBlockX() ||
                    player.getLocation().getBlockZ() != tpq.getBaseLocation().getBlockZ()) {
                    plugin.breaktp(player, tpq);
                }
            }
        }
    }
    I'm not to good with Bukkit Scheduler D:
     
Thread Status:
Not open for further replies.

Share This Page