com.sk89q.worldedit.session.ClipboardHolder Java Examples
The following examples show how to use
com.sk89q.worldedit.session.ClipboardHolder.
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 |
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: SchemGen.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean spawn(PseudoRandom random, int x, int z) throws WorldEditException { mutable.mutX(x); mutable.mutZ(z); int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255); if (y == -1) return false; mutable.mutY(y); if (!mask.test(mutable)) { return false; } mutable.mutY(y + 1); ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); if (randomRotate) { holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform transform = holder.getTransform(); if (transform.isIdentity()) { schematic.paste(extent, mutable, false); } else { schematic.paste(extent, worldData, mutable, false, transform); } mutable.mutY(y); return true; }
Example #3
Source File: SimpleClipboardFloor.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
@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: DefaultFloorRegenerator.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
@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 #5
Source File: ClipboardCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Command( aliases = {"/flip"}, usage = "[<direction>]", desc = "Flip the contents of the clipboard", help = "Flips the contents of the clipboard across the point from which the copy was made.\n", min = 0, max = 1 ) @CommandPermissions("worldedit.clipboard.flip") public void flip(Player player, LocalSession session, @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); AffineTransform transform = new AffineTransform(); transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1)); holder.setTransform(transform.combine(holder.getTransform())); BBC.COMMAND_FLIPPED.send(player); }
Example #6
Source File: ClipboardCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Command( aliases = {"/rotate"}, usage = "<y-axis> [<x-axis>] [<z-axis>]", desc = "Rotate the contents of the clipboard", help = "Non-destructively rotate the contents of the clipboard.\n" + "Angles are provided in degrees and a positive angle will result in a clockwise rotation. " + "Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n" ) @CommandPermissions("worldedit.clipboard.rotate") public void rotate(Player player, LocalSession session, Double yRotate, @Optional Double xRotate, @Optional Double zRotate) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); AffineTransform transform = new AffineTransform(); transform = transform.rotateY(-(yRotate != null ? yRotate : 0)); transform = transform.rotateX(-(xRotate != null ? xRotate : 0)); transform = transform.rotateZ(-(zRotate != null ? zRotate : 0)); holder.setTransform(transform.combine(holder.getTransform())); BBC.COMMAND_ROTATE.send(player); if (!FawePlayer.wrap(player).hasPermission("fawe.tips")) BBC.TIP_FLIP.or(BBC.TIP_DEFORM, BBC.TIP_TRANSFORM).send(player); }
Example #7
Source File: BrushCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Command( aliases = {"clipboard"}, usage = "", desc = "Choose the clipboard brush (Recommended: `/br copypaste`)", help = "Chooses the clipboard brush.\n" + "The -a flag makes it not paste air.\n" + "Without the -p flag, the paste will appear centered at the target location. " + "With the flag, then the paste will appear relative to where you had " + "stood relative to the copied area when you copied it." ) @CommandPermissions("worldedit.brush.clipboard") public BrushSettings clipboardBrush(Player player, LocalSession session, @Switch('a') boolean ignoreAir, @Switch('p') boolean usingOrigin, CommandContext context) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); Vector size = clipboard.getDimensions(); WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockX()); WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockY()); WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockZ()); return set(session, context, new ClipboardBrush(holder, ignoreAir, usingOrigin)); }
Example #8
Source File: LocalSession.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public void addClipboard(@Nonnull MultiClipboardHolder toAppend) { checkNotNull(toAppend); ClipboardHolder existing = getExistingClipboard(); MultiClipboardHolder multi; if (existing instanceof MultiClipboardHolder) { multi = (MultiClipboardHolder) existing; for (ClipboardHolder holder : toAppend.getHolders()) { multi.add(holder); } } else { multi = toAppend; if (existing != null) { multi.add(existing); } } setClipboard(multi); }
Example #9
Source File: RandomFullClipboardPattern.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); AffineTransform transform = new AffineTransform(); if (randomRotate) { transform = transform.rotateY(PseudoRandom.random.random(4) * 90); holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } if (randomFlip) { transform = transform.scale(new Vector(1, 0, 0).multiply(-2).add(1, 1, 1)); } if (!transform.isIdentity()) { holder.setTransform(transform); } Clipboard clipboard = holder.getClipboard(); Schematic schematic = new Schematic(clipboard); Transform newTransform = holder.getTransform(); if (newTransform.isIdentity()) { schematic.paste(extent, setPosition, false); } else { schematic.paste(extent, worldData, setPosition, false, newTransform); } return true; }
Example #10
Source File: SchemVis.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private boolean isSelected(File file) { ClipboardHolder clipboard = player.getSession().getExistingClipboard(); if (clipboard != null) { if (clipboard instanceof URIClipboardHolder) { return ((URIClipboardHolder) clipboard).contains(file.toURI()); } } return false; }
Example #11
Source File: SchematicCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Command( aliases = {"unload"}, usage = "[file]", desc = "Remove a clipboard from your multi-clipboard", min = 1, max = 1 ) @CommandPermissions({"worldedit.clipboard.clear", "worldedit.schematic.clear"}) public void unload(Player player, LocalSession session, String fileName) throws WorldEditException { URI uri; if (fileName.startsWith("file:/") || fileName.startsWith("http://") || fileName.startsWith("https://")) { uri = URI.create(fileName); } else { final LocalConfiguration config = this.worldEdit.getConfiguration(); File working = this.worldEdit.getWorkingDirectoryFile(config.saveDir); File root = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working; uri = new File(root, fileName).toURI(); } boolean removed = false; ClipboardHolder clipboard = session.getClipboard(); if (clipboard instanceof URIClipboardHolder) { URIClipboardHolder identifiable = (URIClipboardHolder) clipboard; if (identifiable.contains(uri)) { if (identifiable instanceof MultiClipboardHolder) { MultiClipboardHolder multi = (MultiClipboardHolder) identifiable; multi.remove(uri); if (multi.getHolders().isEmpty()) session.setClipboard(null); } else { session.setClipboard(null); } BBC.CLIPBOARD_CLEARED.send(player); return; } } BBC.CLIPBOARD_URI_NOT_FOUND.send(player, fileName); }
Example #12
Source File: FawePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * 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 #13
Source File: BrushCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Command( aliases = {"populateschematic", "populateschem", "popschem", "pschem", "ps"}, usage = "<mask> <file|folder|url> [radius=30] [points=5]", desc = "Scatter a schematic on a surface", help = "Chooses the scatter schematic brush.\n" + "The -r flag will apply random rotation", flags = "r", min = 2, max = 4 ) @CommandPermissions("worldedit.brush.populateschematic") public BrushSettings scatterSchemBrush(Player player, EditSession editSession, LocalSession session, Mask mask, String clipboard, @Optional("30") Expression radius, @Optional("50") double density, @Switch('r') boolean rotate, CommandContext context) throws WorldEditException { checkMaxBrushRadius(radius); try { MultiClipboardHolder clipboards = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, player.getWorld().getWorldData(), clipboard, true); if (clipboards == null) { BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard); return null; } List<ClipboardHolder> holders = clipboards.getHolders(); if (holders == null) { BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard); return null; } return set(session, context, new PopulateSchem(mask, holders, (int) density, rotate)) .setSize(radius); } catch (IOException e) { throw new RuntimeException(e); } }
Example #14
Source File: LocalSession.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Sets the clipboard. * <p> * <p>Pass {@code null} to clear the clipboard.</p> * * @param clipboard the clipboard, or null if the clipboard is to be cleared */ public void setClipboard(@Nullable ClipboardHolder clipboard) { if (this.clipboard == clipboard) return; if (this.clipboard != null) { if (clipboard == null || !clipboard.contains(this.clipboard.getClipboard())) { this.clipboard.close(); } } this.clipboard = clipboard; }
Example #15
Source File: SchematicCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private List<File> getFiles(ClipboardHolder clipboard) { List<File> files = new ArrayList<>(); Collection<URI> uris = Collections.emptyList(); if (clipboard instanceof URIClipboardHolder) { uris = ((URIClipboardHolder) clipboard).getURIs(); } for (URI uri : uris) { File file = new File(uri); if (file.exists()) files.add(file); } return files; }
Example #16
Source File: LocalSession.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Gets the clipboard. * * @return clipboard * @throws EmptyClipboardException thrown if no clipboard is set */ public ClipboardHolder getClipboard() throws EmptyClipboardException { if (clipboard == null) { throw new EmptyClipboardException(); } return clipboard; }
Example #17
Source File: PatternCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Command( aliases = {"#fullcopy"}, desc = "Places your full clipboard at each block", usage = "[schem|folder|url=#copy] [rotate=false] [flip=false]", min = 0, max = 2 ) public Pattern fullcopy(Player player, Extent extent, LocalSession session, @Optional("#copy") String location, @Optional("false") boolean rotate, @Optional("false") boolean flip) throws EmptyClipboardException, InputParseException, IOException { List<ClipboardHolder> clipboards; switch (location.toLowerCase()) { case "#copy": case "#clipboard": ClipboardHolder clipboard = session.getExistingClipboard(); if (clipboard == null) { throw new InputParseException("To use #fullcopy, please first copy something to your clipboard"); } if (!rotate && !flip) { return new FullClipboardPattern(extent, clipboard.getClipboard()); } clipboards = Collections.singletonList(clipboard); break; default: MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, player.getWorld().getWorldData(), location, true); clipboards = multi != null ? multi.getHolders() : null; break; } if (clipboards == null) { throw new InputParseException("#fullcopy:<source>"); } return new RandomFullClipboardPattern(extent, player.getWorld().getWorldData(), clipboards, rotate, flip); }
Example #18
Source File: ClipboardCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private void checkPaste(Player player, EditSession editSession, Vector to, ClipboardHolder holder, Clipboard clipboard) { URI uri = null; if (holder instanceof URIClipboardHolder) uri = ((URIClipboardHolder) holder).getURI(clipboard); PasteEvent event = new PasteEvent(player, clipboard, uri, editSession, to); worldEdit.getEventBus().post(event); if (event.isCancelled()) throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL); }
Example #19
Source File: RandomFullClipboardPattern.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
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 #20
Source File: WorldEdit7.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void paste(File file, Location location, Island island) { try { ClipboardFormat format = ClipboardFormats.findByFile(file); ClipboardReader reader = format.getReader(new FileInputStream(file)); Clipboard clipboard = reader.read(); try (EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(location.getWorld()), -1)) { Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(BlockVector3.at(location.getX(), location.getY(), location.getZ())) .copyEntities(true) .ignoreAirBlocks(true) .build(); Operations.complete(operation); } } catch (Exception e) { IridiumSkyblock.getInstance().getLogger().warning("Failed to paste schematic using worldedit"); IridiumSkyblock.schematic.paste(file, location, island); } }
Example #21
Source File: SchemGen.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
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 #22
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void close() { cached = null; for (ClipboardHolder holder : holders) { holder.close(); } }
Example #23
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public Set<URI> getURIs() { Set<URI> set = new HashSet<>(); for (ClipboardHolder holder : getHolders()) { if (holder instanceof URIClipboardHolder) { URI uri = ((URIClipboardHolder) holder).getUri(); if (!uri.toString().isEmpty()) set.add(uri); } } return set; }
Example #24
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public List<ClipboardHolder> getHolders() { ArrayList<ClipboardHolder> holders = new ArrayList<>(); for (ClipboardHolder holder : this.holders) { holders.addAll(holder.getHolders()); } return holders; }
Example #25
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public List<Clipboard> getClipboards() { ArrayList<Clipboard> all = new ArrayList<>(); for (ClipboardHolder holder : holders) { all.addAll(holder.getClipboards()); } return all; }
Example #26
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Deprecated public void add(ClipboardHolder holder) { checkNotNull(holder); if (holder instanceof URIClipboardHolder) { holders.add((URIClipboardHolder) holder); } else { URI uri = URI.create(UUID.randomUUID().toString()); if (!contains(uri)) { holders.add(new URIClipboardHolder(uri, holder.getClipboard(), holder.getWorldData())); } } cached = null; }
Example #27
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean contains(Clipboard clipboard) { for (ClipboardHolder holder : holders) { if (holder.contains(clipboard)) return true; } return false; }
Example #28
Source File: WorldEditHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public static void loadIslandSchematic(final File file, final Location origin, PlayerPerk playerPerk) { log.finer("Trying to load schematic " + file); if (file == null || !file.exists() || !file.canRead()) { LogUtil.log(Level.WARNING, "Unable to load schematic " + file); } boolean noAir = false; BlockVector3 to = BlockVector3.at(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ()); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1); editSession.setFastMode(true); ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(origin); if (region != null) { editSession.setMask(new RegionMask(getRegion(origin.getWorld(), region))); } try { ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file); try (InputStream in = new FileInputStream(file)) { Clipboard clipboard = clipboardFormat.getReader(in).read(); Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(to) .ignoreAirBlocks(noAir) .build(); Operations.completeBlindly(operation); } editSession.flushSession(); } catch (IOException e) { log.log(Level.INFO, "Unable to paste schematic " + file, e); } }
Example #29
Source File: MultiClipboardHolder.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public URI getURI(Clipboard clipboard) { for (ClipboardHolder holder : getHolders()) { if (holder instanceof URIClipboardHolder) { URIClipboardHolder uriHolder = (URIClipboardHolder) holder; URI uri = uriHolder.getURI(clipboard); if (uri != null) return uri; } } return null; }
Example #30
Source File: ScrollClipboard.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean increment(Player player, int amount) { index = MathMan.wrap(index + amount, 0, clipboards.size() - 1); ClipboardHolder clipboard = clipboards.get(index); session.setClipboard(clipboard); return true; }