Add Page Command #130
@ -85,7 +85,7 @@ public class SchematicCommand extends SWCommand {
|
||||
@Register("list")
|
||||
@Register({"list", "/"})
|
||||
public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
|
||||
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT);
|
||||
createCachedSchemList(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT);
|
||||
}
|
||||
|
||||
@Register({"list", "public"})
|
||||
@ -96,13 +96,13 @@ public class SchematicCommand extends SWCommand {
|
||||
@Register({"list", "public"})
|
||||
@Register({"list", "public", "/"})
|
||||
public void schemListPublic(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
|
||||
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build());
|
||||
createCachedSchemList(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build());
|
||||
}
|
||||
|
||||
@Register("list")
|
||||
public void schemList(Player player, @Validator("isDirValidator") @Mapper("dirMapper") SchematicNode node, @OptionalValue("1") int page) {
|
||||
SteamwarUser user = getUser(player);
|
||||
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), Math.max(page - 1, 0), node, SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build());
|
||||
createCachedSchemList(player, SchematicNode.getSchematicNodeInNode(node), Math.max(page - 1, 0), node, SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build());
|
||||
}
|
||||
|
||||
@Register({"info", "public"})
|
||||
@ -334,12 +334,12 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
renderSchemlist(player, nodes, Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
|
||||
createCachedSchemList(player, nodes, Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
|
||||
for (String ss : nameList) {
|
||||
s = s.replace(ss, "§e§l" + ss + "§7");
|
||||
}
|
||||
return "§7" + s;
|
||||
}).setPageCommandGen(integer -> "/schem search " + integer + " " + Arrays.stream(query).reduce((s, s2) -> s + " " + s2).orElse("")).build());
|
||||
}).build());
|
||||
}
|
||||
|
||||
@Register("download")
|
||||
@ -547,6 +547,11 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Register(value = "page", noTabComplete = true)
|
||||
public void pageCommand(Player player, int page) {
|
||||
cachedSchemList(player, page);
|
||||
}
|
||||
|
||||
private final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper();
|
||||
|
||||
@Mapper("publicMapper")
|
||||
|
@ -28,8 +28,10 @@ import de.steamwar.schematicsystem.AutoCheckResult;
|
||||
import de.steamwar.schematicsystem.CheckSchemType;
|
||||
import de.steamwar.schematicsystem.SchematicSystem;
|
||||
import de.steamwar.sql.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.With;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@ -49,6 +51,8 @@ public class SchematicCommandUtils {
|
||||
public static final int CHUNK_SIZE = 15;
|
||||
private static final List<Player> PUBLIC_TOGGLED = new ArrayList<>();
|
||||
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||
private static final Map<Player, CachedSchematicList> CACHED_LISTS = new HashMap<>();
|
||||
|
||||
|
||||
private SchematicCommandUtils() {
|
||||
}
|
||||
@ -83,6 +87,19 @@ public class SchematicCommandUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void createCachedSchemList(Player player, List<SchematicNode> nodes, int chunk, SchematicNode parent, SchematicListBehavior behavior) {
|
||||
CachedSchematicList cachedSchematicList = new CachedSchematicList(nodes, chunk, (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE), parent, behavior.withPageCommandGen((page) -> "/schematic page " + (page - 1)));
|
||||
CACHED_LISTS.put(player, cachedSchematicList);
|
||||
renderSchemlist(player, cachedSchematicList.nodes, chunk, parent, cachedSchematicList.behavior);
|
||||
}
|
||||
|
||||
public static void cachedSchemList(Player player, int chunk) {
|
||||
CACHED_LISTS.computeIfPresent(player, (p, cachedSchematicList) -> {
|
||||
renderSchemlist(player, cachedSchematicList.nodes, chunk, null, cachedSchematicList.behavior);
|
||||
return cachedSchematicList.withPage(chunk);
|
||||
});
|
||||
}
|
||||
|
||||
public static void renderSchemlist(Player player,
|
||||
List<SchematicNode> nodes,
|
||||
int chunk,
|
||||
@ -168,6 +185,7 @@ public class SchematicCommandUtils {
|
||||
|
||||
@Getter
|
||||
@Builder(setterPrefix = "set")
|
||||
@With
|
||||
public static class SchematicListBehavior {
|
||||
public static final SchematicListBehavior DEFAULT = SchematicListBehavior.builder().build();
|
||||
|
||||
@ -453,4 +471,14 @@ public class SchematicCommandUtils {
|
||||
inv.setCallback(-999, click -> player.closeInventory());
|
||||
inv.open();
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@With
|
||||
static class CachedSchematicList {
|
||||
private List<SchematicNode> nodes;
|
||||
private int page;
|
||||
private int maxPage;
|
||||
private SchematicNode parent;
|
||||
private SchematicListBehavior behavior;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren