Search Pageination #113
@ -79,7 +79,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, "", false, null, s -> s, integer -> "/schem list " + integer);
|
||||
}
|
||||
|
||||
@Register({"list", "public"})
|
||||
@ -90,7 +90,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, "", true, null, s -> s, integer -> "/schem list public " + integer);
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,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.generateBreadcrumbs(user), node.getOwner() == 0, node, s -> s, integer -> "/schem list " + node.generateBreadcrumbs(user) + " " + integer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +266,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<Predicate<SchematicNode>> predicates = new ArrayList<>();
|
||||
@ -313,19 +313,12 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
|
||||
nodes.forEach(node -> {
|
||||
String br = node.generateBreadcrumbs(user);
|
||||
String displayName = br;
|
||||
for (String s : nameList) {
|
||||
displayName = displayName.replace(s, "§e§l" + s + "§8");
|
||||
renderSchemlist(player, nodes, page, "", userId == 0, null, s -> {
|
||||
for (String ss : nameList) {
|
||||
s = s.replace(ss, "§e§l" + ss + "§7");
|
||||
}
|
||||
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 " + br));
|
||||
|
||||
player.spigot().sendMessage(schematics);
|
||||
});
|
||||
return "§7" + s;
|
||||
}, integer -> "/schem search " + integer + " " + Arrays.stream(query).reduce((s, s2) -> s + " " + s2).get());
|
||||
}
|
||||
|
||||
@Register("download")
|
||||
|
@ -26,6 +26,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;
|
||||
@ -36,6 +38,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;
|
||||
|
||||
@ -77,18 +81,23 @@ public class SchematicCommandUtils {
|
||||
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,
|
||||
List<SchematicNode> nodes,
|
||||
int chunk,
|
||||
SchematicNode parent,
|
||||
SchematicListBehavior behavior) {
|
||||
nodes.sort(Comparator.comparing(SchematicNode::getName));
|
||||
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);
|
||||
}
|
||||
@ -109,7 +118,7 @@ public class SchematicCommandUtils {
|
||||
nodeString.append("§e");
|
||||
}
|
||||
|
||||
nodeString.append(node.getName());
|
||||
nodeString.append(behavior.getRenderHook().apply(node.getName()));
|
||||
|
||||
if (node.isDir()) {
|
||||
nodeString.append("/");
|
||||
@ -123,10 +132,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);
|
||||
@ -144,7 +153,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);
|
||||
}
|
||||
@ -153,7 +162,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);
|
||||
}
|
||||
@ -162,6 +171,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<String> renderHook = s -> s;
|
||||
@Builder.Default private IntFunction<String> pageCommandGen = value -> "/schem list " + value;
|
||||
}
|
||||
|
||||
public static void printSchemInfo(Player player, SchematicNode node) {
|
||||
SteamwarUser user = getUser(player);
|
||||
player.sendMessage("§7Schematic: §e" + node.getName());
|
||||
|
5
pom.xml
5
pom.xml
@ -45,5 +45,10 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
In neuem Issue referenzieren
Einen Benutzer sperren