Search in sources :

Example 1 with IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException 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 IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException in project PixelsSkyblock by dudullle.

the class WEManager method count_entities.

public static List<? extends Entity> count_entities(World world, Location loc1, Location loc2) {
    EditSession es = new EditSessionBuilder(FaweAPI.getWorld("world")).fastmode(true).build();
    CuboidSelection cbs = new CuboidSelection(world, loc1, loc2);
    Region r = null;
    try {
        r = cbs.getRegionSelector().getRegion();
    } catch (IncompleteRegionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return es.getEntities(r);
}
Also used : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) EditSessionBuilder(com.boydti.fawe.util.EditSessionBuilder) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 3 with IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException in project PixelsSkyblock by dudullle.

the class WEManager method count.

public static List<Countable<Integer>> count(World world, Location loc1, Location loc2) {
    EditSession es = new EditSessionBuilder(FaweAPI.getWorld("world")).fastmode(true).build();
    CuboidSelection cbs = new CuboidSelection(world, loc1, loc2);
    Region r = null;
    try {
        r = cbs.getRegionSelector().getRegion();
    } catch (IncompleteRegionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return es.getBlockDistribution(r);
}
Also used : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) EditSessionBuilder(com.boydti.fawe.util.EditSessionBuilder) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 4 with IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException in project RedProtect by FabioZumbi12.

the class WEListener method regenRegion.

public static void regenRegion(final br.net.fabiozumbi12.RedProtect.Bukkit.Region r, final World w, final Location p1, final Location p2, final int delay, final CommandSender sender, final boolean remove) {
    Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> {
        if (RPUtil.stopRegen) {
            return;
        }
        CuboidSelection csel = new CuboidSelection(w, p1, p2);
        Region wreg = null;
        try {
            wreg = csel.getRegionSelector().getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
        }
        EditSession esession = new EditSession(LocalWorldAdapter.adapt(wreg.getWorld()), -1);
        eSessions.put(r.getID(), esession);
        int delayCount = 1 + delay / 10;
        if (sender != null) {
            if (wreg.getWorld().regenerate(wreg, esession)) {
                RPLang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
            } else {
                RPLang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
            }
        } else {
            if (wreg.getWorld().regenerate(wreg, esession)) {
                RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
            } else {
                RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
            }
        }
        if (remove) {
            RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(r.getWorld()));
        }
        if (RPConfig.getInt("purge.regen.stop-server-every") > 0 && delayCount > RPConfig.getInt("purge.regen.stop-server-every")) {
            Bukkit.getScheduler().cancelTasks(RedProtect.get());
            RedProtect.get().rm.saveAll();
            Bukkit.getServer().shutdown();
        }
    }, delay);
}
Also used : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 5 with IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException in project RedProtect by FabioZumbi12.

the class WEListener method pasteWithWE.

public static void pasteWithWE(Player p, File f) throws DataException {
    SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
    SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());
    LocalSession session = SpongeWorldEdit.inst().getSession(p);
    Closer closer = Closer.create();
    try {
        ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
        FileInputStream fis = closer.register(new FileInputStream(f));
        BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
        ClipboardReader reader = format.getReader(bis);
        WorldData worldData = ws.getWorldData();
        Clipboard clipboard = reader.read(ws.getWorldData());
        session.setClipboard(new ClipboardHolder(clipboard, worldData));
        ClipboardHolder holder = session.getClipboard();
        Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
        Operations.completeLegacy(op);
    } catch (IOException | MaxChangedBlocksException | EmptyClipboardException | IncompleteRegionException e) {
        e.printStackTrace();
    }
}
Also used : Closer(com.sk89q.worldedit.util.io.Closer) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) WorldData(com.sk89q.worldedit.world.registry.WorldData) Operation(com.sk89q.worldedit.function.operation.Operation) IOException(java.io.IOException) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) FileInputStream(java.io.FileInputStream) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) BufferedInputStream(java.io.BufferedInputStream) SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)

Aggregations

IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)8 Region (com.sk89q.worldedit.regions.Region)7 EditSession (com.sk89q.worldedit.EditSession)4 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)4 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)3 Vector (org.bukkit.util.Vector)3 EditSessionBuilder (com.boydti.fawe.util.EditSessionBuilder)2 LocalPlayer (com.sk89q.worldedit.LocalPlayer)2 LocalSession (com.sk89q.worldedit.LocalSession)2 World (com.sk89q.worldedit.world.World)2 EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 LocalWorld (com.sk89q.worldedit.LocalWorld)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)1 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 SpongePlayer (com.sk89q.worldedit.sponge.SpongePlayer)1