Search in sources :

Example 66 with Location

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.");
}
Also used : Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionPermissionModel(com.sk89q.worldguard.internal.permission.RegionPermissionModel) Location(com.sk89q.worldedit.util.Location)

Example 67 with Location

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);
    }
}
Also used : RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) Handler(com.sk89q.worldguard.session.handler.Handler) Location(com.sk89q.worldedit.util.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 68 with Location

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() + "'.");
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) Region(com.sk89q.worldedit.regions.Region) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Location(com.sk89q.worldedit.util.Location) Command(com.sk89q.minecraft.util.commands.Command)

Example 69 with Location

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();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location)

Example 70 with Location

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;
}
Also used : Location(com.sk89q.worldedit.util.Location)

Aggregations

Location (com.sk89q.worldedit.util.Location)75 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 World (com.sk89q.worldedit.world.World)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 Region (com.sk89q.worldedit.regions.Region)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 Command (org.enginehub.piston.annotation.Command)9 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 Tag (com.sk89q.jnbt.Tag)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)8 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)8 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Player (com.sk89q.worldedit.entity.Player)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)7 StringTag (com.sk89q.jnbt.StringTag)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6