Java Code Examples for com.sk89q.worldedit.world.World#getWorldData()

The following examples show how to use com.sk89q.worldedit.world.World#getWorldData() . 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: SchematicHelper.java    From FunnyGuilds with Apache License 2.0 8 votes vote down vote up
public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ());
        World pasteWorld = new BukkitWorld(location.getWorld());
        WorldData pasteWorldData = pasteWorld.getWorldData();

        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData);
        ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, pasteWorldData);

        EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);

        Operation operation = clipboardHolder
                .createPaste(editSession, pasteWorldData)
                .to(pasteLocation)
                .ignoreAirBlocks(!withAir)
                .build();

        Operations.completeLegacy(operation);
        return true;
    }
    catch (IOException | MaxChangedBlocksException e) {
        FunnyGuilds.getInstance().getPluginLogger().error("Could not paste schematic: " + schematicFile.getAbsolutePath(), e);
        return false;
    }
}
 
Example 2
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 3
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 4
Source File: CFICommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"schem", "schematic", "schems", "schematics", "addschems"},
        usage = "[url] <mask> <file|folder|url> <rarity> <distance> <rotate=true>",
        desc = "Populate schematics",
        help = "Populate a schematic on the terrain\n" +
                " - Change the mask (e.g. angle mask) to only place the schematic in specific locations.\n" +
                " - The rarity is a value between 0 and 100.\n" +
                " - The distance is the spacing between each schematic"
)
@CommandPermissions("worldedit.anvil.cfi")
public void schem(FawePlayer fp, @Optional BufferedImage imageMask, Mask mask, String schematic, int rarity, int distance, boolean rotate) throws ParameterException, IOException, WorldEditException {
    HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();

    World world = fp.getWorld();
    WorldData wd = world.getWorldData();
    MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(fp.getPlayer(), wd, schematic, true);
    if (multi == null) {
        return;
    }
    if (imageMask == null) {
        gen.addSchems(mask, wd, multi.getHolders(), rarity, distance, rotate);
    } else {
        gen.addSchems(imageMask, mask, wd, multi.getHolders(), rarity, distance, rotate);
    }
    msg("Added schematics!").send(fp);
    populate(fp);
}