13
0

Merge pull request 'Search Pageination' (#113) from pagination into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #113
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Chaoscaot 2022-02-24 22:20:31 +01:00
Commit 307036ac82
2 geänderte Dateien mit 36 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -84,7 +84,7 @@ public class SchematicCommand extends SWCommand {
@Register("list") @Register("list")
@Register({"list", "/"}) @Register({"list", "/"})
public void schemList(Player player, @OptionalValue("0") int page) { public void schemList(Player player, @OptionalValue("0") int page) {
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), page, "", false, null); renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), page, null, SchematicListBehavior.DEFAULT);
} }
@Register({"list", "public"}) @Register({"list", "public"})
@ -95,7 +95,7 @@ public class SchematicCommand extends SWCommand {
@Register({"list", "public"}) @Register({"list", "public"})
@Register({"list", "public", "/"}) @Register({"list", "public", "/"})
public void schemListPublic(Player player, @OptionalValue("0") int page) { public void schemListPublic(Player player, @OptionalValue("0") int page) {
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), page, "", true, null); renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), page, null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build());
} }
@ -110,7 +110,7 @@ public class SchematicCommand extends SWCommand {
if (!node.isDir()) { if (!node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner");
} else { } else {
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner() == 0, node); renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node, SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build());
} }
} }
@ -287,7 +287,7 @@ public class SchematicCommand extends SWCommand {
} }
@Register("search") @Register("search")
public void schemSearch(Player player, @Mapper("searchMapper") String... query) { public void schemSearch(Player player, @OptionalValue("0") int page, @Mapper("searchMapper") String... query) {
SteamwarUser user = getUser(player); SteamwarUser user = getUser(player);
int userId = user.getId(); int userId = user.getId();
List<Predicate<SchematicNode>> predicates = new ArrayList<>(); List<Predicate<SchematicNode>> predicates = new ArrayList<>();
@ -349,23 +349,12 @@ public class SchematicCommand extends SWCommand {
} }
return true; return true;
}); });
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); renderSchemlist(player, nodes, page, null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
int finalUserId = userId; for (String ss : nameList) {
nodes.forEach(node -> { s = s.replace(ss, "§e§l" + ss + "§7");
String br = node.generateBreadcrumbs(user);
String displayName = br;
if (!nameList.isEmpty()) {
displayName = "§8" + br;
} }
for (String s : nameList) { return "§7" + s;
displayName = displayName.replace(s, "§e§l" + s + "§8"); }).setPageCommandGen(integer -> "/schem search " + integer + " " + Arrays.stream(query).reduce((s, s2) -> s + " " + s2).orElse("")).build());
}
TextComponent schematics = new TextComponent("§7" + displayName);
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (finalUserId == 0 ? "public ":"") + br));
player.spigot().sendMessage(schematics);
});
} }
@Register("download") @Register("download")

Datei anzeigen

@ -27,6 +27,8 @@ import de.steamwar.schematicsystem.AutoCheckResult;
import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import lombok.Builder;
import lombok.Getter;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
@ -37,6 +39,8 @@ import org.bukkit.entity.Player;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.IntFunction;
import java.util.function.UnaryOperator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -79,18 +83,22 @@ public class SchematicCommandUtils {
return false; return false;
} }
public static void renderSchemlist(Player player, List<SchematicNode> nodes, int chunk, String breadcrumbs, boolean isPublic, SchematicNode parent) { public static void renderSchemlist(Player player,
nodes.sort(Comparator.comparing(SchematicNode::getName)); List<SchematicNode> nodes,
int chunk,
SchematicNode parent,
SchematicListBehavior behavior) {
SteamwarUser user = getUser(player); SteamwarUser user = getUser(player);
int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE);
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
String breadcrumbs = parent == null ? "" : parent.generateBreadcrumbs(user);
player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty() ? "/" : breadcrumbs)); player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty() ? "/" : breadcrumbs));
if (!breadcrumbs.isEmpty()) { if (!breadcrumbs.isEmpty()) {
TextComponent back = new TextComponent("§e../"); TextComponent back = new TextComponent("§e../");
String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/"))); String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/")));
back.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück gehen" + str).create())); back.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück gehen" + str).create()));
back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + str)); back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public" : "") + " " + str));
player.spigot().sendMessage(back); player.spigot().sendMessage(back);
} }
@ -111,7 +119,7 @@ public class SchematicCommandUtils {
nodeString.append("§e"); nodeString.append("§e");
} }
nodeString.append(node.getName()); nodeString.append(behavior.getRenderHook().apply(node.getName()));
if (node.isDir()) { if (node.isDir()) {
nodeString.append("/"); nodeString.append("/");
@ -125,10 +133,10 @@ public class SchematicCommandUtils {
if (node.isDir()) { if (node.isDir()) {
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eOrdner anzeigen").create())); schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eOrdner anzeigen").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + node.getName() + "/")); schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public" : "") + " " + breadcrumbs + node.getName() + "/"));
} else { } else {
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create())); schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (isPublic ? "public" : "") + " " + breadcrumbs + node.getName())); schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (behavior.isPublics() ? "public" : "") + " " + breadcrumbs + node.getName()));
} }
player.spigot().sendMessage(schematics); player.spigot().sendMessage(schematics);
@ -146,7 +154,7 @@ public class SchematicCommandUtils {
if (chunk > 0) { if (chunk > 0) {
beforePage.setColor(ChatColor.YELLOW); beforePage.setColor(ChatColor.YELLOW);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create())); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1))); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, behavior.getPageCommandGen().apply(chunk - 1)));
} else { } else {
beforePage.setColor(ChatColor.RED); beforePage.setColor(ChatColor.RED);
} }
@ -155,7 +163,7 @@ public class SchematicCommandUtils {
if (chunk < pageCount - 1) { if (chunk < pageCount - 1) {
nextPage.setColor(ChatColor.YELLOW); nextPage.setColor(ChatColor.YELLOW);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create())); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1))); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, behavior.getPageCommandGen().apply(chunk + 1)));
} else { } else {
nextPage.setColor(ChatColor.RED); nextPage.setColor(ChatColor.RED);
} }
@ -164,6 +172,17 @@ public class SchematicCommandUtils {
player.spigot().sendMessage(beforePage); player.spigot().sendMessage(beforePage);
} }
@Getter
@Builder(setterPrefix = "set")
public static class SchematicListBehavior {
public static final SchematicListBehavior DEFAULT = SchematicListBehavior.builder().build();
@Builder.Default private boolean showPath = true;
@Builder.Default private boolean publics = false;
@Builder.Default private UnaryOperator<String> renderHook = s -> s;
@Builder.Default private IntFunction<String> pageCommandGen = value -> "/schem list " + value;
}
public static void printSchemInfo(Player player, SchematicNode node) { public static void printSchemInfo(Player player, SchematicNode node) {
SteamwarUser user = getUser(player); SteamwarUser user = getUser(player);
player.sendMessage("§7Schematic: §e" + node.getName()); player.sendMessage("§7Schematic: §e" + node.getName());