Teleportation when a certain location

Discussion in 'Plugin Development' started by StedyOne, Dec 26, 2013.

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

    StedyOne

    Im trying to make a plugin, so when you are in a certain location, lets say Y < 5 you teleport to a location you previously marked.Sombody could give me a little help please??
    :)
     
  2. Offline

    WhatAaCow

    StedyOne Use PlayerMoveEvent and check the given location ;)
     
  3. Offline

    StedyOne

    WhatAaCow So far i have set the place to teleport once i am Y < 5 with this code:
    Code:
    if(commandLabel.equalsIgnoreCase("setfall")){
              getConfig().set("set.fall", player.getLocation().getWorld());
              getConfig().set("spawn.X", player.getLocation().getX());
              getConfig().set("spawn.Y", player.getLocation().getY());
              getConfig().set("spawn.Z", player.getLocation().getZ());
              saveConfig();
              player.sendMessage(ChatColor.GREEN+ "Fall set!");
         
          }
     
          return false;
    So, now how do i check if the event is on the given location?
    Code:
     @EventHandler
      public void onPlayerTeleportation(PlayerMoveEvent tp){
     
     
      }
     
  4. Offline

    repsor

    StedyOne try checking if the Y of tp.getTo() is <5, and if it is, use tp.getPlayer().teleport(<location you want the player to teleport to>); that should work :)
     
  5. Offline

    aredherring

    PlayerMoveEvent seems very intensive, it would be checked every time any player in the world moved.
    Would it not be better to place a block and have the player teleported when they stepped on that block?
     
  6. Offline

    jthort

    You could just create an array list of locations in a square area using two for loops, then get the players location and checking if they are in there.

    That way you don't use events every time you move
     
  7. Offline

    aredherring

    This would still be utilizing the events every time a player moves because you would need to check if they were within (X1, Y1) - (X2,Y2) every time they moved.
     
  8. Offline

    jthort

    aredherring True, either way it would work

    Edit: I just find it better not to use events unless you have to, just my way of coding :)
     
  9. Offline

    aredherring

    Not a question of it working or not, but scaling issues. With a lot of players (or movement), using PlayerMoveEvent would quickly become an issue.
    Just my 2p
     
  10. Offline

    jthort

    aredherring Now I'm curious, it would be better using the PlayerMoveEvent in small servers?
     
  11. Offline

    aredherring

    We are digressing here, but....
    PlayerMoveEvent triggers every time a player moves. This would happen a lot, as you can imagine.
    Adding any logic to this event would incur overhead which would be run every single time a player moved.

    However it seems that there is no event for when a player "steps on" a block -.-"
    EDIT: I looked around a little. Seems that this is what people came up with almost 2 years ago
     
  12. Offline

    jthort

    If you are referring to the fact that I said "I would rather not use events", I meant in the actual code where instead of creating a whole new method, you can simple create a quick loop and player.getLocation().
     
  13. Offline

    WhatAaCow

    jthort aredherring It's very slow if you use arrays and loop/timer to check the arrays (and if nobody moves, no event is fired but a timer is always running). A playermoveonblock event, would use the playermoveevent = equal, but with an "if".
     
    jthort likes this.
Thread Status:
Not open for further replies.

Share This Page