Cancel player movement but allow rotating ??

Discussion in 'Plugin Development' started by ThunderWaffeMC, Mar 2, 2014.

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

    ThunderWaffeMC

    Hi. Is it possible to stop players from moving coords? I only want players to be able to rotate their perspective but not to be able to move. The code below makes it so they can still move around on the block but I wont to cancel that entirely:

    Code:java
    1.  
    2. @EventHandler
    3. public void movement(PlayerMoveEvent event) {
    4. Player player = event.getPlayer();
    5. Double xTo = event.getTo().getX();
    6. Double xFrom = event.getFrom().getX();
    7. Double yTo = event.getTo().getY();
    8. Double yFrom = event.getFrom().getY();
    9. Double zTo = event.getTo().getZ();
    10. Double zFrom = event.getFrom().getZ();
    11. if(event.getTo().locToBlock(xTo) != event.getFrom().locToBlock(xFrom) || event.getTo().locToBlock(zTo) != event.getFrom().locToBlock(zFrom) || event.getTo().locToBlock(yTo) != event.getFrom().locToBlock(yFrom)) {
    12. player.teleport(event.getFrom());
    13. }
    14. }
    15.  
     
  2. Offline

    spiroulis

    ThunderWaffeMC hmm what if you gave the player a slowness effect instead?
     
  3. Offline

    ThunderWaffeMC

    Nah, but surely there would be something better to use.
     
  4. Offline

    ThunderWaffeMC

    Bump. Any ideas?
     
  5. Offline

    MisterPhiloe

    It would be more efficient if you just cancel the players movement with an event.
     
  6. Offline

    Barinade

    ThunderWaffeMC and 97waterpolo like this.
  7. Offline

    DarkBladee12

    Barinade you should stay away from doing that, because it causes weird things to happen...
     
  8. Offline

    The Fancy Whale

    DarkBladee12 Barinade It works so they can't move. It just looks like they are sitting, which depending on what you are doing might not matter
     
  9. ThunderWaffeMC
    Code:java
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onMove(PlayerMoveEvent e) {
    3. Player player = e.getPlayer();
    4. if (switching.contains(player.getName())){
    5. Location from = e.getFrom();
    6.  
    7. if (from.getZ() != e.getTo().getZ() && from.getX() != e.getTo().getX()) {
    8. Chat.get();
    9. Chat.sendMessage(player, "Stop Moving!");
    10. player.teleport(e.getFrom());
    11. }
    12. }
    13. }


    This is what i use for my SurvivalGames Plugin, Give it a go & tell me what you think :)
     
    ThunderWaffeMC likes this.
  10. Offline

    DarkBladee12

    The Fancy Whale if this player gets for example items they will look buggy or if this player logs out during this state he is trapped in the void... And the server can also crash, which happened to me after playing around with that.
     
  11. Offline

    Garris0n

    ThunderWaffeMC and DarkBladee12 like this.
  12. Offline

    Barinade

    It worked back when I found it, all it does is disable the controls as if you were mounted on something else, and since the controls are disabled you can't move, thus your rider (you) can't move.

    I have no idea what it will do these days, I found that out over a year ago, haven't used it in a while, but if it crashes the server then the server needs a little adjustment because there is a way to do it without the memory leak you are implying.
     
  13. Offline

    Garris0n

    If you have two entities and set them as riding each other it will crash the server (it creates an infinite loop somewhere). This is true whenever you create a loop (you could have 10 players and put the bottom one on the top and it would crash). I'm assuming bad things would also happen if you make a player ride themselves.
     
  14. Offline

    Barinade

    Like I said, it worked when I discovered it without crash. I just tested it to see if it still works and you're right, it crashed the server. That cool, I never said it didn't. As I said, numerous times, it worked when I first discovered it, but I have no idea (well, now I do) if it will work now.
     
    Benlewis9000 likes this.
  15. Offline

    Gamecube762

    You can always spawn a mob with slowness and invisibility, I've heard a witherskull can be good for that job with how the new holograms work.
     
  16. Offline

    Bammerbom

    ThunderWaffeMC
    Code:java
    1. Location to = e.getFrom();
    2. to.setPitch(e.getTo().getPitch());
    3. to.setYaw(e.getTo().getYaw());
    4. e.setTo(to);
     
    ThunderWaffeMC likes this.
Thread Status:
Not open for further replies.

Share This Page