3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 02:50:05 +01:00

listchunks doesn't need to be a list

Nor does it need to be a string. As long as we can iterate, it should be fine.

This somewhat mitigates OOM from listchunks.
Dieser Commit ist enthalten in:
Jesse Boyd 2019-07-29 05:03:17 +10:00
Ursprung 8aaed49fa6
Commit 3303434d52
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
2 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -94,8 +94,7 @@ public class ChunkCommands {
@ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException {
Set<BlockVector2> chunks = session.getSelection(player.getWorld()).getChunks();
PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%",
chunks.stream().map(BlockVector2::toString).collect(Collectors.toList()));
PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%", chunks);
player.print(paginationBox.create(page));
}

Datei anzeigen

@ -26,6 +26,9 @@ import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
public abstract class PaginationBox extends MessageBox {
@ -128,21 +131,44 @@ public abstract class PaginationBox extends MessageBox {
throw new IllegalStateException("Pagination components must be created with a page");
}
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection lines) {
return new ListPaginationBox(header, pageCommand, lines);
}
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List<String> lines) {
return new ListPaginationBox(header, pageCommand, lines);
}
private static class ListPaginationBox extends PaginationBox {
private final List<String> lines;
private final Collection lines;
private int iterIndex;
private Iterator iterator;
ListPaginationBox(String header, String pageCommand, List<String> lines) {
this(header, pageCommand, (Collection) lines);
}
ListPaginationBox(String header, String pageCommand, Collection lines) {
super(header, pageCommand);
this.lines = lines;
}
@Override
public Component getComponent(int number) {
return TextComponent.of(lines.get(number));
Object obj;
if (lines instanceof List) {
obj = ((List) lines).get(number);
} else {
if (iterator == null || iterIndex > number) {
iterator = lines.iterator();
iterIndex = 0;
}
do {
obj = iterator.next();
iterIndex++;
} while (iterIndex < number);
}
return TextComponent.of(obj.toString());
}
@Override