Search in sources :

Example 26 with Player

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.");
}
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)

Aggregations

Player (com.sk89q.worldedit.entity.Player)26 LocalSession (com.sk89q.worldedit.LocalSession)13 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 World (com.sk89q.worldedit.world.World)9 Command (org.enginehub.piston.annotation.Command)9 Logging (com.sk89q.worldedit.command.util.Logging)7 Location (com.sk89q.worldedit.util.Location)6 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)4 Actor (com.sk89q.worldedit.extension.platform.Actor)4 Region (com.sk89q.worldedit.regions.Region)4 Caption (com.fastasyncworldedit.core.configuration.Caption)3 EditSession (com.sk89q.worldedit.EditSession)3 BlockBag (com.sk89q.worldedit.extent.inventory.BlockBag)3 FaweAPI (com.fastasyncworldedit.core.FaweAPI)2 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)2 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 Arguments (com.sk89q.worldedit.command.argument.Arguments)2 BlockTool (com.sk89q.worldedit.command.tool.BlockTool)2