diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 67fb20e..1260878 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -84,7 +84,7 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) 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"}) @@ -95,7 +95,7 @@ public class SchematicCommand extends SWCommand { @Register({"list", "public"}) @Register({"list", "public", "/"}) 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()) { player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); } 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") - 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); int userId = user.getId(); List> predicates = new ArrayList<>(); @@ -349,23 +349,12 @@ public class SchematicCommand extends SWCommand { } return true; }); - player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); - int finalUserId = userId; - nodes.forEach(node -> { - String br = node.generateBreadcrumbs(user); - String displayName = br; - if (!nameList.isEmpty()) { - displayName = "§8" + br; + renderSchemlist(player, nodes, page, null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> { + for (String ss : nameList) { + s = s.replace(ss, "§e§l" + ss + "§7"); } - for (String s : nameList) { - displayName = displayName.replace(s, "§e§l" + s + "§8"); - } - 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); - }); + return "§7" + s; + }).setPageCommandGen(integer -> "/schem search " + integer + " " + Arrays.stream(query).reduce((s, s2) -> s + " " + s2).orElse("")).build()); } @Register("download") diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 0e873c3..8f35220 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -27,6 +27,8 @@ import de.steamwar.schematicsystem.AutoCheckResult; import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; +import lombok.Builder; +import lombok.Getter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -37,6 +39,8 @@ import org.bukkit.entity.Player; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.function.IntFunction; +import java.util.function.UnaryOperator; import java.util.logging.Level; import java.util.stream.Collectors; @@ -79,18 +83,22 @@ public class SchematicCommandUtils { return false; } - public static void renderSchemlist(Player player, List nodes, int chunk, String breadcrumbs, boolean isPublic, SchematicNode parent) { - nodes.sort(Comparator.comparing(SchematicNode::getName)); + public static void renderSchemlist(Player player, + List nodes, + int chunk, + SchematicNode parent, + SchematicListBehavior behavior) { SteamwarUser user = getUser(player); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); + String breadcrumbs = parent == null ? "" : parent.generateBreadcrumbs(user); player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty() ? "/" : breadcrumbs)); if (!breadcrumbs.isEmpty()) { TextComponent back = new TextComponent("§e../"); 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.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); } @@ -111,7 +119,7 @@ public class SchematicCommandUtils { nodeString.append("§e"); } - nodeString.append(node.getName()); + nodeString.append(behavior.getRenderHook().apply(node.getName())); if (node.isDir()) { nodeString.append("/"); @@ -125,10 +133,10 @@ public class SchematicCommandUtils { if (node.isDir()) { 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 { 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); @@ -146,7 +154,7 @@ public class SchematicCommandUtils { if (chunk > 0) { beforePage.setColor(ChatColor.YELLOW); 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 { beforePage.setColor(ChatColor.RED); } @@ -155,7 +163,7 @@ public class SchematicCommandUtils { if (chunk < pageCount - 1) { nextPage.setColor(ChatColor.YELLOW); 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 { nextPage.setColor(ChatColor.RED); } @@ -164,6 +172,17 @@ public class SchematicCommandUtils { 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 renderHook = s -> s; + @Builder.Default private IntFunction pageCommandGen = value -> "/schem list " + value; + } + public static void printSchemInfo(Player player, SchematicNode node) { SteamwarUser user = getUser(player); player.sendMessage("§7Schematic: §e" + node.getName());