mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 21:56:33 +01:00
//schem list [mine|<filter>] [page=1]
This commit is contained in:
parent
d6d3b51456
commit
36a093eb5f
@ -53,6 +53,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
@ -322,8 +323,9 @@ public class SchematicCommands {
|
|||||||
@Command(
|
@Command(
|
||||||
aliases = {"list", "all", "ls"},
|
aliases = {"list", "all", "ls"},
|
||||||
desc = "List saved schematics",
|
desc = "List saved schematics",
|
||||||
|
usage = "[mine|<filter>] [page=1]",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 2,
|
max = -1,
|
||||||
flags = "dnp",
|
flags = "dnp",
|
||||||
help = "List all schematics in the schematics directory\n" +
|
help = "List all schematics in the schematics directory\n" +
|
||||||
" -d sorts by date, oldest first\n" +
|
" -d sorts by date, oldest first\n" +
|
||||||
@ -334,25 +336,47 @@ public class SchematicCommands {
|
|||||||
public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException {
|
public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException {
|
||||||
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir);
|
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir);
|
||||||
List<File> fileList = new ArrayList<>();
|
List<File> fileList = new ArrayList<>();
|
||||||
|
int len = args.argsLength();
|
||||||
|
List<String> filters = new ArrayList<>();
|
||||||
|
boolean mine = false;
|
||||||
|
if (len > 0) {
|
||||||
|
int max = len;
|
||||||
|
if (MathMan.isInteger(args.getString(len - 1))) {
|
||||||
|
page = args.getInteger(--len);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
switch (args.getString(i).toLowerCase()) {
|
||||||
|
case "mine":
|
||||||
|
mine = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filters.add(args.getString(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) {
|
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) {
|
||||||
File playerDir = new File(dir, actor.getUniqueId().toString());
|
File playerDir = new File(dir, actor.getUniqueId().toString());
|
||||||
if (playerDir.exists()) {
|
if (playerDir.exists()) {
|
||||||
fileList.addAll(allFiles(playerDir, true));
|
fileList.addAll(allFiles(playerDir, true));
|
||||||
}
|
}
|
||||||
fileList.addAll(allFiles(dir, false));
|
if (!mine) {
|
||||||
|
fileList.addAll(allFiles(dir, false));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fileList.addAll(allFiles(dir, true));
|
fileList.addAll(allFiles(dir, true));
|
||||||
}
|
}
|
||||||
|
if (!filters.isEmpty()) {
|
||||||
|
for (String filter : filters) {
|
||||||
|
fileList.removeIf(file -> !file.getPath().contains(filter));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (fileList.isEmpty()) {
|
if (fileList.isEmpty()) {
|
||||||
BBC.SCHEMATIC_NONE.send(actor);
|
BBC.SCHEMATIC_NONE.send(actor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] files = new File[fileList.size()];
|
File[] files = new File[fileList.size()];
|
||||||
fileList.toArray(files);
|
fileList.toArray(files);
|
||||||
if (args.argsLength() > 0 && MathMan.isInteger(args.getString(0))) {
|
|
||||||
page = args.getInteger(0);
|
|
||||||
}
|
|
||||||
int pageCount = files.length / SCHEMATICS_PER_PAGE + 1;
|
int pageCount = files.length / SCHEMATICS_PER_PAGE + 1;
|
||||||
if (page < 1) {
|
if (page < 1) {
|
||||||
BBC.SCHEMATIC_PAGE.send(actor, ">0");
|
BBC.SCHEMATIC_PAGE.send(actor, ">0");
|
||||||
@ -384,7 +408,7 @@ public class SchematicCommands {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
List<String> schematics = listFiles(worldEdit.getConfiguration().saveDir, files);
|
List<String> schematics = listFiles(files, worldEdit.getConfiguration().saveDir, Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? actor.getUniqueId() : null);
|
||||||
int offset = (page - 1) * SCHEMATICS_PER_PAGE;
|
int offset = (page - 1) * SCHEMATICS_PER_PAGE;
|
||||||
|
|
||||||
BBC.SCHEMATIC_LIST.send(actor, page, pageCount);
|
BBC.SCHEMATIC_LIST.send(actor, page, pageCount);
|
||||||
@ -417,22 +441,36 @@ public class SchematicCommands {
|
|||||||
return fileList;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> listFiles(String prefix, File[] files) {
|
private List<String> listFiles(File[] files, String prefix, UUID uuid) {
|
||||||
File dir = worldEdit.getWorkingDirectoryFile(prefix);
|
|
||||||
if (prefix == null) prefix = "";
|
if (prefix == null) prefix = "";
|
||||||
|
File root = worldEdit.getWorkingDirectoryFile(prefix);
|
||||||
|
File dir;
|
||||||
|
if (uuid != null) {
|
||||||
|
dir = new File(root, uuid.toString());
|
||||||
|
} else {
|
||||||
|
dir = root;
|
||||||
|
}
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
StringBuilder build = new StringBuilder();
|
StringBuilder build = new StringBuilder();
|
||||||
|
|
||||||
build.append("\u00a72");
|
build.append("\u00a72");
|
||||||
ClipboardFormat format = ClipboardFormat.findByFile(file);
|
ClipboardFormat format = ClipboardFormat.findByFile(file);
|
||||||
boolean inRoot = file.getParentFile().getName().equals(prefix);
|
// boolean inRoot = file.getParentFile().getName().equals(prefix);
|
||||||
if (inRoot) {
|
// if (inRoot) {
|
||||||
build.append(file.getName());
|
// build.append(file.getName());
|
||||||
} else {
|
// } else {
|
||||||
String relative = dir.toURI().relativize(file.toURI()).getPath();
|
// String relative = dir.toURI().relativize(file.toURI()).getPath();
|
||||||
build.append(relative);
|
// build.append(relative);
|
||||||
|
// }
|
||||||
|
URI relative = dir.toURI().relativize(file.toURI());
|
||||||
|
String name = "";
|
||||||
|
if (relative.isAbsolute()) {
|
||||||
|
relative = root.toURI().relativize(file.toURI());
|
||||||
|
name += "../";
|
||||||
}
|
}
|
||||||
|
name += relative.getPath();
|
||||||
|
build.append(name);
|
||||||
build.append(": ").append(format == null ? "Unknown" : format.name());
|
build.append(": ").append(format == null ? "Unknown" : format.name());
|
||||||
result.add(build.toString());
|
result.add(build.toString());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user