Java Code Examples for com.sk89q.worldedit.LocalSession#getClipboard()

The following examples show how to use com.sk89q.worldedit.LocalSession#getClipboard() . 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: WorldEditHelper.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@Nullable
private ClipboardHolder getClipboardHolder(@Nullable LocalSession session) {
    if (session != null) {
        try {
            return session.getClipboard();
        } catch (EmptyClipboardException e) {
            // ignore, clipboard is empty
        }
    }
    return null;
}
 
Example 2
Source File: SchematicCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 3
Source File: SchematicCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(aliases = {"move", "m"}, usage = "<directory>", desc = "Move your loaded schematic", help = "Move your currently loaded schematics", min = 1, max = 1)
@CommandPermissions({"worldedit.schematic.move", "worldedit.schematic.move.other"})
public void move(final Player player, final LocalSession session, final CommandContext args) throws WorldEditException, IOException {
    final LocalConfiguration config = this.worldEdit.getConfiguration();
    final File working = this.worldEdit.getWorkingDirectoryFile(config.saveDir);
    final File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
    File destDir = new File(dir, args.getString(0));
    if (!MainUtil.isInSubDirectory(working, destDir)) {
        player.printError("Directory " + destDir + " does not exist!");
        return;
    }
    if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, destDir) && !player.hasPermission("worldedit.schematic.move.other")) {
        BBC.NO_PERM.send(player, "worldedit.schematic.move.other");
        return;
    }
    ClipboardHolder clipboard = session.getClipboard();
    List<File> sources = getFiles(clipboard);
    if (sources.isEmpty()) {
        BBC.SCHEMATIC_NONE.send(player);
        return;
    }
    if (!destDir.exists() && !destDir.mkdirs()) {
        player.printError("Creation of " + destDir + " failed! (check file permissions)");
        return;
    }
    for (File source : sources) {
        File destFile = new File(destDir, source.getName());
        if (destFile.exists()) {
            BBC.SCHEMATIC_MOVE_EXISTS.send(player, destFile);
            continue;
        }
        if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && (!MainUtil.isInSubDirectory(dir, destFile) || !MainUtil.isInSubDirectory(dir, source)) && !player.hasPermission("worldedit.schematic.delete.other")) {
            BBC.SCHEMATIC_MOVE_FAILED.send(player, destFile, BBC.NO_PERM.f("worldedit.schematic.move.other"));
            continue;
        }
        try {
            File cached = new File(source.getParentFile(), "." + source.getName() + ".cached");
            Files.move(source.toPath(), destFile.toPath());
            if (cached.exists()) Files.move(cached.toPath(), destFile.toPath());
            BBC.SCHEMATIC_MOVE_SUCCESS.send(player, source, destFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}