Advertisement
LilFrostay

Untitled

May 12th, 2020
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. @EventHandler
  2. public void onMove(PlayerMoveEvent evt) {
  3. if (!evt.getTo().getWorld().getName().equalsIgnoreCase("factionborders")) {
  4. return;
  5. }
  6. FactionBorder factionBorder = FactionBorderManager.getFactionBorderFromLocation(evt.getTo());
  7. if (factionBorder == null) {
  8. evt.getPlayer().sendMessage(Color.t("&cYou can not walk outside the border."));
  9. Vector direction = evt.getPlayer().getLocation().getDirection();
  10. evt.getPlayer().setVelocity(direction.setY(-0.5).multiply(-2));
  11. return;
  12. }
  13. }
  14.  
  15. public static FactionBorder getFactionBorderFromLocation(Location location) {
  16. for (FactionBorder n : factionBorderList) {
  17. if (inArea(location, n.getCorner1(), n.getCorner3())) {
  18. return n;
  19. }
  20. }
  21. return null;
  22. }
  23.  
  24. public static boolean inArea(Location targetLocation, Location inAreaLocation1, Location inAreaLocation2) {
  25. if (inAreaLocation1.getWorld().getName().equalsIgnoreCase(inAreaLocation2.getWorld().getName())) {
  26. if (targetLocation.getWorld().getName().equalsIgnoreCase(inAreaLocation1.getWorld().getName())) {
  27. if ((targetLocation.getBlockX() >= inAreaLocation1.getBlockX() && targetLocation.getBlockX() <= inAreaLocation2.getBlockX()) || (targetLocation.getBlockX() <= inAreaLocation1.getBlockX() && targetLocation.getBlockX() >= inAreaLocation2.getBlockX())) {
  28. return (targetLocation.getBlockZ() >= inAreaLocation1.getBlockZ() && targetLocation.getBlockZ() <= inAreaLocation2.getBlockZ()) || (targetLocation.getBlockZ() <= inAreaLocation1.getBlockZ() && targetLocation.getBlockZ() >= inAreaLocation2.getBlockZ());
  29. }
  30. }
  31. }
  32. return false;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement