Archiviert
1
0

Split team list into several pages

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-05-23 11:49:44 +02:00
Ursprung 01dcd0152e
Commit fae81c9c4a

Datei anzeigen

@ -5,9 +5,13 @@ import de.steamwar.bungeecore.sql.Event;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.Team;
import de.steamwar.bungeecore.sql.TeamTeilnahme; 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.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
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.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.time.Instant; import java.time.Instant;
@ -92,7 +96,7 @@ public class TeamCommand extends BasicCommand {
info(player, user, team, args); info(player, user, team, args);
break; break;
case "list": case "list":
list(player); list(player, args);
break; break;
case "event": case "event":
event(player, user, team, args); event(player, user, team, args);
@ -366,15 +370,56 @@ public class TeamCommand extends BasicCommand {
} }
} }
private void list(ProxiedPlayer player){ private void list(ProxiedPlayer player, String[] args){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7§lTeamliste");
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<Team> all = Team.getAll(); List<Team> 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, BungeeCore.send(player,
"§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + SteamwarUser.get(tm.getTeamLeader()).getUserName() + "§8]", "§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + SteamwarUser.get(tm.getTeamLeader()).getUserName() + "§8]",
"§7Teaminfo", "§7Teaminfo",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel())); 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){ private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){