Disallowing players to move spazzing out

Discussion in 'Plugin Development' started by Starfire1337, Aug 6, 2014.

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

    Starfire1337

    Hello, I need to not permit players to move, but still rotate their screens, chat etc. Currently, I have
    Code:
    @EventHandler(priority=EventPriority.HIGHEST)
        public void onPlayerMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if(ArenaManager.getManager().isInGame(p)) { //check if a player is in a game
                HashMap<String, Integer> players = ArenaManager.getPlayers(); //get's the HashMap players from the ArenaManager class
                HashMap<Integer, String> state = ArenaManager.getState(); //get's the HashMap state from ArenaManager class
                if(players.containsKey(p.getName())) {
                    int arenaId = players.get(p.getName()); //get's the arenaID the player is in
                    if(state.containsKey(arenaId)) {
                        String arenaState = state.get(arenaId); //get's the state of the arena
                        if(arenaState.equalsIgnoreCase("idle")) {
                            if(!p.hasPermission("pvprun.bypass")) {
                                e.setCancelled(true); //Does not allow players to move if the arena is in idle state
                            }
                        }
                    }
                }
            }
        }
    There are 2 problems with this, first of all, when I try to move at all, my screen starts spazzing out, my view angle changing rapidly back and fourth, and second of all, I am not able to rotate.

    Thanks
     
  2. Offline

    Garris0n

    Only cancel the event if the x, y, or z changes between the two locations.
     
  3. Offline

    Starfire1337

    Garris0n
    Any ideas why it's spazzing out though?
     
  4. Starfire1337 Saddly if your blocking rotation or movement it is going to spazz out because of limitations of the client.
     
  5. Offline

    Starfire1337

    BorisTheTerrible
    How do you make it so it doesn't? I've seen plugins where you cannot move without the spazz.

    Edit: added
    Code:
    if(e.getFrom().getBlockX() == e.getTo().getBlockX() && e.getFrom().getBlockY() == e.getTo().getBlockY() && e.getFrom().getBlockZ() == e.getTo().getBlockZ()) {
        return;
    }
    at the beginning.
     
  6. Offline

    xAstraah

    Starfire1337, Hey fwend,

    Put them in a ArrayList or something so when you want the freeze to be toggled and then if they are in the ArrayList if they're x or z changes do p.teleport(p.getLocation());

    Hope this helps,
    xAstraah.
     
  7. Starfire1337
    Hmm well my belief that you cannot block movement or rotation without spazzing is outdated.
    player.setWalkSpeed(0.001F);
    That works fine. However don't set it to zero because it will crash the client.
    Edit:Well this works for movement anways, which I don't think you wanted to block rotation.
     
  8. Offline

    Garris0n

    Use getX/Y/Z unless you want them to be able to move around inside the block.

    Also, does that not work? It should work fine unless you walk and move your mouse at the same time.

    If you're curious, it does that because there are 3 move packets (I'm doing this on memory, so don't kill me):
    -Move (walking around)
    -Look (mouse movement)
    -Combined move and look (if you move your mouse and walk at the same time, it sends one combined packet)

    So, if the client sends the third one, it will screw up simply canceling the event. What you could do is teleport the player to a location with their current position but the new yaw/pitch.
     
  9. Offline

    fireblast709

    Starfire1337 give them a slowness 7 effect and a jump 128, disallowing movement (including jumping). This should stop them from moving client side. Add the x, y, z check where you simply set the x, y and z in the to Location to the coords where they are kept (while keeping the pitch and yaw! Also do not cancel the event!) to block movement server side as well (if they go all hacking galore, you never know)
     
  10. Offline

    Forseth11

    I think this is because when you move your screen just that little bit it goes to the server and it cancels it. It then puts the player back in their original position. By putting them there it probably calls the event again which would make the screen shake.
    What I always did with this was put:
    Code:java
    1. @EventHandler
    2. public void move(PlayerMoveEvent event){
    3. if(!event.getTo().getBlock().equals(event.getFrom().getBlock())){
    4. event.setCancelled(true);
    5. }
    6. }
     
  11. Offline

    qlimax5000

    player.teleport(event.getFrom());

    NEVER cancel a move event.

    Forseth11
    I think that's wrong too, event.getFrom() return a Location which contains pitch and yaw, so event.getTo() would not be event.getFrom() if they just looked around.

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

    Starfire1337

    qlimax5000
    Thanks, but why not? Why would Bukkit have it able to be cancelled if your not supposed to cancel it?
     
  13. Offline

    Flamedek

    qlimax5000 He is comparing the blocks though, not the locations. And the blocks don't contain pitch/yaw information so it should work ok.
     
  14. Offline

    qlimax5000

    Starfire1337
    Because it's easy i guess. Not sure.
    As for the why not, the move event is fired really rapidly so say you cancel it multiple times it's gonna freak out the client causing it to flip back and forth.


    Longer better explaination of what happends:

    The player is frozen and moves quickly and gets cancelled a few times, then switch direction of running the client will freak out and the screen will look like you're teleporting between first direction point and second direction point.

    Flamedek
    Oh, yeah. I see. Still would not work tho, because walking from grass to grass wouldn't trigger the code.

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

    Forseth11

    What I did is checking if you moved to another block. It did nothing with pitch or yaw only the block at the from and to location.
     
Thread Status:
Not open for further replies.

Share This Page