PlayerMoveEvent cancel and teleport away

Discussion in 'Plugin Development' started by UltraMC, Jan 23, 2014.

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

    UltraMC

    If I cancel PlayerMoveEvent and Player will force himself to pass it he will eventually:
    - get stuck in place in forever loop of canceled events
    - die out of falling damage
    - kicked (NoCheatPlus) - Too many packets

    To bypass it I would teleport player back few blocks from location he's entering. Locations am canceling move event are WorldGuard regions.

    Any idea how to move player back a few blocks from place that he entered?
     
  2. Offline

    L33m4n123

    What do you mean? If he like keeps running into a border he is not allowed to pass?
     
  3. Offline

    UltraMC

  4. Offline

    L33m4n123

    Instead of cancel the movement event, try something like

    Code:
    player.getLocation().setVelocity(player.getLocation().getVelocity().multiply(-2));
    In theory it should launch them back
     
  5. Offline

    UltraMC

    L33m4n123 How it's calculated? I tried to move player back away based on his yaw but when he was moving backwards than it fas forcing him to calceled region.
     
  6. Offline

    L33m4n123

    No Idea what you mean. Especially with the yaw. But to move the player away directly from the direction he came from

    Code:
    player.getLocation().getDirection()
    will give you a Vector in what direction he walks. If you multiply that by -1 and force it onto him you might be able to turn him arround by 180°
     
  7. Offline

    UltraMC

    I am talking about situation when player is moving backwars.

    Was also thinking about saving every player position in List from span of last few seconds.
     
  8. Offline

    Quackster

    Has this situation been solved? If not...

    Code:
     private void moveBack(PlayerMoveEvent event) {
                    Location newLoc = event.getFrom();
                    newLoc.setX(newLoc.getBlockX() + 0.5);
                    newLoc.setY(newLoc.getBlockY());
                    newLoc.setZ(newLoc.getBlockZ() + 0.5);
                    event.getPlayer().teleport(newLoc);
    }
     
  9. Offline

    UltraMC

    Quackster No, as I'm colectiong Your advices. Will take a look at them tommorow and surley update this thread.

    L33m4n123
    The method getVelocity() is undefined for the type Location

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  10. Offline

    Bart


    player.setVelocity(player.getVelocity().multiply(-1));
     
  11. Offline

    L33m4n123


    My bad. thought it was a Method from Location. Do as Bart said.
     
  12. Offline

    UltraMC


    Kinda works. Player is launched in space if looking down btw.

    Could someone explain me what does "Velocity" of a Player mean in the first place? I am not native English speaker and cant find good translation.
     
Thread Status:
Not open for further replies.

Share This Page