Search in sources :

Example 1 with Region

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

use of com.sk89q.worldedit.regions.Region in project Skree by Skelril.

the class WEDecorator method pasteAt.

public <T> ZoneWorldBoundingBox pasteAt(WorldResolver world, Vector3i origin, String resourceName, Function<ZoneWorldBoundingBox, T> initMapper, Consumer<T> callback) {
    EditSession transaction = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world.getWorldEditWorld(), -1);
    transaction.setFastMode(true);
    transaction.getChangeSet().setRecordChanges(false);
    hashRefMap.computeIfAbsent(resourceName, (a) -> {
        HashRef ref = new HashRef();
        try {
            ref.holder = getHolder(resourceName, world.getWorldEditWorld().getWorldData());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ref;
    });
    HashRef ref = hashRefMap.get(resourceName);
    if (ref == null) {
        callback.accept(null);
        return null;
    }
    ++ref.refCount;
    Clipboard clipboard = ref.holder.getClipboard();
    Region clipReg = clipboard.getRegion();
    clipboard.setOrigin(clipReg.getMinimumPoint());
    Operation operation = ref.holder.createPaste(transaction, transaction.getWorld().getWorldData()).to(new Vector(origin.getX(), origin.getY(), origin.getZ())).build();
    Vector dimensions = clipboard.getDimensions();
    ZoneWorldBoundingBox region = new ZoneWorldBoundingBox(world.getSpongeWorld(), origin, new Vector3i(dimensions.getX(), dimensions.getY(), dimensions.getZ()));
    T returnVal = initMapper.apply(region);
    RunManager.runOperation(operation, () -> {
        RunManager.runOperation(transaction.commit(), () -> {
            callback.accept(returnVal);
            if (--ref.refCount == 0) {
                hashRefMap.remove(resourceName);
                System.gc();
            }
        });
    });
    return region;
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Operation(com.sk89q.worldedit.function.operation.Operation) Vector(com.sk89q.worldedit.Vector) ZoneWorldBoundingBox(com.skelril.skree.service.internal.zone.ZoneWorldBoundingBox)

Example 3 with Region

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

Region (com.sk89q.worldedit.regions.Region)3 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)2 LocalPlayer (com.sk89q.worldedit.LocalPlayer)2 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)2 Vector (org.bukkit.util.Vector)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 EditSession (com.sk89q.worldedit.EditSession)1 LocalWorld (com.sk89q.worldedit.LocalWorld)1 Vector (com.sk89q.worldedit.Vector)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 World (com.sk89q.worldedit.world.World)1 ZoneWorldBoundingBox (com.skelril.skree.service.internal.zone.ZoneWorldBoundingBox)1 IOException (java.io.IOException)1 DataType (uk.co.oliwali.HawkEye.DataType)1 SearchParser (uk.co.oliwali.HawkEye.SearchParser)1 RollbackCallback (uk.co.oliwali.HawkEye.callbacks.RollbackCallback)1 SearchQuery (uk.co.oliwali.HawkEye.database.SearchQuery)1