use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method list.
@Command(name = "list", desc = "List your history")
@CommandPermissions("worldedit.history.list")
public void list(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) {
int index = session.getHistoryIndex();
List<Supplier<? extends ChangeSet>> history = Lists.transform(session.getHistory(), (Function<ChangeSet, Supplier<ChangeSet>>) input -> () -> input);
Location origin = player.getLocation();
String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
Reference<PaginationBox> cached = player.getMeta(pageCommand);
PaginationBox pages = cached == null ? null : cached.get();
if (page == null || pages == null) {
pages = list(database, pageCommand, history, origin.toBlockPoint());
page = 1;
}
player.print(pages.create(page));
}
use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.
the class BiomeCommands method biomeList.
@Command(name = "biomelist", aliases = { "biomels", "/biomelist", "/listbiomes" }, desc = "Gets all biomes available.")
@CommandPermissions("worldedit.biome.list")
public void biomeList(Actor actor, @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) {
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%", BiomeType.REGISTRY.values().stream().map(biomeType -> TextComponent.builder().append(biomeType.getId()).append(" (").append(biomeRegistry.getRichName(biomeType)).append(")").build()).collect(Collectors.toList()));
return paginationBox.create(page);
}, (Component) null);
}
use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.
the class SchematicCommands method list.
@Command(name = "list", aliases = { "all", "ls" }, desc = "List saved schematics", descFooter = "Note: Format is not fully verified until loading.")
@CommandPermissions("worldedit.schematic.list")
public void list(Actor actor, LocalSession session, @ArgFlag(name = 'p', desc = "Page to view.", def = "1") int page, @Switch(name = 'd', desc = "Sort by date, oldest first") boolean oldFirst, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "") String formatName, @Arg(name = "filter", desc = "Filter for schematics", def = "all") String filter, Arguments arguments) throws WorldEditException {
if (oldFirst && newFirst) {
throw new StopExecutionException(Caption.of("worldedit.schematic.sorting-old-new"));
}
// FAWE start
String pageCommand = "/" + arguments.get();
LocalConfiguration config = worldEdit.getConfiguration();
File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
String schemCmd = "//schematic";
String loadSingle = schemCmd + " load";
String loadMulti = schemCmd + " loadall";
String unload = schemCmd + " unload";
String delete = schemCmd + " delete";
String list = schemCmd + " list";
String showCmd = schemCmd + " show";
List<String> args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" "));
URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard());
final boolean hasShow = false;
// If player forgot -p argument
boolean playerFolder = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
UUID uuid = playerFolder ? actor.getUniqueId() : null;
List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
Function<URI, Boolean> isLoaded = multi == null ? f -> false : multi::contains;
List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> {
TextComponentProducer msg = new TextComponentProducer();
msg.append(Caption.of("worldedit.schematic.dash.symbol"));
if (loaded) {
msg.append(Caption.of("worldedit.schematic.minus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.unload"))));
} else {
msg.append(Caption.of("worldedit.schematic.plus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.clipboard"))));
}
if (type != UtilityCommands.URIType.DIRECTORY) {
msg.append(Caption.of("worldedit.schematic.x.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete"))));
} else if (hasShow) {
msg.append(Caption.of("worldedit.schematic.0.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.visualize"))));
}
TextComponent msgElem = TextComponent.of(name);
if (type != UtilityCommands.URIType.DIRECTORY) {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.load")));
} else {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.list")));
}
msg.append(msgElem);
if (type == UtilityCommands.URIType.FILE) {
long filesize = 0;
try {
filesize = Files.size(Paths.get(dir.getAbsolutePath() + File.separator + (playerFolder ? (uuid.toString() + File.separator) : "") + path));
} catch (IOException e) {
e.printStackTrace();
}
TextComponent sizeElem = TextComponent.of(String.format(" (%.1f kb)", filesize / 1000.0), TextColor.GRAY);
msg.append(sizeElem);
}
return msg.create();
});
long totalBytes = 0;
File parentDir = new File(dir.getAbsolutePath() + (playerFolder ? File.separator + uuid.toString() : ""));
try {
List<File> toAddUp = getFiles(parentDir, null, null);
if (toAddUp != null && toAddUp.size() != 0) {
for (File schem : toAddUp) {
if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) {
totalBytes += Files.size(Paths.get(schem.getAbsolutePath()));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
String headerBytesElem = String.format("%.1fkb", totalBytes / 1000.0);
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
headerBytesElem += String.format(" / %dkb", Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT);
}
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
String fullHeader = "| My Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
} else {
String fullHeader = "| Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
}
// FAWE end
}
use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method find.
@Command(name = "find", aliases = { "inspect", "search", "near" }, desc = "Find nearby edits")
@CommandPermissions("worldedit.history.find")
public synchronized void find(Player player, World world, RollbackDatabase database, Arguments arguments, @ArgFlag(name = 'u', def = "", desc = "String user") UUID other, @ArgFlag(name = 'r', def = "0", desc = "radius") @Range(from = 0, to = Integer.MAX_VALUE) Integer radius, @ArgFlag(name = 't', desc = "Time e.g. 20s", def = "0") @Time Long timeDiff, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws WorldEditException {
if (!Settings.settings().HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with //history import )"));
return;
}
if (other == null && radius == 0 && timeDiff == 0) {
throw new InsufficientArgumentsException(Caption.of("fawe.error.invalid-user"));
}
checkCommandArgument(radius > 0, Caption.of("fawe.error.radius-too-small"));
checkCommandArgument(timeDiff > 0, Caption.of("fawe.error.time-too-less"));
Location origin = player.getLocation();
String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
Reference<List<Supplier<? extends ChangeSet>>> cached = player.getMeta(pageCommand);
List<Supplier<? extends ChangeSet>> history = cached == null ? null : cached.get();
if (page == null || history == null) {
if (other == null) {
other = player.getUniqueId();
}
if (!other.equals(player.getUniqueId())) {
player.checkPermission("worldedit.history.undo.other");
}
if (other == Identifiable.EVERYONE) {
other = null;
}
BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
bot = bot.clampY(world.getMinY(), world.getMaxY());
top = top.clampY(world.getMinY(), world.getMaxY());
long minTime = System.currentTimeMillis() - timeDiff;
Iterable<Supplier<RollbackOptimizedHistory>> edits = database.getEdits(other, minTime, bot, top, false, false);
history = Lists.newArrayList(edits);
player.setMeta(pageCommand, new SoftReference<>(history));
page = 1;
}
PaginationBox box = list(database, pageCommand, history, origin.toBlockPoint());
player.print(box.create(page));
}
use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method distr.
@Command(name = "distr", aliases = { "distribution" }, desc = "View block distribution for an edit")
@CommandPermissions("worldedit.history.distr")
public void distr(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws ExecutionException, InterruptedException {
String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
Reference<PaginationBox> cached = player.getMeta(pageCommand);
PaginationBox pages = cached == null ? null : cached.get();
if (page == null || pages == null) {
RollbackOptimizedHistory edit = database.getEdit(other, index).get();
SimpleChangeSetSummary summary = edit.summarize(RegionWrapper.GLOBAL(), false);
if (summary != null) {
List<Countable<BlockState>> distr = summary.getBlockDistributionWithData();
SelectionCommands.BlockDistributionResult distrPages = new SelectionCommands.BlockDistributionResult(distr, true, pageCommand);
pages = new PaginationBox.MergedPaginationBox("Block Distribution", pageCommand, pages, distrPages);
player.setMeta(pageCommand, new SoftReference<>(pages));
}
page = 1;
}
if (pages == null) {
player.print(Caption.of("fawe.worldedit.history.distr.summary_null"));
} else {
player.print(pages.create(page));
}
}
Aggregations