Add setting to prevent cross-world teleportation with '/as tp'

Related to #234
This commit is contained in:
Thijs Wiefferink 2016-12-26 23:20:12 +01:00
parent 16c7a044ea
commit bb1f592807
4 changed files with 29 additions and 9 deletions

View File

@ -72,6 +72,8 @@ public class FindCommand extends CommandAreaShop {
return;
}
}
// Find buy regions
if(args[1].equalsIgnoreCase("buy")) {
List<BuyRegion> regions = plugin.getFileManager().getBuys();
List<BuyRegion> results = new ArrayList<>();
@ -106,7 +108,10 @@ public class FindCommand extends CommandAreaShop {
plugin.message(player, "find-noneFound", "buy", Utils.formatCurrency(balance), onlyInGroup);
}
}
} else {
}
// Find rental regions
else {
List<RentRegion> regions = plugin.getFileManager().getRents();
List<RentRegion> results = new ArrayList<>();
for(RentRegion region : regions) {

View File

@ -66,11 +66,8 @@ public class TeleportFeature extends RegionFeature {
* @return true if the teleport succeeded, otherwise false
*/
public boolean teleportPlayer(Player player, boolean toSign, boolean checkPermissions) {
int checked = 1;
boolean owner;
boolean friend = region.getFriendsFeature().getFriends().contains(player.getUniqueId());
boolean available = region.isAvailable();
ProtectedRegion wRegion = region.getRegion();
// Check basics
if(region.getWorld() == null) {
region.message(player, "general-noWorld");
return false;
@ -79,9 +76,18 @@ public class TeleportFeature extends RegionFeature {
region.message(player, "general-noRegion");
return false;
}
owner = player.getUniqueId().equals(region.getOwner());
// Check correct world
if(!region.getBooleanSetting("general.teleportCrossWorld") && !player.getWorld().equals(region.getWorld())) {
region.message(player, "teleport-wrongWorld", player.getWorld().getName());
return false;
}
ProtectedRegion wRegion = region.getRegion();
if(checkPermissions) {
boolean owner = player.getUniqueId().equals(region.getOwner());
boolean friend = region.getFriendsFeature().getFriends().contains(player.getUniqueId());
boolean available = region.isAvailable();
// Teleport to sign instead if they dont have permission for teleporting to region
if((!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
@ -129,20 +135,26 @@ public class TeleportFeature extends RegionFeature {
} else {
insideRegion = region.getBooleanSetting("general.teleportIntoRegion");
}
int maxTries = plugin.getConfig().getInt("maximumTries");
// Check locations starting from startLocation and then a cube that increases
// radius around that (until no block in the region is found at all cube sides)
Location safeLocation = startLocation;
int radius = 1;
boolean blocksInRegion = wRegion.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
if(!blocksInRegion && insideRegion) {
region.message(player, "teleport-blocked");
return false;
}
// Tries limit tracking
int radius = 1;
int checked = 1;
int maxTries = plugin.getConfig().getInt("maximumTries");
// Tracking of which sides to continue the search
boolean done = isSafe(safeLocation) && ((blocksInRegion && insideRegion) || (!insideRegion));
boolean northDone = false, eastDone = false, southDone = false, westDone = false, topDone = false, bottomDone = false;
boolean continueThisDirection;
while(((blocksInRegion && insideRegion) || (!insideRegion)) && !done) {
blocksInRegion = false;

View File

@ -15,6 +15,8 @@ general:
teleportIntoRegion: true
# Same as above, but then for when you teleport to the sign of a region instead of the region itself.
teleportToSignIntoRegion: false
# Allow teleporting to the region from another world with `/as tp`
teleportCrossWorld: true
# Set where the '/as find' command should teleport the player to, set to true for the first sign of the region and set to
# false to teleport to the location set by '/as settp' or the default location (if not set).
findTeleportToSign: true

View File

@ -352,6 +352,7 @@ teleport-noSafe: "No safe position found in %lang:region%, no spots in the regio
teleport-blocked: "You can't teleport because the position is outside the region, and you are forced to teleport inside."
teleport-changedToSign: "You only have permission to teleport to the sign and not inside the region, teleporting to sign."
teleport-changedToNoSign: "No sign available to teleport to, trying to teleport inside the region instead."
teleport-wrongWorld: "You need to be in world '%world%' to teleport to %lang:region%, but you are in world '%0%'."
setteleport-help: "/as settp [region] [reset], the region you stand in will be used if not specified."
setteleport-noPermission: "You don't have permission to set the teleport location."