Skip to content

Commit

Permalink
[Code] Patched bug on team quit. (#65)
Browse files Browse the repository at this point in the history
Le bug il vient pas de moi, ez.
  • Loading branch information
ri1ongithub authored Jul 5, 2024
2 parents 958a40c + 977f86c commit 11b2098
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/fr/communaywen/core/teams/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public boolean addPlayer(UUID player) {
public MethodState removePlayer(UUID player) throws SQLException {
if (players.size() - 1 == 0) {
players.remove(player);
AywenCraftPlugin.getInstance().getTeamManager().removePlayer(player);
if (!AywenCraftPlugin.getInstance().getTeamManager().deleteTeam(this)) {
players.add(player);
return MethodState.INVALID;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/fr/communaywen/core/teams/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ public Team acceptInvite(UUID player) throws SQLException {
return team;
}

public Team removePlayer(UUID player) throws SQLException {
Team team = isInTeam(player);
if (team != null) {
team.removePlayer(player);
try (Connection connection = databaseConnection.getConnection();
PreparedStatement updatePlayers = connection.prepareStatement("UPDATE teams SET players = ? WHERE name = ?")) {

String playerListString = team.getPlayers().stream()
.map(UUID::toString)
.collect(Collectors.joining(","));

updatePlayers.setString(1, playerListString);
updatePlayers.setString(2, team.getName());
updatePlayers.executeUpdate();

if (team.getPlayers().size() == 0) {
deleteTeam(team);
}
}
}
return team;
}

public Team getTeamByName(String name) throws SQLException {
try (Connection connection = databaseConnection.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT owner, players FROM teams WHERE name = ?")) {
Expand Down

0 comments on commit 11b2098

Please sign in to comment.