/** * Get an edit session. Every subsequent call returns a new edit session. * Usually you only need to use one edit session. * * @return an edit session */ public EditSession remember() { EditSession editSession = controller.getEditSessionFactory() .getEditSession(player.getWorld(), session.getBlockChangeLimit(), session.getBlockBag(player), player); editSession.enableStandardMode(); editSessions.add(editSession); return editSession; }
/** * Performs a redo * * @param newBlockBag a new block bag * @param player the player * @return whether anything was redone */ public EditSession redo(@Nullable BlockBag newBlockBag, Player player) { checkNotNull(player); if (historyPointer < history.size()) { EditSession editSession = history.get(historyPointer); try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(editSession.getWorld(), -1, newBlockBag, player)) { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); editSession.redo(newEditSession); } ++historyPointer; return editSession; } return null; }
/** * Performs an undo. * * @param newBlockBag a new block bag * @param player the player * @return whether anything was undone */ public EditSession undo(@Nullable BlockBag newBlockBag, Player player) { checkNotNull(player); --historyPointer; if (historyPointer >= 0) { EditSession editSession = history.get(historyPointer); try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(editSession.getWorld(), -1, newBlockBag, player)) { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); editSession.undo(newEditSession); } return editSession; } else { historyPointer = 0; return null; } }
/** * Construct a new edit session. * * @param player the player * @return an edit session */ public EditSession createEditSession(Player player) { checkNotNull(player); BlockBag blockBag = getBlockBag(player); // Create an edit session EditSession editSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(player.isPlayer() ? player.getWorld() : null, getBlockChangeLimit(), blockBag, player); editSession.setFastMode(fastMode); editSession.setReorderMode(reorderMode); Request.request().setEditSession(editSession); editSession.setMask(mask); return editSession; }
/** * Gets the session for the player. * * @param player a player * @return a session */ public EditSession createEditSession(Player player) { com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player); LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer); BlockBag blockBag = session.getBlockBag(wePlayer); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory() .getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer); editSession.enableStandardMode(); return editSession; }
@Override public void paste() { try { EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(SpongeWorldEdit.inst().getWorld(world), -1); editSession.enableQueue(); clipboard.place(editSession, origin, false); editSession.flushQueue(); } catch (MaxChangedBlocksException e) { // is never thrown because we are on infinite mode } }
@Override public void copy() { EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(SpongeWorldEdit.inst().getWorld(world), -1); editSession.enableQueue(); clipboard.copy(editSession); editSession.flushQueue(); } }
@Override public void run(String playerID) throws QuestRuntimeException { try { Location location = loc.getLocation(playerID); SchematicFormat schematic = SchematicFormat.getFormat(file); CuboidClipboard clipboard = schematic.load(file); BukkitWorld world = new BukkitWorld(location.getWorld()); EditSession editSession = we.getWorldEdit().getEditSessionFactory().getEditSession(world, 64*64*64); Vector newOrigin = BukkitUtil.toVector(location); clipboard.paste(editSession, newOrigin, noAir); } catch (DataException | IOException | MaxChangedBlocksException e) { Debug.error("Error while pasting a schematic: " + e.getMessage()); } }
@Override public void clear() { try { CuboidRegion region = new CuboidRegion(origin, origin.add(size.getX() - 1, size.getY() - 1, size.getZ() - 1)); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(SpongeWorldEdit.inst().getWorld(world), -1); editSession.enableQueue(); editSession.setBlocks(region, new BaseBlock(0)); editSession.flushQueue(); } catch (MaxChangedBlocksException e) { // is never thrown } }
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) { FunnyGuildsLogger.exception(e); return false; } }