Guest User

Example Boundary Wrapper

a guest
May 26th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. /*
  2. Sample boundary teleporter
  3. Written in about 5 minutes by cembry90
  4. May contain imperfections; just a demonstration
  5.  
  6.         compass
  7.         N (-Z)
  8. W (-X)          E (+X)
  9.         S (+Z)
  10. */
  11.  
  12. public class BoundaryListener implements Listener {
  13.     int minX = -1000, maxX = 1000,
  14.         minZ = -1000, maxZ = 1000;
  15.    
  16.     @EventHandler(priority = EventPriority.NORMAL)
  17.     public void onPlayerMove(PlayerMoveEvent e) {
  18.         Player p = e.getPlayer();
  19.         Location loc = p.getLocation();
  20.         World world = p.getWorld();
  21.         int curX = loc.getBlockX(),
  22.             curY = loc.getBlockY(),
  23.             curZ = loc.getBlockZ();
  24.        
  25.         if (curX < minX) {
  26.             p.teleport(new Location(world, maxX, curY, curZ));
  27.         } else if (curX > maxX) {
  28.             p.teleport(new Location(world, minX, curY, curZ));
  29.         } else if (curZ < minZ) {
  30.             p.teleport(new Location(world, curX, curY, maxZ));
  31.         } else if (curZ > maxZ) {
  32.             p.teleport(new Location(world, curX, curY, minZ));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment