Java Code Examples for com.sk89q.worldedit.regions.Region#getWorld()

The following examples show how to use com.sk89q.worldedit.regions.Region#getWorld() . 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: DefaultFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	Clipboard clipboard = floor.getClipboard();
	
	Region region = clipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(clipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
Source File: SimpleClipboardFloor.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Deprecated
public void generate(EditSession session) {
	Region region = floorClipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(floorClipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example 3
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 4
Source File: FAWEFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
    Clipboard clipboard = floor.getClipboard();
    Schematic faweSchematic = new Schematic(clipboard);

    Region region = clipboard.getRegion();
    World world = region.getWorld();
    if (world == null) {
        throw new IllegalStateException("World of floor " + floor.getName() + " is null!");
    }

    faweSchematic.paste(world, region.getMinimumPoint(), false, false, (Transform) null);
}
 
Example 5
Source File: WorldEditHelper.java    From WorldEditSelectionVisualizer with MIT License 4 votes vote down vote up
public void updatePlayerVisualization(PlayerVisualizerInfos playerInfo, SelectionType type) {
    Player player = playerInfo.getPlayer();
    LocalSession session;
    try {
        session = worldEditPlugin.getSession(player);
    } catch (Exception e) {
        // sometimes after a reload getSession create errors with WorldEdit, this prevent error spam
        return;
    }

    PlayerSelection playerSelection = playerInfo.getSelection(type).orElse(null);

    if (playerSelection == null || session == null) {
        return;
    }

    Vector3d origin = Vector3d.ZERO;
    Region region;

    if (type == SelectionType.CLIPBOARD) {
        ClipboardHolder clipboardHolder = getClipboardHolder(session);

        if (clipboardHolder == null) {
            playerSelection.resetSelection();
            return;
        }

        Clipboard clipboard = clipboardHolder.getClipboard();
        Transform transform = clipboardHolder.getTransform();

        origin = plugin.getCompatibilityHelper().adaptClipboard(clipboard).getOrigin();
        region = clipboard.getRegion().clone();

        if (!transform.isIdentity()) {
            region = plugin.getCompatibilityHelper().adaptRegion(region).transform(transform, origin);
        }
    } else {
        region = getSelectedRegion(session);
    }

    if (region == null) {
        playerSelection.resetSelection();
        return;
    }

    if (type == SelectionType.SELECTION && (region.getWorld() == null || !region.getWorld().getName().equals(player.getWorld().getName()))) {
        playerSelection.resetSelection();
        return;
    }

    RegionAdapter regionAdapter = plugin.getCompatibilityHelper().adaptRegion(region);
    RegionInfos regionInfos = regionAdapter.getRegionsInfos();

    if (regionInfos.equals(playerSelection.getLastSelectedRegion())) {
        SelectionPoints points = playerSelection.getSelectionPoints();
        if (points == null || points.origin().equals(origin)) {
            return;
        }
    }

    if (!player.hasPermission("wesv.use")) {
        playerSelection.resetSelection(regionInfos);
        return;
    }

    GlobalSelectionConfig config = plugin.getSelectionConfig(type);
    if (region.getArea() > config.getMaxSelectionSize()) {
        if (!playerSelection.isLastSelectionTooLarge()) {
            String message = plugin.getMessage("selection-too-large").replace("%blocks%", Integer.toString(config.getMaxSelectionSize()));
            plugin.getCompatibilityHelper().sendActionBar(player, message);
        }

        playerSelection.resetSelection(regionInfos);
        playerSelection.setLastSelectionTooLarge(true);
        return;
    }

    plugin.updateHoldingSelectionItem(playerInfo);

    Bukkit.getPluginManager().callEvent(new SelectionChangeEvent(player, region));

    ShapeProcessor<?> shapeProcessor = shapeProcessors.get(region.getClass());

    if (shapeProcessor != null) {
        playerSelection.updateSelection(shapeProcessor.processSelection(regionAdapter, config, origin), regionInfos, config.getFadeDelay());
    } else {
        // Unsupported selection type
        playerSelection.resetSelection(regionInfos);
    }
}
 
Example 6
Source File: FlagRegenPercentage.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	if (cause == RegenerationCause.COUNTDOWN) {
		return;
	}
	
	Region region = floor.getRegion();
	
	double percentage = getValue() / 100D;
	int area = region.getArea();
	
	int notRegenerating = area - (int) (percentage * area);
	
	Iterator<BlockVector> iterator = region.iterator();
	List<BlockVector> vectors = Lists.newArrayList();
	Map<BlockVector, BaseBlock> clipboardBlockCache = Maps.newHashMap();
	Clipboard clipboard = floor.getClipboard();
	
	while (iterator.hasNext()) {
		BlockVector vector = iterator.next();
		BaseBlock block = clipboard.getLazyBlock(vector);
		clipboardBlockCache.put(vector, block);
		
		if (block.getType() == AIR_ID) {
			continue;
		}
		
		vectors.add(vector);
	}
	
	for (int i = 0; i < notRegenerating; i++) {
		int rnd = random.nextInt(vectors.size());
		vectors.remove(rnd);
	}
	
	World world = region.getWorld();
	
	try {
		//Iterate over all remaining block vectors and regenerate these blocks
		for (BlockVector regeneratingBlock : vectors) {
			BaseBlock clipboardBlock = clipboardBlockCache.get(regeneratingBlock);
			BaseBlock worldBlock = world.getBlock(regeneratingBlock);
			
			int id = clipboardBlock.getId();
			int data = clipboardBlock.getData();
			
			worldBlock.setIdAndData(id, data);
			world.setBlock(regeneratingBlock, worldBlock);
		}
	} catch (WorldEditException e) {
		getHeavySpleef().getLogger().log(Level.SEVERE, "Failed to regenerate floor " + floor.getName() + " for game " + game.getName(), e);
	}
}