Stop player movement but allow them to look around.

Discussion in 'Plugin Development' started by __Ultimatum, Aug 15, 2016.

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

    __Ultimatum

    I'm making a plugin where I need to do what the title says. Anyone know how? I already have:

    @EventHandler
    public void playerMovement(PlayerMoveEvent e) {
    Player p = e.getPlayer();


    if (Turret.turretInstance.playersInTurret.contains(p.getUniqueId())) {
    e.setCancelled(true);
    Location to = e.getFrom();
    to.setPitch(e.getTo().getPitch());
    to.setYaw(e.getTo().getYaw());
    e.setTo(to);


    }

    }
    It works but it doesn't work well.
     
  2. Offline

    MCMastery

    give them slowness 1000

    if you don't want the particle effects showing up, I can't help you with that :p someone else can
     
  3. Offline

    GamerzKing

    • You act like you can't remove particle effects in the PotionEffect parameter.
    • Don't answer questions if you don't know what you're talking about. Why use potion effects, of even PlayerMoveEvent, when you can just set their walk speed to 0?
     
  4. Offline

    MCMastery

    forgot about walk speed lol
     
  5. Offline

    Marti201

    Code:
    if(from.getX() != to.getX() || from.getZ() != to.getZ())
        e.setTo(e.getFrom());
    This will allow the player to look around and jump. If you want to prevent this too, add a check for Y.
     
    Last edited: Aug 16, 2016
  6. Offline

    I Al Istannen

    @Marti201 @MCMastery @__Ultimatum
    Or do what I think @AlvinB proposed:
    Code:
    // no moving for you, but looking round is okay.
    Location newToLocation = e.getFrom().setDirection(e.getTo().getDirection());
    e.setTo(newToLocation);
     
  7. Offline

    mythbusterma

    @GamerzKing

    Setting the player's walk speed to 0 used to crash them, I don't know what version changed this, but do take it with a grain of salt.
     
  8. Offline

    Zombie_Striker

    @MCMastery
    That is overthinking the problem, and adds new problems as well.(the potion effects/ potion effect messages/ screenchanges)
    Both of these will work. You can use either one of these. @__Ultimatum
     
    MCMastery likes this.
  9. Offline

    __Ultimatum

    Both of those cause really jerky movement. Also you can jump and move around when falling.
     
  10. Offline

    Zombie_Striker

    @__Ultimatum
    1. It is only jerky because of lag. Since it is not instantaneous, the player will not be told to 'not move' until a few milliseconds after they already moved. If you do not like this, you will have to use potion effects (since there is no need for the server to tell the player not to move, and as such is instantaneous.)
    2. Are you sure about that? Are you sure the events are being called? If so, which method did you use? If you used @Marti201 's method, then there may be a glitch in your code. The other bit of code is not meant for falling.
     
    I Al Istannen and Marti201 like this.
  11. Offline

    I Al Istannen

    @__Ultimatum @Zombie_Striker
    I used that exact code on my localhost and all was fine, not jerky. So yea, probably lag.

    You should not be able to jump or fall, or move at all.
    If you want to use "my" snippet and be able to fall, allow the y coordinate to change.

    The one I posted is a bit more free, as it should allow looking around, while being set back, but both should work.
     
Thread Status:
Not open for further replies.

Share This Page