Can't Move, but can view! How to make ?

Discussion in 'Plugin Development' started by Lurieder, Sep 1, 2014.

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

    Lurieder

    Pls help me! how can i make that the player cant move equals he is or he isnt on ground ? But he can view around!
     
  2. Offline

    mine-care

    Lurieder wait you want players to be able to spin arround but not move?
    Easy!
    in your PlayerMoveEvent:
    Code:java
    1. if (e.getFrom().getBlockX() == e.getTo().getBlockX() && e.getFrom().getBlockZ() == e.getTo().getBlockZ() && e.getFrom().getBlockY() == e.getTo().getBlockY()) return; //if he is just spining arround, let him
    2. e.setCanceled(true); // if he is changing block (moving) Sop him.
     
  3. Offline

    jojo1541

    i'm not sure if i fully understood your question but just check if the player is flying and cancel all move events which would change the block the player is standing on.
     
  4. Offline

    MineStein

    Just like Mine-care said. Listen for the PlayerMoveEvent. This event is fired whenever their x, y, z, pitch, or yaw values change. When they move have an if statement that checks if the x, y, and z are the same. Use the Player#getTo/getFrom methods and then use getX, getY, etc.

    Also, if you have buggy movement when their y changes (jumping/falling), remove that check.
     
    mine-care likes this.
  5. Offline

    Lurieder

    mine-care thx for you help! But i also mean if he is in the air he also stop falling down and stand in the air for 5 sec !
    In this time he can spin around but can move forward backward...!
     
  6. Offline

    hintss

    set them to flying, cancel downward movements?
     
    mine-care likes this.
  7. Offline

    mine-care

    Lurieder then remove this bit of the code i send you :
    Code:java
    1. && e.getFrom().getBlockY() == e.getTo().getBlockY()

    and make your code above look like dis:
    Code:java
    1. if (e.getFrom().getBlockX() == e.getTo().getBlockX() && e.getFrom().getBlockZ() == e.getTo().getBlockZ()) return; //if he is just spining arround, let him
    2. if( e.getFrom().getBlockY() == e.getTo().getBlockY()){
    3. player.setFlying(true); //set player flying so he is frozen on air
    4. player.teleport(e.getFrom());//NOT TESTED! this is an atempt to put him back to where he was.
    5. return;
    6. }
    7. e.setCanceled(true); // if he is changing block (moving) Stop him...
    8.  

    if that doesnt work, you can try this:
    Code:java
    1. if(e.getFrom().getBlockX() == e.getTo().getBlockX() && e.getFrom().getBlockZ() == e.getTo().getBlockZ()) return; //if he is just spining arround, let him
    2. if(e.getFrom().getBlockY() == e.getTo().getBlockY()){
    3. player.setFlying(true); //set player flying so he is frozen on air
    4. player.teleport(player.getLocation());//Teleport him to his own location so he is standing on the same spot...
    5. return;
    6. }
    7. e.setCanceled(true); // if he is changing block (moving) Stop him...
    8.  

    but you may face problems with NoCheat or anticheat ect ect ect

    WARN: you may want to make players disable flying to keep this working...^ (even though it already sets them flying when hey fall from a place.)
    Hoppe i helped
     
  8. Set them to flying is a good choice, as anti-cheating plugins are more likely to accept it :p. I wouldn't just cancel the moves, but instead store a location to teleport them back to, because CraftBukkit does not put through every single player move. Instead CB will skip events with a too small change in both looking direction and distance, thus you can have different from+to+player locations when a moving event is processed. In fact if you do it wrongly, a cheater might be able to fly slowly.

    Actually i am not sure if cancelling would be alright, because player.getLocation() might be the culprit (differ from last from-location), however there have been oddities with CB updating moves wrongly/strangely in relation to vehicles, so i still think that storing the login location/coordinates for setting back to there is the best way to go.
     
  9. Offline

    hintss

    Set them to flying, cancel sneaking?
     
  10. Cancel sneaking shouldn't really do much, because the client is too much in control of things, especially cheat clients can still send moves, no matter what other events you cancel or not cancel. So if you have cheating in mind, you need to ensure you set back to the freeze-location, and i would say storing the location and setting back to there is the most reliable way to do it (setTo in moving events and teleport if anything strange occurs). In addition setting to flying will help vanilla clients to stay in air or wherever if that should be the case. You could also set a very low fly speed.
     
Thread Status:
Not open for further replies.

Share This Page