com.sk89q.worldedit.world.registry.WorldData Java Examples

The following examples show how to use com.sk89q.worldedit.world.registry.WorldData. 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: 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: 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 #4
Source File: Schematic.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void paste(Extent extent, WorldData worldData, Vector to, boolean pasteAir, Transform transform) {
    checkNotNull(transform);
    Region region = clipboard.getRegion();
    Extent source = clipboard;
    if (worldData != null && transform != null) {
        source = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to);
    if (transform != null) {
        copy.setTransform(transform);
    }
    copy.setCopyBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes());
    if (extent instanceof EditSession) {
        EditSession editSession = (EditSession) extent;
        Mask sourceMask = editSession.getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            editSession.setSourceMask(null);
        }
    }
    if (!pasteAir) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    Operations.completeBlindly(copy);
}
 
Example #5
Source File: PasteBuilder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param holder          the clipboard holder
 * @param targetExtent    an extent
 * @param targetWorldData world data of the target
 */
public PasteBuilder(ClipboardHolder holder, Extent targetExtent, WorldData targetWorldData) {
    checkNotNull(holder);
    checkNotNull(targetExtent);
    checkNotNull(targetWorldData);
    this.clipboard = holder.getClipboard();
    this.worldData = holder.getWorldData();
    this.transform = holder.getTransform();
    this.targetExtent = targetExtent;
    this.targetWorldData = targetWorldData;
}
 
Example #6
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);
}
 
Example #7
Source File: BukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public WorldData getWorldData() {
    try {
        Class<?> wd = Class.forName("com.sk89q.worldedit.bukkit.BukkitWorldData");
        Method methodInstance = wd.getDeclaredMethod("getInstance");
        methodInstance.setAccessible(true);
        return (WorldData) methodInstance.invoke(null);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: ClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance with the given clipboard.
 *
 * @param clipboard the clipboard
 * @param worldData the mapping of blocks, entities, and so on
 */
public ClipboardHolder(Clipboard clipboard, WorldData worldData) {
    checkNotNull(clipboard);
    checkNotNull(worldData);
    this.clipboard = clipboard;
    this.worldData = worldData;
}
 
Example #9
Source File: SchemGen.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public SchemGen(Mask mask, Extent extent, WorldData worldData, List<ClipboardHolder> clipboards, boolean randomRotate) {
    this.mask = mask;
    this.extent = extent;
    this.worldData = worldData;
    this.clipboards = clipboards;
    this.randomRotate = randomRotate;
}
 
Example #10
Source File: WavefrontReader.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Clipboard read(WorldData data) throws IOException {
    try (InputStream finalStream = inputStream) {
        load(finalStream);
    }
    return null;
}
 
Example #11
Source File: SchematicReader.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public Clipboard read(WorldData data, final UUID clipboardId) throws IOException {
    try {
        return new SchematicStreamer(inputStream, clipboardId).getClipboard();
    } catch (Exception e) {
        Fawe.debug("Input is corrupt!");
        e.printStackTrace();
        return new CorruptSchematicStreamer(rootStream, clipboardId).recover();
    }
}
 
Example #12
Source File: SchematicWriter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(final Clipboard clipboard, WorldData data) throws IOException {
    if (clipboard instanceof BlockArrayClipboard) {
        stream((BlockArrayClipboard) clipboard);
    } else {
        outputStream.writeNamedTag("Schematic", writeTag(clipboard));
        outputStream.flush();
    }
}
 
Example #13
Source File: LazyClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance with the given clipboard.
 *
 * @param worldData the mapping of blocks, entities, and so on
 */
public LazyClipboardHolder(URI uri, ByteSource source, ClipboardFormat format, WorldData worldData, UUID uuid) {
    super(uri, EmptyClipboard.INSTANCE, worldData);
    this.source = source;
    this.format = format;
    this.uuid = uuid != null ? uuid : UUID.randomUUID();
}
 
Example #14
Source File: FlattenedClipboardTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param original  the original clipboard
 * @param transform the transform
 * @param worldData the world data instance
 */
private FlattenedClipboardTransform(Clipboard original, Transform transform, WorldData worldData) {
    checkNotNull(original);
    checkNotNull(transform);
    checkNotNull(worldData);
    this.original = original;
    this.transform = transform;
    this.worldData = worldData;
}
 
Example #15
Source File: MultiClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public MultiClipboardHolder(Clipboard clipboard, WorldData worldData) {
    super(URI.create(""), EmptyClipboard.INSTANCE, worldData);
    holders = new ArrayList<>();
    URI uri = URI.create("");
    if (clipboard instanceof BlockArrayClipboard) {
        FaweClipboard fc = ((BlockArrayClipboard) clipboard).IMP;
        if (fc instanceof DiskOptimizedClipboard) {
            uri = ((DiskOptimizedClipboard) fc).getFile().toURI();
        }
    }
    add(uri, clipboard);
}
 
Example #16
Source File: SchematicCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"loadall"},
        usage = "[<format>] <filename|url>",
        help = "Load multiple clipboards\n" +
                "The -r flag will apply random rotation",
        desc = "Load multiple clipboards (paste will randomly choose one)"
)
@Deprecated
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.upload"})
public void loadall(final Player player, final LocalSession session, @Optional("schematic") final String formatName, final String filename, @Switch('r') boolean randomRotate) throws FilenameException {
    final ClipboardFormat format = ClipboardFormat.findByAlias(formatName);
    if (format == null) {
        BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
        return;
    }
    try {
        WorldData wd = player.getWorld().getWorldData();

        MultiClipboardHolder all = format.loadAllFromInput(player, wd, filename, true);
        if (all != null) {
            session.addClipboard(all);
            BBC.SCHEMATIC_LOADED.send(player, filename);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: FawePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads any history items from disk:
 * - Should already be called if history on disk is enabled
 */
public void loadClipboardFromDisk() {
    File file = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.CLIPBOARD + File.separator + getUUID() + ".bd");
    try {
        if (file.exists() && file.length() > 5) {
            DiskOptimizedClipboard doc = new DiskOptimizedClipboard(file);
            Player player = toWorldEditPlayer();
            LocalSession session = getSession();
            try {
                if (session.getClipboard() != null) {
                    return;
                }
            } catch (EmptyClipboardException e) {
            }
            if (player != null && session != null) {
                WorldData worldData = player.getWorld().getWorldData();
                Clipboard clip = doc.toClipboard();
                ClipboardHolder holder = new ClipboardHolder(clip, worldData);
                getSession().setClipboard(holder);
            }
        }
    } catch (Exception ignore) {
        Fawe.debug("====== INVALID CLIPBOARD ======");
        MainUtil.handleError(ignore, false);
        Fawe.debug("===============---=============");
        Fawe.debug("This shouldn't result in any failure");
        Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")");
        Fawe.debug("===============---=============");
    }
}
 
Example #18
Source File: RandomFullClipboardPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public RandomFullClipboardPattern(Extent extent, WorldData worldData, List<ClipboardHolder> clipboards, boolean randomRotate, boolean randomFlip) {
    checkNotNull(clipboards);
    this.clipboards = clipboards;
    this.extent = extent;
    this.randomRotate = randomRotate;
    this.worldData = worldData;
}
 
Example #19
Source File: LocalWorldAdapter.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WorldData getWorldData() {
    return world.getWorldData();
}
 
Example #20
Source File: SchematicReader.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Clipboard read(WorldData data) throws IOException {
    return read(data, UUID.randomUUID());
}
 
Example #21
Source File: Extent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
default public void addSchems(Region region, Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
    spawnResource(region, new SchemGen(mask, this, worldData, clipboards, rotate), rarity, 1);
}
 
Example #22
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public WorldData getWorldData() {
    return getWorld() != null ? getWorld().getWorldData() : null;
}
 
Example #23
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static Region pasteWithWE(Player p, File file) {
    Location<World> loc = p.getLocation();
    Region r = null;

    if (p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.WATER) ||
            p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.FLOWING_WATER)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.needground");
        return null;
    }

    SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
    SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());

    LocalSession session = SpongeWorldEdit.inst().getSession(p);

    Closer closer = Closer.create();
    try {
        ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
        FileInputStream fis = closer.register(new FileInputStream(file));
        BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
        ClipboardReader reader = format.getReader(bis);

        WorldData worldData = ws.getWorldData();
        Clipboard clipboard = reader.read(ws.getWorldData());
        session.setClipboard(new ClipboardHolder(clipboard, worldData));

        Vector bmin = clipboard.getMinimumPoint();
        Vector bmax = clipboard.getMaximumPoint();

        Location<World> min = loc.add(bmin.getX(), bmin.getY(), bmin.getZ());
        Location<World> max = loc.add(bmax.getX(), bmax.getY(), bmax.getZ());

        PlayerRegion leader = new PlayerRegion(p.getUniqueId().toString(), p.getName());
        RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", leader, new HashSet<>(), false);
        if (rb2.ready()) {
            r = rb2.build();
        }

        ClipboardHolder holder = session.getClipboard();

        Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
        Operations.completeLegacy(op);
    } catch (IOException | EmptyClipboardException | IncompleteRegionException | MaxChangedBlocksException e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }

    return r;
}
 
Example #24
Source File: DelegateClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PasteBuilder createPaste(Extent targetExtent, WorldData targetWorldData) {
    return parent.createPaste(targetExtent, targetWorldData);
}
 
Example #25
Source File: DelegateClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WorldData getWorldData() {
    return parent.getWorldData();
}
 
Example #26
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WorldData getWorldData() {
    if (player != null) return player.getWorld().getWorldData();
    return null;
}
 
Example #27
Source File: StructureFormat.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Clipboard read(WorldData data) throws IOException {
    return read(data, UUID.randomUUID());
}
 
Example #28
Source File: NukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WorldData getWorldData() {
    return LegacyWorldData.getInstance();
}
 
Example #29
Source File: IDelegateFaweQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
default void addSchems(Region region, Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
    getQueue().addSchems(region, mask, worldData, clipboards, rarity, rotate);
}
 
Example #30
Source File: MultiClipboardHolder.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public MultiClipboardHolder(WorldData worldData) {
    this(URI.create(""), worldData);
}