use of com.sk89q.worldedit.util.Location 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.");
}
use of com.sk89q.worldedit.util.Location in project WorldGuard by EngineHub.
the class Session method tick.
/**
* Tick the session.
*
* @param player The player
*/
public void tick(LocalPlayer player) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location location = player.getLocation();
ApplicableRegionSet set = query.getApplicableRegions(location);
for (Handler handler : handlers.values()) {
handler.tick(player, set);
}
}
use of com.sk89q.worldedit.util.Location in project WorldGuard by EngineHub.
the class RegionCommands method teleport.
/**
* Teleport to a region
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "teleport", "tp" }, usage = "[-w world] [-c|s] <id>", flags = "csw:", desc = "Teleports you to the location associated with the region.", min = 1, max = 1)
public void teleport(CommandContext args, Actor sender) throws CommandException {
LocalPlayer player = worldGuard.checkPlayer(sender);
Location teleportLocation;
// Lookup the existing region
World world = checkWorld(args, player, 'w');
RegionManager regionManager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(regionManager, args.getString(0), true);
// Check permissions
if (!getPermissionModel(player).mayTeleportTo(existing)) {
throw new CommandPermissionsException();
}
// -s for spawn location
if (args.hasFlag('s')) {
teleportLocation = FlagValueCalculator.getEffectiveFlagOf(existing, Flags.SPAWN_LOC, player);
if (teleportLocation == null) {
throw new CommandException("The region has no spawn point associated.");
}
} else if (args.hasFlag('c')) {
// Check permissions
if (!getPermissionModel(player).mayTeleportToCenter(existing)) {
throw new CommandPermissionsException();
}
Region region = WorldEditRegionConverter.convertToRegion(existing);
if (region == null || region.getCenter() == null) {
throw new CommandException("The region has no center point.");
}
if (player.getGameMode() == GameModes.SPECTATOR) {
teleportLocation = new Location(world, region.getCenter(), 0, 0);
} else {
// It doesn't return the found location and it can't be checked if the location is inside the region.
throw new CommandException("Center teleport is only availible in Spectator gamemode.");
}
} else {
teleportLocation = FlagValueCalculator.getEffectiveFlagOf(existing, Flags.TELE_LOC, player);
if (teleportLocation == null) {
throw new CommandException("The region has no teleport point associated.");
}
}
String message = FlagValueCalculator.getEffectiveFlagOf(existing, Flags.TELE_MESSAGE, player);
// If message.isEmpty(), no message is sent by LocalPlayer#teleport(...)
if (message == null) {
message = Flags.TELE_MESSAGE.getDefault();
}
player.teleport(teleportLocation, message.replace("%id%", existing.getId()), "Unable to teleport to region '" + existing.getId() + "'.");
}
use of com.sk89q.worldedit.util.Location in project WorldGuard by EngineHub.
the class RegionPrintoutBuilder method appendBounds.
/**
* Add information about coordinates.
*/
public void appendBounds() {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
builder.append(TextComponent.of("Bounds:", TextColor.BLUE));
TextComponent bound = TextComponent.of(" " + min + " -> " + max, TextColor.YELLOW);
if (perms != null && perms.maySelect(region)) {
bound = bound.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg select " + region.getId()));
}
builder.append(bound);
final Location teleFlag = FlagValueCalculator.getEffectiveFlagOf(region, Flags.TELE_LOC, perms != null && perms.getSender() instanceof RegionAssociable ? (RegionAssociable) perms.getSender() : null);
if (teleFlag != null && perms != null && perms.mayTeleportTo(region)) {
builder.append(TextComponent.space().append(TextComponent.of("[Teleport]", TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to teleport").append(TextComponent.newline()).append(TextComponent.of(teleFlag.getBlockX() + ", " + teleFlag.getBlockY() + ", " + teleFlag.getBlockZ())))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg tp -w \"" + world + "\" " + region.getId()))));
} else if (perms != null && perms.mayTeleportToCenter(region) && region.isPhysicalArea()) {
builder.append(TextComponent.space().append(TextComponent.of("[Center Teleport]", TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to teleport to the center of the region"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg tp -c -w \"" + world + "\" " + region.getId()))));
}
newline();
}
use of com.sk89q.worldedit.util.Location in project WorldGuard by EngineHub.
the class SignChestProtection method isAdjacentChestProtected.
public boolean isAdjacentChestProtected(Location searchBlock, LocalPlayer player) {
Location side;
boolean res;
side = searchBlock;
res = isProtected(side, player);
if (res)
return res;
side = searchBlock.setX(searchBlock.getX() - 1);
res = isProtected(side, player);
if (res)
return res;
side = searchBlock.setX(searchBlock.getX() + 1);
res = isProtected(side, player);
if (res)
return res;
side = searchBlock.setZ(searchBlock.getZ() - 1);
res = isProtected(side, player);
if (res)
return res;
side = searchBlock.setZ(searchBlock.getZ() + 1);
res = isProtected(side, player);
if (res)
return res;
return false;
}
Aggregations