Skip to content

Commit

Permalink
If players glitch deep into a locked island they are teleported out.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 5, 2017
1 parent 0bdc659 commit 17663a5
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/com/wasteofplastic/askyblock/listeners/IslandGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,30 @@ public void onVehicleMove(final VehicleMoveEvent e) {
&& !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")
&& !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);

// Check if the player is within the border a lot
int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(),
e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(),
e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
int minMin = Math.max(minX, minZ);
//plugin.getLogger().info("DEBUG: " + minMin);
if (minMin < -1) {
// Teleport player
plugin.getGrid().homeTeleport(player);

} else if (minMin < 1) {
Vector v = e.getVehicle().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2,0,1.2));
if (DEBUG)
plugin.getLogger().info("DEBUG: direction vector = " + v);
e.getVehicle().setVelocity(v);
}
// Get the vector away from this island
/*
Vector v = e.getVehicle().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2,0,1.2));
if (DEBUG)
plugin.getLogger().info("DEBUG: direction vector = " + v);
e.getVehicle().setVelocity(v);
*/
return;
}
}
Expand Down Expand Up @@ -428,10 +446,22 @@ public void onPlayerMove(final PlayerMoveEvent e) {
}

} else {
Vector v = e.getPlayer().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2,0,1.2));
if (DEBUG)
plugin.getLogger().info("DEBUG: direction vector = " + v);
e.getPlayer().setVelocity(v);
// Check if the player is within the border a lot
int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(),
e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(),
e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
int minMin = Math.max(minX, minZ);
//plugin.getLogger().info("DEBUG: " + minMin);
if (minMin < -1) {
// Teleport player
plugin.getGrid().homeTeleport(e.getPlayer());
} else if (minMin < 1) {
Vector v = e.getPlayer().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2,0,1.2));
if (DEBUG)
plugin.getLogger().info("DEBUG: direction vector = " + v);
e.getPlayer().setVelocity(v);
}
}
return;
}
Expand Down

0 comments on commit 17663a5

Please sign in to comment.