"Stick" player to location

Discussion in 'Plugin Development' started by HamOmlet, Nov 9, 2012.

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

    HamOmlet

    Any suggestion on how to go about "sticking" a player to a particular location? I could of course keep teleporting a player to a location, but I feel as though there is a cleaner solution.
     
  2. Offline

    gjossep

    Add the player to a list, then in OnPlayerMoveEvent check if the player is in the list, if it is the cancel the event.
     
  3. Offline

    HamOmlet

    If the player "sticks" to, let's say, a block in the air, wouldn't cancelling the event be similar to just teleporting them back to the location (in terms of the player constantly falling)?
     
  4. Offline

    boardinggamer

    you can do a check. if they are in the air set the block under them to dirt or something
     
  5. Offline

    Double0negative

    cancelling the playerMoveEvent creates some very weird effects, such as being stuck in a constant tp back and forth. Your going to need to store the players location and check if they have moved from that location, if so, tp them back to that location

    Code:
    HashMap<Player, Location>locations = new HashMap<Player, Location>();
     
    public void move(PlayerMoveEvent e){
       Location l = e.getPLayer().getLocation();
        Location l2 = locations.get(e.getPLayer());
         if(l.getX()!=l2.getX() || l.getZ() != l2.getX()){
                e.getPLayer().teleport(l2);
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page