com.sk89q.worldedit.regions.RegionSelector Java Examples

The following examples show how to use com.sk89q.worldedit.regions.RegionSelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldEditApiProvider.java    From GriefPrevention with MIT License 6 votes vote down vote up
public void revertVisuals(Player player, GPPlayerData playerData, UUID claimUniqueId) {
    final LocalSession session = this.getLocalSession(player.getName());
    if (session == null || !session.hasCUISupport()) {
        return;
    }
    final World world = this.getWorld(player.getWorld());
    final RegionSelector region = session.getRegionSelector(world);
    final GPActor actor = this.getOrCreateActor(player);
    region.clear();
    session.dispatchCUISelection(actor);
    if (claimUniqueId != null) {
        actor.dispatchCUIEvent(new MultiSelectionClearEvent(claimUniqueId));
    } else {
        actor.dispatchCUIEvent(new MultiSelectionClearEvent());
    }
}
 
Example #2
Source File: CuboidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a copy of another selector.
 *
 * @param oldSelector another selector
 */
public CuboidRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());

    if (oldSelector instanceof CuboidRegionSelector) {
        final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;

        position1 = cuboidRegionSelector.position1;
        position2 = cuboidRegionSelector.position2;
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        position1 = oldRegion.getMinimumPoint().toBlockVector();
        position2 = oldRegion.getMaximumPoint().toBlockVector();
    }
    region.setPos1(position1);
    region.setPos2(position2);
}
 
Example #3
Source File: EllipsoidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new selector from the given selector.
 *
 * @param oldSelector the old selector
 */
public EllipsoidRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
    if (oldSelector instanceof EllipsoidRegionSelector) {
        final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;

        region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
    } else {
        Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        BlockVector pos1 = oldRegion.getMinimumPoint().toBlockVector();
        BlockVector pos2 = oldRegion.getMaximumPoint().toBlockVector();

        Vector center = pos1.add(pos2).divide(2).floor();
        region.setCenter(center);
        region.setRadius(pos2.subtract(center));
    }
}
 
Example #4
Source File: WorldEditApiProvider.java    From GriefPrevention with MIT License 5 votes vote down vote up
public RegionSelector getRegionSelector(Player player) {
    final LocalSession session = getLocalSession(player.getName());
    if (session == null) {
        return null;
    }

    World world = session.getSelectionWorld();
    if (world == null) {
        world = this.getWorld(player.getWorld());
    }
    return session.getRegionSelector(world);
}
 
Example #5
Source File: CylinderRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector from the given one.
 *
 * @param oldSelector the old selector
 */
public CylinderRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());

    if (oldSelector instanceof CylinderRegionSelector) {
        final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;

        region = new CylinderRegion(cylSelector.region);
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        Vector pos1 = oldRegion.getMinimumPoint();
        Vector pos2 = oldRegion.getMaximumPoint();

        Vector center = pos1.add(pos2).divide(2).floor();
        region.setCenter(center.toVector2D());
        region.setRadius(pos2.toVector2D().subtract(center.toVector2D()));

        region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
        region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
    }
}
 
Example #6
Source File: ExtendingCuboidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector from another one.
 *
 * @param oldSelector the other selector
 */
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
    super(oldSelector);

    if (position1 == null || position2 == null) {
        return;
    }

    position1 = region.getMinimumPoint().toBlockVector();
    position2 = region.getMaximumPoint().toBlockVector();
    region.setPos1(position1);
    region.setPos2(position2);
}
 
Example #7
Source File: ConvexPolyhedralRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector.
 *
 * @param oldSelector the old selector
 */
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector) {
    checkNotNull(oldSelector);

    if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
        final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;

        pos1 = convexPolyhedralRegionSelector.pos1;
        region = new ConvexPolyhedralRegion(convexPolyhedralRegionSelector.region);
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            region = new ConvexPolyhedralRegion(oldSelector.getIncompleteRegion().getWorld());
            return;
        }

        final int minY = oldRegion.getMinimumPoint().getBlockY();
        final int maxY = oldRegion.getMaximumPoint().getBlockY();

        region = new ConvexPolyhedralRegion(oldRegion.getWorld());

        for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(Integer.MAX_VALUE))) {
            region.addVertex(pt.toVector(minY));
            region.addVertex(pt.toVector(maxY));
        }

        learnChanges();
    }
}
 
Example #8
Source File: SphereRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector from another one
 *
 * @param oldSelector the old selector
 */
public SphereRegionSelector(RegionSelector oldSelector) {
    super(oldSelector);
    final Vector radius = region.getRadius();
    final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
    region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
}
 
Example #9
Source File: WorldEditHelper.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@Nullable
private Region getSelectedRegion(@Nullable LocalSession session) {
    if (session != null && session.getSelectionWorld() != null) {
        RegionSelector selector = session.getRegionSelector(session.getSelectionWorld());

        if (selector.isDefined()) {
            try {
                return selector.getRegion();
            } catch (IncompleteRegionException e) {
                plugin.getLogger().warning("Region still incomplete");
            }
        }
    }
    return null;
}
 
Example #10
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the region selector for defining the selection. If the selection
 * was defined for a different world, the old selection will be discarded.
 *
 * @param world the world
 * @return position the position
 */
public RegionSelector getRegionSelector(World world) {
    checkNotNull(world);
    try {
        if (selector.getWorld() == null || !selector.getWorld().equals(world)) {
            selector.setWorld(world);
            selector.clear();
        }
    } catch (Throwable ignore) {
        selector.clear();
    }
    return selector;
}
 
Example #11
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private static void setSelection(BukkitWorld ws, Player p, Location pos1, Location pos2) {
    WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    RegionSelector regs = worldEdit.getSession(p).getRegionSelector(ws);
    regs.selectPrimary(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), null);
    regs.selectSecondary(BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()), null);
    worldEdit.getSession(p).setRegionSelector(ws, regs);
    worldEdit.getSession(p).dispatchCUISelection(worldEdit.wrapPlayer(p));
}
 
Example #12
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the region selector.
 *
 * @param world    the world
 * @param selector the selector
 */
public void setRegionSelector(World world, RegionSelector selector) {
    checkNotNull(world);
    checkNotNull(selector);
    selector.setWorld(world);
    this.selector = selector;
}
 
Example #13
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private static void setSelection(SpongeWorld ws, Player p, Location pos1, Location pos2) {
    RegionSelector regs = SpongeWorldEdit.inst().getSession(p).getRegionSelector(ws);
    regs.selectPrimary(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), null);
    regs.selectSecondary(new Vector(pos2.getX(), pos2.getY(), pos2.getZ()), null);
    SpongeWorldEdit.inst().getSession(p).setRegionSelector(ws, regs);
    SpongeWorldEdit.inst().getSession(p).dispatchCUISelection(SpongeWorldEdit.inst().wrapPlayer(p));
}
 
Example #14
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void regenRegion(final Region region, final World world, final Location p1, final Location p2, final int delay, final CommandSender sender, final boolean remove) {
    Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> {
        if (RedProtect.get().getUtil().stopRegen) {
            return;
        }

        RegionSelector regs = new LocalSession().getRegionSelector(new BukkitWorld(world));
        regs.selectPrimary(BlockVector3.at(p1.getX(), p1.getY(), p1.getZ()), null);
        regs.selectSecondary(BlockVector3.at(p2.getX(), p2.getY(), p2.getZ()), null);

        com.sk89q.worldedit.regions.Region wReg;
        try {
            wReg = regs.getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
            return;
        }

        try (EditSession eSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1)) {
            eSessions.put(region.getID(), eSession);
            int delayCount = 1 + delay / 10;

            com.sk89q.worldedit.world.World wRegWorld = wReg.getWorld();
            if (wRegWorld == null) return;

            if (sender != null) {
                if (wRegWorld.regenerate(wReg, eSession)) {
                    RedProtect.get().lang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + region.getID().split("@")[0] + " regenerated with success!");
                } else {
                    RedProtect.get().lang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + region.getID().split("@")[0] + "!");
                }
            } else {
                if (wRegWorld.regenerate(wReg, eSession)) {
                    eSession.setMask(null);
                    RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + region.getID().split("@")[0] + " regenerated with success!");
                } else {
                    RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + region.getID().split("@")[0] + "!");
                }
            }

            if (remove) {
                region.notifyRemove();
                RedProtect.get().rm.remove(region, region.getWorld());
            }

            if (delayCount % 50 == 0) {
                RedProtect.get().rm.saveAll(true);
            }

            if (RedProtect.get().config.configRoot().purge.regen.stop_server_every > 0 && delayCount > RedProtect.get().config.configRoot().purge.regen.stop_server_every) {

                Bukkit.getScheduler().cancelTasks(RedProtect.get());
                RedProtect.get().rm.saveAll(false);

                Bukkit.getServer().shutdown();
            }
        }
    }, delay);
}
 
Example #15
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void regenRegion(final Region r, final World w, final Location<World> p1, final Location<World> p2, final int delay, final CommandSource sender, final boolean remove) {
    Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
        if (RedProtect.get().getUtil().stopRegen) {
            return;
        }

        RegionSelector regs = new LocalSession().getRegionSelector(SpongeWorldEdit.inst().getWorld(w));
        regs.selectPrimary(new Vector(p1.getX(), p1.getY(), p1.getZ()), null);
        regs.selectSecondary(new Vector(p2.getX(), p2.getY(), p2.getZ()), null);

        com.sk89q.worldedit.regions.Region wreg = null;
        try {
            wreg = regs.getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
        }

        EditSession esession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(SpongeWorldEdit.inst().getWorld(w), -1);

        eSessions.put(r.getID(), esession);
        int delayCount = 1 + delay / 10;

        if (sender != null) {
            if (wreg.getWorld().regenerate(wreg, esession)) {
                RedProtect.get().lang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
            } else {
                RedProtect.get().lang.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) {
            r.notifyRemove();
            RedProtect.get().rm.remove(r, r.getWorld());
        }

        if (delayCount % 50 == 0) {
            RedProtect.get().rm.saveAll(true);
        }

        if (RedProtect.get().config.configRoot().purge.regen.stop_server_every > 0 && delayCount > RedProtect.get().config.configRoot().purge.regen.stop_server_every) {
            Sponge.getScheduler().getScheduledTasks(RedProtect.get().container).forEach(Task::cancel);
            RedProtect.get().rm.saveAll(false);

            Sponge.getServer().shutdown();
        }

    }, delay, TimeUnit.MILLISECONDS);
}
 
Example #16
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @deprecated use {@link #setRegionSelector(World, RegionSelector)}
 */
@Deprecated
public void setRegionSelector(LocalWorld world, RegionSelector selector) {
    setRegionSelector((World) world, selector);
}
 
Example #17
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @deprecated use {@link #getRegionSelector(World)}
 */
@Deprecated
public RegionSelector getRegionSelector() {
    return selector;
}
 
Example #18
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @deprecated Use {@link #getRegionSelector(World)}
 */
@Deprecated
public RegionSelector getRegionSelector(LocalWorld world) {
    return getRegionSelector((World) world);
}