Check teleportation on command location prefix

This commit is contained in:
Jesse Boyd
2016-06-21 03:02:41 +10:00
parent 2ff4e07919
commit e08db3d12b
3 changed files with 59 additions and 7 deletions

View File

@ -206,13 +206,18 @@ public class MainCommand extends Command {
PlotArea area = player.getApplicablePlotArea();
Plot newPlot = Plot.fromString(area, args[0]);
if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea().equals(area) || Permissions.hasPermission(player, C.PERMISSION_ADMIN)) && !newPlot.isDenied(player.getUUID())) {
// Save meta
loc = player.getMeta("location");
plot = player.getMeta("lastplot");
tp = true;
// Set loc
player.setMeta("location", newPlot.getBottomAbs());
player.setMeta("lastplot", newPlot);
Location newLoc = newPlot.getCenter();
if (player.canTeleport(newLoc)) {
// Save meta
loc = player.getMeta("location");
plot = player.getMeta("lastplot");
tp = true;
// Set loc
player.setMeta("location", newLoc);
player.setMeta("lastplot", newPlot);
} else {
C.BORDER.send(player);
}
// Trim command
args = Arrays.copyOfRange(args, 1, args.length);
}

View File

@ -250,6 +250,17 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/
public abstract UUID getUUID();
public boolean canTeleport(Location loc) {
Location current = getLocationFull();
teleport(loc);
boolean result = true;
if (!getLocation().equals(loc)) {
result = false;
}
teleport(current);
return result;
}
/**
* Teleport the player to a location.
* @param location the target location