Checking if player moved entire block

Discussion in 'Plugin Development' started by RizzelDazz, Feb 27, 2014.

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

    RizzelDazz

    I am trying to check to see if a player moved an entire block, and if so, remove them from an ArrayList and send them a message. Right now it works, but event the slightest move of the mouse will remove them.

    Here is what I have:

    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent e){
    3. Player player = e.getPlayer();
    4. String pname = player.getName();
    5. if(notMoving.contains(pname)){
    6. notMoving.remove(pname);
    7. player.sendMessage(ChatColor.RED + "You have moved, teleportation canceled.");
    8. }
    9. }
     
  2. Offline

    Scizzr

    You could keep track of a HashMap<String, Location> (using their name as the key) and when a player moves, check that the Location.getBlockX() Location.getBlockY() and Location.getBlockZ() are the same. If not, the player moved a whole block.
     
    1 person likes this.
  3. Offline

    TryB4

    RizzelDazz
    Code:java
    1. if(e.getFrom().getX() != e.getTo().getX() || e.getFrom().getZ() != e.getTo().getZ()) { // full block }
     
  4. Offline

    RizzelDazz

    I love you.

    Edit: Do you think that this event will cause lagg?
     
  5. Offline

    TryB4

    RizzelDazz
    I use it for my survival games plugin and it doesn't seem to lag with 24 players on moving at the same time, so no.
     
  6. Offline

    CoderRyan

    @EventHandler
    public void onPlayerMoveTeleport(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if ((event.getFrom().getBlockX() == event.getTo().getBlockX()) && (event.getFrom().getBlockZ() == event.getTo().getBlockZ()) && (event.getFrom().getBlockY() == event.getTo().getBlockY())) {
    return;
    }
    if (ListsManager.warpmove.contains(event.getPlayer().getName())) {
    ListsManager.warpmove.remove(event.getPlayer().getName());
    MessageManager.sendMessage(player, ChatColor.RED + "Warp cancelled.");
    }
    }
     
  7. Offline

    Pocketkid2

    I've been using this same code and it doesn't work. Has anything changed in the new spigot 1.8 API?
     
Thread Status:
Not open for further replies.

Share This Page