prevent a player from moving (x,y,z, but allow turning head)

Discussion in 'Spigot Plugin Development' started by NoobDoesMC, Jul 19, 2018.

  1. I want to loop teleporting a player, to "stun" them

    Slowness won't work because I don't want to change their fov

    but I don't want the jittery direction-setting

    the player should be able to look around freely, just not move

    how can I do that?
     
  2. Not recommended, but you could always set their walking speed to 0 :p
     
  3. why not recommended?
     
  4. Because I personally have never done it. You can give it a go though :p

    I just know it'll give the no moving effect, with no FOV change.
     
  5. How do I set the walk speed to 0?
     
  6. What's the normal walk speed so I can reset it afterwards?
     
  7. You have your location. Apply Yaw and Pitch of player to your location. After that teleport it to the location.


    Edit: Cancel player velocity event.
    Or cancel move event when position x y z != old positions x y z.
     
    #7 ysl3000, Jul 19, 2018
    Last edited: Jul 19, 2018
  8. That’s not what he was asking at all.
    Edit: And now you’ve edited it, but you still haven’t read his post to see what he is asking
    Second edit: wow I’m retarded, love you ysl

    OP,
    I this might help:
     
    #8 FloThePony, Jul 19, 2018
    Last edited: Jul 19, 2018
  9. But spectator mode doesn't block movement?

    And I want people to still see their hotbar and health, and be damageable
     
  10. Wow, after telling the guy that I quoted he didn’t read the post it was me who can’t read.
    I thought it said it did want to block looking around and you didn’t want the jittering effect that used.

    Sorry!

    Edit: actually answer time: @Xgoldenman16X is right.

    Code (Text):
    Player#setWalkSpeed(0F);
    does exactly what you are looking for (at least until I realise I didn’t read your post correctly again and you are asking something different
     
    #10 FloThePony, Jul 19, 2018
    Last edited: Jul 19, 2018
  11. I might be misunderstanding what you're asking for, but from what I understand you're just trying to slow a player down without changing their fov? Why don't you just do

    Code (Text):
    Player.setWalkingSpeed(float value here);
    Default walking speed is 0.2
     
  12. Teleport the payer back in the MoveEvent, that should to the trick.
     
  13. No, actually that moves their yaw and pitch back as well.
     
  14. Where are you getting these errors? Your console or your IDE?
    If IDE, what IDE do you use?
     
  15. I use Player.setWalkSpeed(0F), combined with Player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, -5, false, false), true);

    However, if the player holds w and spams space they can inch forwards every "jump"
     
    • Informative Informative x 1
  16. You could always accept the jittering and check if getTo().getY() is higher than getFrom().getY() and if it is, set player's Y to getFrom().getY()
    Or, if you give them the jump potion at level 150, they can't jump.
     
  17. maol3

    Supporter

    Code (Text):
    boolean movingAllowed = false;

    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e) {
        if(!movingAllowed) {
            if(e.getTo().getBlockX() > e.getFrom().getBlockX() || e.getTo().getBlockX() < e.getFrom().getBlockX() || e.getTo().getBlockZ() > e.getFrom().getBlockZ() || e.getTo().getBlockZ() < e.getFrom().getBlockZ()) {
                e.getPlayer().teleport(e.getFrom());
            }
        }
    }
    Untested code, but should work.
     
  18. No, it won't. It will work on one player, but by setting only one variable, it will not work if there are more than 1 player online, which is just dumb. Try using a HashMap to store the truth and false values. :)
     
  19. maol3

    Supporter

    I don't know what he's trying to do here, but that should definitely work to prevent a player from moving around (which is what he asked for). Then it's up to him to add his own logic to it, as when it will apply and who it will apply to.
     
  20. No, he specifically stated he wants the player to not be able to move or jump, but be able to look around freely.
    He also does not want the jittery effect that teleporting on the PlayerMoveEvent causes.
     
    • Winner Winner x 2