Send message only once in on player move event

Discussion in 'Plugin Development' started by slater96, Dec 24, 2012.

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

    slater96

    Hello, the problem is that when someone moves on the block, the message is being sent whenever they move. How can I make it only be sent once?
    Code:
    @EventHandler
        public void onMovement(PlayerMoveEvent event) {
            final Player p = event.getPlayer();
            if (p.hasPermission("multiwarp.use")) {
                Block blockBelow = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
                if (this.blockLocations.containsValue(blockBelow.getLocation())) {
                    p.sendMessage(ChatColor.DARK_GREEN + "Teleporting in " + ChatColor.GREEN + "3 seconds!");
                    this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        @Override
                        public void run() {
                            //teleport
                        }
                    }, 60L);
                }
            } else {
                p.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
            }
        }
     
  2. Offline

    gomeow

    You would need to implement a cool down. The search bar could yield a lot of info on that matter.
     
  3. Offline

    drampelt

    You could use event.getFrom() and event.getTo() and check if the blocks are the same.
     
Thread Status:
Not open for further replies.

Share This Page