use of com.sk89q.worldedit.entity.Player in project WorldGuard by EngineHub.
the class LocationFlag method parseInput.
@Override
public Location parseInput(FlagContext context) throws InvalidFlagFormat {
String input = context.getUserInput();
Player player = context.getPlayerSender();
Location loc = null;
if ("here".equalsIgnoreCase(input)) {
Location playerLoc = player.getLocation();
loc = new LazyLocation(((World) playerLoc.getExtent()).getName(), playerLoc.toVector(), playerLoc.getYaw(), playerLoc.getPitch());
} else {
String[] split = input.split(",");
if (split.length >= 3) {
try {
final World world = player.getWorld();
final double x = Double.parseDouble(split[0]);
final double y = Double.parseDouble(split[1]);
final double z = Double.parseDouble(split[2]);
final float yaw = split.length < 4 ? 0 : Float.parseFloat(split[3]);
final float pitch = split.length < 5 ? 0 : Float.parseFloat(split[4]);
loc = new LazyLocation(world.getName(), Vector3.at(x, y, z), yaw, pitch);
} catch (NumberFormatException ignored) {
}
}
}
if (loc != null) {
Object obj = context.get("region");
if (obj instanceof ProtectedRegion) {
ProtectedRegion rg = (ProtectedRegion) obj;
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld()).boundedLocationFlags) {
if (!rg.contains(loc.toVector().toBlockPoint())) {
if (new RegionPermissionModel(player).mayOverrideLocationFlagBounds(rg)) {
player.printDebug("WARNING: Flag location is outside of region.");
} else {
// no permission
throw new InvalidFlagFormat("You can't set that flag outside of the region boundaries.");
}
}
// clamp height to world limits
loc.setPosition(loc.toVector().clampY(0, player.getWorld().getMaxY()));
return loc;
}
}
return loc;
}
throw new InvalidFlagFormat("Expected 'here' or x,y,z.");
}
Aggregations