Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- public void onMove(PlayerMoveEvent evt) {
- if (!evt.getTo().getWorld().getName().equalsIgnoreCase("factionborders")) {
- return;
- }
- FactionBorder factionBorder = FactionBorderManager.getFactionBorderFromLocation(evt.getTo());
- if (factionBorder == null) {
- evt.getPlayer().sendMessage(Color.t("&cYou can not walk outside the border."));
- Vector direction = evt.getPlayer().getLocation().getDirection();
- evt.getPlayer().setVelocity(direction.setY(-0.5).multiply(-2));
- return;
- }
- }
- public static FactionBorder getFactionBorderFromLocation(Location location) {
- for (FactionBorder n : factionBorderList) {
- if (inArea(location, n.getCorner1(), n.getCorner3())) {
- return n;
- }
- }
- return null;
- }
- public static boolean inArea(Location targetLocation, Location inAreaLocation1, Location inAreaLocation2) {
- if (inAreaLocation1.getWorld().getName().equalsIgnoreCase(inAreaLocation2.getWorld().getName())) {
- if (targetLocation.getWorld().getName().equalsIgnoreCase(inAreaLocation1.getWorld().getName())) {
- if ((targetLocation.getBlockX() >= inAreaLocation1.getBlockX() && targetLocation.getBlockX() <= inAreaLocation2.getBlockX()) || (targetLocation.getBlockX() <= inAreaLocation1.getBlockX() && targetLocation.getBlockX() >= inAreaLocation2.getBlockX())) {
- return (targetLocation.getBlockZ() >= inAreaLocation1.getBlockZ() && targetLocation.getBlockZ() <= inAreaLocation2.getBlockZ()) || (targetLocation.getBlockZ() <= inAreaLocation1.getBlockZ() && targetLocation.getBlockZ() >= inAreaLocation2.getBlockZ());
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement