新增队伍列表tui

This commit is contained in:
zhangyuheng 2024-04-11 01:18:52 +08:00
parent 642f8bf51a
commit 02905e30d3
10 changed files with 231 additions and 109 deletions

View File

@ -19,8 +19,9 @@ public final class AC48 extends JavaPlugin {
scheduler = new Scheduler(this);
Objects.requireNonNull(Bukkit.getPluginCommand("ac48")).setExecutor(new Commands());
Bukkit.getPluginManager().registerEvents(new Events(), this);
Metrics metrics = new Metrics(this, 21550);
Metrics metrics = new Metrics(this, 21550);
if (config.getCheckUpdate()) {
giteaReleaseCheck = new GiteaReleaseCheck(this,
"https://ssl.lunadeer.cn:14446",

View File

@ -11,30 +11,31 @@ import java.util.List;
/*
/ac48
/ac48 activate
/ac48 deactivate
/ac48 update
/ac48 sign_up
/ac48 sign_up <队伍名称>
/ac48 vote
/ac48 vote <队伍名称>
/ac48 my_team [page]
/ac48 team_list [page]
/ac48 team_view <队伍名称>
/ac48 material_sponsor [page]
/ac48 my_invitation [page]
/ac48 accept_invitation <邀请ID>
/ac48 reject_invitation <邀请ID>
/ac48 tp <玩家名称>
/ac48 tp_base
/ac48 invite
/ac48 invite_select [page]
/ac48 invite <玩家名称>
/ac48 set_base
/ac48 disband [force]
/ac48 kick <玩家名称>
/ac48 kick <玩家名称> [force]
*/

View File

@ -1,6 +1,9 @@
package cn.lunadeer.ac48;
import cn.lunadeer.ac48.dtos.PlayerDTO;
import cn.lunadeer.ac48.dtos.ThemeDTO;
import cn.lunadeer.ac48.utils.Notification;
import cn.lunadeer.ac48.utils.STUI.Button;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -12,6 +15,13 @@ public class Events implements Listener {
Player bukkitPlayer = event.getPlayer();
PlayerDTO player = PlayerDTO.getFromBukkitPlayer(bukkitPlayer);
player = player.updateName(bukkitPlayer.getName());
// todo
ThemeDTO theme = ThemeDTO.getCurrentActivateTheme();
if (theme == null) return;
Notification.info(bukkitPlayer, "=======================");
Notification.info(bukkitPlayer, "AC48 建筑比赛正在进行中!");
Notification.info(bukkitPlayer, Button.create("点击查看详情", "/ac48"));
Notification.info(bukkitPlayer, "=======================");
}
}

View File

@ -11,6 +11,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class TeamDTO {
/*
@ -63,6 +64,7 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
public List<PlayerDTO> getMembers() {
return members;
}
public Location getBaseLocation() {
return base_location;
}
@ -89,12 +91,13 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
}
}
private static TeamDTO query(String sql) {
private static List<TeamDTO> query(String sql) {
List<TeamDTO> teams = new ArrayList<>();
try (ResultSet rs = Database.query(sql)) {
if (rs == null) return null;
if (rs == null) return teams;
while (rs.next()) {
ThemeDTO theme = ThemeDTO.getCurrentActivateTheme();
if (theme == null) return null;
if (theme == null) return teams;
if (rs.getInt("theme_id") != theme.getId()) {
continue;
}
@ -106,7 +109,7 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
String schematic_base64 = rs.getString("schematic_base64");
String base_world = rs.getString("base_world");
Location base_location = null;
if (base_world != "null") {
if (!Objects.equals(base_world, "null")) {
int base_x = rs.getInt("base_x");
int base_y = rs.getInt("base_y");
int base_z = rs.getInt("base_z");
@ -115,18 +118,26 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
base_location = new Location(world, base_x, base_y, base_z);
}
}
return new TeamDTO(id, name, captain_id, vote_used, vote_gained, schematic_base64, base_location);
TeamDTO team = new TeamDTO(id, name, captain_id, vote_used, vote_gained, schematic_base64, base_location);
teams.add(team);
}
} catch (SQLException e) {
XLogger.err("Database query failed: " + e.getMessage());
XLogger.err("SQL: " + sql);
}
return null;
return teams;
}
public static List<TeamDTO> getByThemeID(Integer id) {
String sql = "SELECT * FROM team WHERE theme_id = " + id + ";";
return query(sql);
}
public static TeamDTO getByTeamID(Integer id) {
String sql = "SELECT * FROM team WHERE id = " + id + ";";
return query(sql);
List<TeamDTO> teams = query(sql);
if (teams.size() != 1) return null;
return teams.get(0);
}
@ -138,7 +149,10 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
PlayerDTO player = PlayerDTO.select(name);
if (player == null) return null;
String sql = "SELECT * FROM team WHERE captain_id = " + player.getId() + ";";
TeamDTO team = query(sql);
List<TeamDTO> teams = query(sql);
TeamDTO team;
if (teams.size() != 1) return null;
team = teams.get(0);
if (team != null) {
return getByTeamID(team.getId());
}
@ -166,7 +180,9 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
"VALUES " +
"(" + theme_id + ", '" + name + "', " + captain_id + ") " +
"RETURNING *;";
return query(sql);
List<TeamDTO> teams = query(sql);
if (teams.size() != 1) return null;
return teams.get(0);
}
public TeamDTO addMember(PlayerDTO player) {
@ -193,17 +209,21 @@ sql = "CREATE TABLE IF NOT EXISTS team (" +
public TeamDTO rename(String name) {
String sql = "UPDATE team SET name = '" + name + "' WHERE id = " + id + " RETURNING *;";
return query(sql);
List<TeamDTO> teams = query(sql);
if (teams.size() != 1) return null;
return teams.get(0);
}
public TeamDTO setBaseLocation(Location location){
public TeamDTO setBaseLocation(Location location) {
String sql = "UPDATE team SET " +
"base_world = '" + location.getWorld().getName() + "', " +
"base_x = " + location.getBlockX() + ", " +
"base_y = " + location.getBlockY() + ", " +
"base_z = " + location.getBlockZ() + " " +
"WHERE id = " + id + " RETURNING *;";
return query(sql);
List<TeamDTO> teams = query(sql);
if (teams.size() != 1) return null;
return teams.get(0);
}
}

View File

@ -13,7 +13,9 @@ import java.util.List;
public class ThemeDTO {
private final Integer id;
private final String name;
private final LocalDateTime signUpBeginTime;
private final LocalDateTime beginTime;
private final LocalDateTime endTime;
private final Integer durationHours;
private final Integer teamVoteLimit;
private final Boolean activated;
@ -29,6 +31,13 @@ public class ThemeDTO {
public LocalDateTime getBeginTime() {
return beginTime;
}
public LocalDateTime getEndTime() {
return endTime;
}
public LocalDateTime getSignUpBeginTime() {
return signUpBeginTime;
}
public Integer getDurationHours() {
return durationHours;
@ -70,6 +79,8 @@ public class ThemeDTO {
this.durationHours = durationHours;
this.teamVoteLimit = teamVoteLimit;
this.activated = activated;
this.signUpBeginTime = beginTime.minusWeeks(1);
this.endTime = beginTime.plusHours(durationHours);
}
public static ThemeDTO createThemeFromConfig() {

View File

@ -1,5 +1,6 @@
package cn.lunadeer.ac48.tuis;
import cn.lunadeer.ac48.dtos.TeamDTO;
import cn.lunadeer.ac48.dtos.ThemeDTO;
import cn.lunadeer.ac48.utils.Notification;
import cn.lunadeer.ac48.utils.STUI.Button;
@ -30,8 +31,8 @@ public class MainView {
return;
}
LocalDateTime begin_time = theme.getBeginTime(); // 活动开始时间
LocalDateTime sign_up_time = begin_time.minusWeeks(1); // 报名开始时间
LocalDateTime end_time = begin_time.plusHours(theme.getDurationHours()); // 活动结束时间
LocalDateTime sign_up_time = theme.getSignUpBeginTime(); // 报名开始时间
LocalDateTime end_time = theme.getEndTime(); // 活动结束时间
LocalDateTime now = LocalDateTime.now(); // 当前时间
Line progress = Line.create().append("活动进度:");
@ -45,7 +46,7 @@ public class MainView {
Line stage2 = Line.create().append(" ").append("2").append("报名参赛");
if (now.isAfter(sign_up_time) && now.isBefore(begin_time)) {
TextComponent signUpButton = Button.create("点击报名", "/ac48 sign_up");
TextComponent signUpButton = Button.create("创建队伍", "/ac48 sign_up");
stage2.append(signUpButton);
} else if (now.isBefore(sign_up_time)) {
stage2.append(Component.text("[预计" + sign_up_time + "开始]", notStartColor));
@ -64,14 +65,20 @@ public class MainView {
Line stage4 = Line.create().append(" ").append("4").append("参观互评");
if (now.isAfter(end_time)) {
TextComponent voteButton = Button.create("点击投票", "/ac48 vote");
TextComponent voteButton = Button.create("前往投票", "/ac48 team_list");
stage4.append(voteButton);
} else {
stage4.append(Component.text("[预计" + end_time + "开始]", notStartColor));
}
Line menu = Line.create().append("功能菜单:");
TextComponent myTeamButton = Button.create("我的队伍", "/ac48 my_team");
TeamDTO team = TeamDTO.getByPlayer(player);
TextComponent myTeamButton;
if (team == null) {
myTeamButton = Button.create("收到的邀请", "/ac48 my_invitation");
} else {
myTeamButton = Button.create("我的队伍", "/ac48 team_view " + team.getName());
}
TextComponent teamListButton = Button.create("队伍列表", "/ac48 team_list");
TextComponent materialSponsorButton = Button.create("材料供应", "/ac48 material_sponsor");
Line menuLine = Line.create().append(" ")

View File

@ -0,0 +1,39 @@
package cn.lunadeer.ac48.tuis;
import cn.lunadeer.ac48.dtos.InvitationDTO;
import cn.lunadeer.ac48.utils.STUI.Button;
import cn.lunadeer.ac48.utils.STUI.Line;
import cn.lunadeer.ac48.utils.STUI.ListView;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.ac48.tuis.Apis.playerOnly;
public class MyInvitation {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
ListView view = ListView.create(10, "/ac48 my_invitation").title("我收到的邀请");
List<InvitationDTO> invitations = InvitationDTO.allInvitations(player);
for (InvitationDTO invitation : invitations) {
TextComponent acceptBtn = Button.createGreen("接受", "/ac48 accept_invitation " + invitation.getId());
TextComponent rejectBtn = Button.createRed("拒绝", "/ac48 reject_invitation " + invitation.getId());
view.add(Line.create()
.append(invitation.getTeam().getName())
.append(acceptBtn)
.append(rejectBtn)
);
}
view.showOn(player, page);
}
}

View File

@ -1,86 +0,0 @@
package cn.lunadeer.ac48.tuis;
import cn.lunadeer.ac48.dtos.InvitationDTO;
import cn.lunadeer.ac48.dtos.PlayerDTO;
import cn.lunadeer.ac48.dtos.TeamDTO;
import cn.lunadeer.ac48.utils.STUI.Button;
import cn.lunadeer.ac48.utils.STUI.Line;
import cn.lunadeer.ac48.utils.STUI.ListView;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.ac48.tuis.Apis.playerOnly;
public class MyTeam {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
ListView view = ListView.create(10, "/ac48 my_team").title("我的队伍");
TeamDTO team = TeamDTO.getByPlayer(player);
if (team == null) {
view.subtitle(Line.create()
.append("你还没有加入任何队伍,以下是你收到的邀请:"));
List<InvitationDTO> invitations = InvitationDTO.allInvitations(player);
for (InvitationDTO invitation : invitations) {
TextComponent acceptBtn = Button.createGreen("接受", "/ac48 accept_invitation " + invitation.getId());
TextComponent rejectBtn = Button.createRed("拒绝", "/ac48 reject_invitation " + invitation.getId());
view.add(Line.create()
.append(invitation.getTeam().getName())
.append(acceptBtn)
.append(rejectBtn)
);
}
} else {
view.subtitle(Line.create()
.append("你可以点击 TP 快速移动到你的队友身边:"));
Line base = Line.create()
.append("队伍名称:")
.append(team.getName())
.append(Button.createGreen("传送到集合点", "/ac48 tp_base"));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
base.append(Button.create("设置集合地点", "/ac48 set_base"));
}
view.add(base);
Line captain = Line.create()
.append("[队长]")
.append(team.getCaptain().getLastKnownName())
.append(Button.createGreen("TP", "/ac48 tp " + team.getCaptain().getLastKnownName()));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
captain.append(Button.createRed("解散队伍", "/ac48 disband"));
}
view.add(captain);
for (PlayerDTO member : team.getMembers()) {
Line memberLine = Line.create()
.append("[队员]")
.append(member.getLastKnownName())
.append(Button.createGreen("TP", "/ac48 tp " + member.getLastKnownName()));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
memberLine.append(Button.createRed("踢出", "/ac48 kick " + member.getLastKnownName()));
} else if (member.getUuid().equals(player.getUniqueId())) {
memberLine.append(Button.createRed("退出队伍", "/ac48 leave"));
}
view.add(memberLine);
}
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
TextComponent inviteBtn = Button.create("邀请玩家", "/ac48 invite");
view.add(Line.create().append(inviteBtn));
}
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,48 @@
package cn.lunadeer.ac48.tuis;
import cn.lunadeer.ac48.dtos.TeamDTO;
import cn.lunadeer.ac48.dtos.ThemeDTO;
import cn.lunadeer.ac48.utils.Notification;
import cn.lunadeer.ac48.utils.STUI.Button;
import cn.lunadeer.ac48.utils.STUI.Line;
import cn.lunadeer.ac48.utils.STUI.ListView;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.time.LocalDateTime;
import java.util.List;
import static cn.lunadeer.ac48.tuis.Apis.playerOnly;
public class TeamList {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
ThemeDTO theme = ThemeDTO.getCurrentActivateTheme();
if (theme == null) {
Notification.error(sender, "当前没有正在进行的比赛活动。");
return;
}
LocalDateTime now = LocalDateTime.now(); // 当前时间
List<TeamDTO> teams = TeamDTO.getByThemeID(theme.getId());
ListView view = ListView.create(10, "/ac48 team_list").title("参赛队伍列表");
for (TeamDTO team : teams) {
Line line = Line.create().append(team.getName())
.append(Button.create("查看", "/ac48 team_view " + team.getName()));
if (now.isAfter(theme.getEndTime())) {
line.append(Button.createGreen("投票", "/ac48 vote " + team.getName()));
}
view.add(line);
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,71 @@
package cn.lunadeer.ac48.tuis;
import cn.lunadeer.ac48.dtos.PlayerDTO;
import cn.lunadeer.ac48.dtos.TeamDTO;
import cn.lunadeer.ac48.utils.Notification;
import cn.lunadeer.ac48.utils.STUI.Button;
import cn.lunadeer.ac48.utils.STUI.Line;
import cn.lunadeer.ac48.utils.STUI.ListView;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.ac48.tuis.Apis.playerOnly;
public class TeamView {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
TeamDTO team = TeamDTO.getByPlayer(player);
if (team == null) {
Notification.error(sender, "你不在任何队伍中。");
return;
}
ListView view = ListView.create(10, "/ac48 team_view").title("队伍名称:" + team.getName());
view.subtitle(Line.create()
.append("你可以点击 TP 快速移动到玩家身边:"));
Line base = Line.create()
.append(Button.createGreen("传送到集合点", "/ac48 tp_base"));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
base.append(Button.create("设置集合地点", "/ac48 set_base"));
}
view.add(base);
Line captain = Line.create()
.append("[队长]")
.append(team.getCaptain().getLastKnownName())
.append(Button.createGreen("TP", "/ac48 tp " + team.getCaptain().getLastKnownName()));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
captain.append(Button.createRed("解散队伍", "/ac48 disband"));
}
view.add(captain);
for (PlayerDTO member : team.getMembers()) {
Line memberLine = Line.create()
.append("[队员]")
.append(member.getLastKnownName())
.append(Button.createGreen("TP", "/ac48 tp " + member.getLastKnownName()));
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
memberLine.append(Button.createRed("踢出", "/ac48 kick " + member.getLastKnownName()));
} else if (member.getUuid().equals(player.getUniqueId())) {
memberLine.append(Button.createRed("退出队伍", "/ac48 leave"));
}
view.add(memberLine);
}
if (team.getCaptain().getUuid().equals(player.getUniqueId())) {
TextComponent inviteBtn = Button.create("邀请玩家", "/ac48 invite_select");
view.add(Line.create().append(inviteBtn));
}
view.showOn(player, page);
}
}