geforkt von Mirrors/FastAsyncWorldEdit
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:
Ursprung
8aaed49fa6
Commit
3303434d52
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren