Search in sources :

Example 6 with IncompleteRegionException

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

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

the class AWEListener 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;
        try {
            wreg = csel.getRegionSelector().getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
            return;
        }
        AsyncWorldEditBukkit aweMain = (AsyncWorldEditBukkit) Bukkit.getPluginManager().getPlugin("AsyncWorldEdit");
        IBlockPlacer bPlacer = aweMain.getBlockPlacer();
        final IBlockPlacerListener listener = new IBlockPlacerListener() {

            @Override
            public void jobAdded(IJobEntry job) {
            /*if (job.getPlayer().getName().equals("redprotect")){
                        String name = job.getName();
                        //job.addStateChangedListener(stateListener);
                        RedProtect.get().logger.warning("JobAdded: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.isTaskDone());
                    }*/
            }

            @Override
            public void jobRemoved(IJobEntry job) {
                if (job.getPlayer().getName().equals("redprotect")) {
                    String name = job.getName();
                    // job.addStateChangedListener(stateListener);
                    if (RPConfig.getBool("purge.regen.awe-logs") && job.isTaskDone()) {
                        RedProtect.get().logger.sucess("JobDone: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.getStatusString());
                    }
                }
            }
        };
        bPlacer.addListener(listener);
        AsyncEditSessionFactory factory = (AsyncEditSessionFactory) WorldEdit.getInstance().getEditSessionFactory();
        EditSession ess = factory.getEditSession(wreg.getWorld(), -1);
        eSessions.put(r.getID(), ess);
        int delayCount = 1 + delay / 10;
        if (sender != null) {
            if (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
                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 (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
                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 : AsyncWorldEditBukkit(org.primesoft.asyncworldedit.AsyncWorldEditBukkit) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) PlayerManager(org.primesoft.asyncworldedit.playerManager.PlayerManager) IBlockPlacer(org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacer) IBlockPlacerListener(org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacerListener) IJobEntry(org.primesoft.asyncworldedit.api.blockPlacer.entries.IJobEntry) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) AsyncEditSessionFactory(org.primesoft.asyncworldedit.worldedit.AsyncEditSessionFactory)

Example 8 with IncompleteRegionException

use of com.sk89q.worldedit.IncompleteRegionException in project HawkEye by oliverwoodings.

the class WorldEditRollbackCommand method execute.

@Override
public boolean execute() {
    // Check if player already has a rollback processing
    if (session.doingRollback()) {
        Util.sendMessage(sender, "&cYou already have a rollback command processing!");
        return true;
    }
    // Check if WorldEdit is enabled
    if (HawkEye.worldEdit == null) {
        Util.sendMessage(sender, "&7WorldEdit&c is not enabled, unable to perform rollbacks in selected region");
        return true;
    }
    // Check if the WorldEdit selection is complete
    Region region = null;
    try {
        LocalPlayer lp = new BukkitPlayer(HawkEye.worldEdit, HawkEye.worldEdit.getWorldEdit().getServer(), player);
        LocalWorld lw = lp.getWorld();
        region = HawkEye.worldEdit.getWorldEdit().getSession(lp).getSelection(lw);
    } catch (IncompleteRegionException e) {
        Util.sendMessage(sender, "&cPlease complete your selection before doing a &7WorldEdit&c rollback!");
        return true;
    }
    // Parse arguments
    SearchParser parser = null;
    try {
        parser = new SearchParser(player, args);
        // Check that supplied actions can rollback
        if (parser.actions.size() > 0) {
            for (DataType type : parser.actions) if (!type.canRollback())
                throw new IllegalArgumentException("You cannot rollback that action type: &7" + type.getConfigName());
        } else // If none supplied, add in all rollback types
        {
            for (DataType type : DataType.values()) if (type.canRollback())
                parser.actions.add(type);
        }
    } catch (IllegalArgumentException e) {
        Util.sendMessage(sender, "&c" + e.getMessage());
        return true;
    }
    // Set WorldEdit locations
    parser.minLoc = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
    parser.maxLoc = new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
    // Create new SearchQuery with data
    new SearchQuery(new RollbackCallback(session, RollbackType.GLOBAL), parser, SearchDir.DESC);
    return true;
}
Also used : SearchQuery(uk.co.oliwali.HawkEye.database.SearchQuery) LocalWorld(com.sk89q.worldedit.LocalWorld) LocalPlayer(com.sk89q.worldedit.LocalPlayer) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) DataType(uk.co.oliwali.HawkEye.DataType) SearchParser(uk.co.oliwali.HawkEye.SearchParser) Vector(org.bukkit.util.Vector) RollbackCallback(uk.co.oliwali.HawkEye.callbacks.RollbackCallback) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer)

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