Add Page Command #130
@ -22,6 +22,8 @@ package de.steamwar.schematicsystem;
|
||||
import de.steamwar.message.Message;
|
||||
import de.steamwar.schematicsystem.commands.DownloadCommand;
|
||||
import de.steamwar.schematicsystem.commands.SchematicCommand;
|
||||
import de.steamwar.schematicsystem.listener.PlayerEventListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class SchematicSystem extends JavaPlugin {
|
||||
@ -35,6 +37,8 @@ public class SchematicSystem extends JavaPlugin {
|
||||
|
||||
new SchematicCommand();
|
||||
new DownloadCommand();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerEventListener(), this);
|
||||
}
|
||||
|
||||
public static SchematicSystem getInstance() {
|
||||
|
@ -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,19 @@ public class SchematicCommandUtils {
|
||||
inv.setCallback(-999, click -> player.closeInventory());
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void quitPlayer(Player player) {
|
||||
CACHED_LISTS.remove(player);
|
||||
PUBLIC_TOGGLED.remove(player);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@With
|
||||
static class CachedSchematicList {
|
||||
private List<SchematicNode> nodes;
|
||||
private int page;
|
||||
private int maxPage;
|
||||
private SchematicNode parent;
|
||||
private SchematicListBehavior behavior;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package de.steamwar.schematicsystem.listener;
|
||||
|
||||
import de.steamwar.schematicsystem.commands.SchematicCommandUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
SchematicCommandUtils.quitPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren