Search in sources :

Example 1 with World

use of com.sk89q.worldedit.world.World 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)

Example 2 with World

use of com.sk89q.worldedit.world.World in project Prism-Bukkit by prism.

the class WorldEditBridge method getSelectedArea.

/**
 * Worldedit bridge.
 *
 * @param plugin     Prism
 * @param player     Player
 * @param parameters {@link QueryParameters}
 * @return boolean.
 */
public static boolean getSelectedArea(Plugin plugin, Player player, QueryParameters parameters) {
    // Get selected area
    Region region = null;
    try {
        final BukkitPlayer lp = BukkitAdapter.adapt(player);
        final World lw = lp.getWorld();
        LocalSession session = WorldEdit.getInstance().getSessionManager().getIfPresent(lp);
        if (session != null) {
            region = session.getSelection(lw);
        }
        if (region == null) {
            return false;
        }
        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());
        final Region sel = session.getRegionSelector(lw).getRegion();
        final double lRadius = ((float) sel.getLength() + 1) / 2;
        final double wRadius = ((float) sel.getWidth() + 1) / 2;
        final double hRadius = ((float) sel.getHeight() + 1) / 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);
        }
    } catch (final IncompleteRegionException e) {
        return false;
    }
    return true;
}
Also used : LocalSession(com.sk89q.worldedit.LocalSession) 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)

Example 3 with World

use of com.sk89q.worldedit.world.World in project FunnyGuilds by FunnyGuilds.

the class SchematicHelper method pasteSchematic.

public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ());
        World pasteWorld = new BukkitWorld(location.getWorld());
        WorldData pasteWorldData = pasteWorld.getWorldData();
        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData);
        Region pasteRegion = clipboard.getRegion();
        Extent pasteExtent = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);
        AffineTransform transform = new AffineTransform();
        ForwardExtentCopy copy = new ForwardExtentCopy(pasteExtent, pasteRegion, clipboard.getOrigin(), pasteExtent, pasteLocation);
        if (!transform.isIdentity()) {
            copy.setTransform(transform);
        }
        if (!withAir) {
            copy.setSourceMask(new ExistingBlockMask(clipboard));
        }
        Operations.completeLegacy(copy);
        return true;
    } catch (IOException | MaxChangedBlocksException e) {
        FunnyLogger.exception(e);
        return false;
    }
}
Also used : Extent(com.sk89q.worldedit.extent.Extent) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) WorldData(com.sk89q.worldedit.world.registry.WorldData) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) FileInputStream(java.io.FileInputStream) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Vector(com.sk89q.worldedit.Vector)

Aggregations

Region (com.sk89q.worldedit.regions.Region)3 World (com.sk89q.worldedit.world.World)3 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)2 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)2 Vector (org.bukkit.util.Vector)2 LocalPlayer (com.sk89q.worldedit.LocalPlayer)1 LocalSession (com.sk89q.worldedit.LocalSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Vector (com.sk89q.worldedit.Vector)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 Extent (com.sk89q.worldedit.extent.Extent)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)1 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)1 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)1 WorldData (com.sk89q.worldedit.world.registry.WorldData)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1