Search in sources :

Example 1 with Selection

use of com.sk89q.worldedit.bukkit.selections.Selection in project Prism-Bukkit by prism.

the class WorldEditBridge method getSelectedArea.

/**
     * 
     * @param plugin
     * @param player
     * @param parameters
     * @return
     */
public static boolean getSelectedArea(Prism plugin, Player player, QueryParameters parameters) {
    // Get selected area
    Region region;
    try {
        final LocalPlayer lp = new BukkitPlayer(Prism.plugin_worldEdit, Prism.plugin_worldEdit.getWorldEdit().getServer(), player);
        final World lw = lp.getWorld();
        region = Prism.plugin_worldEdit.getWorldEdit().getSession(lp).getSelection(lw);
    } catch (final IncompleteRegionException e) {
        return false;
    }
    // Set WorldEdit locations
    final Vector minLoc = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
    final Vector maxLoc = new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
    // Check selection against max radius
    final Selection sel = Prism.plugin_worldEdit.getSelection(player);
    final double lRadius = Math.ceil(sel.getLength() / 2);
    final double wRadius = Math.ceil(sel.getWidth() / 2);
    final double hRadius = Math.ceil(sel.getHeight() / 2);
    String procType = "applier";
    if (parameters.getProcessType().equals(PrismProcessType.LOOKUP)) {
        procType = "lookup";
    }
    final int maxRadius = plugin.getConfig().getInt("prism.queries.max-" + procType + "-radius");
    if (maxRadius != 0 && (lRadius > maxRadius || wRadius > maxRadius || hRadius > maxRadius) && !player.hasPermission("prism.override-max-" + procType + "-radius")) {
        return false;
    } else {
        parameters.setWorld(region.getWorld().getName());
        parameters.setMinLocation(minLoc);
        parameters.setMaxLocation(maxLoc);
    }
    return true;
}
Also used : LocalPlayer(com.sk89q.worldedit.LocalPlayer) Selection(com.sk89q.worldedit.bukkit.selections.Selection) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) World(com.sk89q.worldedit.world.World) Vector(org.bukkit.util.Vector) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer)

Aggregations

IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalPlayer (com.sk89q.worldedit.LocalPlayer)1 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 Region (com.sk89q.worldedit.regions.Region)1 World (com.sk89q.worldedit.world.World)1 Vector (org.bukkit.util.Vector)1