Search in sources :

Example 61 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 62 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 63 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 64 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)

Example 65 with Location

use of com.sk89q.worldedit.util.Location in project WorldGuard by EngineHub.

the class GeneralCommands method locate.

@Command(aliases = { "locate" }, usage = "[player]", desc = "Locate a player", max = 1)
@CommandPermissions({ "worldguard.locate" })
public void locate(CommandContext args, Actor sender) throws CommandException {
    LocalPlayer player = worldGuard.checkPlayer(sender);
    if (args.argsLength() == 0) {
        player.setCompassTarget(new Location(player.getWorld(), player.getWorld().getSpawnPosition().toVector3()));
        sender.print("Compass reset to spawn.");
    } else {
        LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
        player.setCompassTarget(target.getLocation());
        sender.print("Compass repointed.");
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Location(com.sk89q.worldedit.util.Location) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Location (com.sk89q.worldedit.util.Location)65 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 World (com.sk89q.worldedit.world.World)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 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 StringTag (com.sk89q.jnbt.StringTag)6 Player (com.sk89q.worldedit.entity.Player)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6 BlockState (com.sk89q.worldedit.world.block.BlockState)6 IntTag (com.sk89q.jnbt.IntTag)5