diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 2d4552a..f79e6ec 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -5,9 +5,13 @@ import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.TeamTeilnahme; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; @@ -92,7 +96,7 @@ public class TeamCommand extends BasicCommand { info(player, user, team, args); break; case "list": - list(player); + list(player, args); break; case "event": event(player, user, team, args); @@ -366,15 +370,56 @@ public class TeamCommand extends BasicCommand { } } - private void list(ProxiedPlayer player){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7§lTeamliste"); + private void list(ProxiedPlayer player, String[] args){ + + final int TEAMS_PER_PAGE = 10; + + int page; + if(args.length > 1){ + try{ + page = Integer.parseInt(args[1]); + }catch(NumberFormatException e){ + BungeeCore.send(player, "§cKeine Seitenzahl angegeben"); + return; + } + }else + page = 1; + List all = Team.getAll(); - for(Team tm : all){ + final int lastPage = (all.size() - 1) / 10; + if(page < 1 || page > lastPage){ + BungeeCore.send(player, "§cUngültige Seitenzahl angegeben"); + return; + } + + BungeeCore.send(player, "§7§lTeamliste §7" + page + "§8/§7" + lastPage); + + for(int i = page * TEAMS_PER_PAGE; i < page * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++){ + Team tm = all.get(i); BungeeCore.send(player, "§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + SteamwarUser.get(tm.getTeamLeader()).getUserName() + "§8]", "§7Teaminfo", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel())); } + + TextComponent beforePage = new TextComponent("««"); + if(page > 1){ + 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, "/team list " + (page - 1))); + }else + beforePage.setColor(ChatColor.DARK_GRAY); + + TextComponent nextPage = new TextComponent(" Seite »»"); + if(page < lastPage){ + 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, "/team list " + (page + 1))); + }else + nextPage.setColor(ChatColor.DARK_GRAY); + + beforePage.addExtra(nextPage); + player.sendMessage(beforePage); } private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){