Skip to content

Commit

Permalink
feat: use the bungee random game selection algorithm for /bw join w…
Browse files Browse the repository at this point in the history
…ithout arguments to make it more random

The only difference is that it remembers all the games with the max player count and then randomly chooses one of them, instead of doing it deterministically
  • Loading branch information
Misat11 committed Dec 31, 2024
1 parent 1da422f commit 14dd90c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions plugin/src/main/java/org/screamingsandals/bedwars/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,16 +802,20 @@ public org.screamingsandals.bedwars.api.game.Game getRandomWaitingGameForBungeeM
return;
}

if (game.getConnectedPlayers().size() >= game.getMaxPlayers()) {
return;
}

availableGames.computeIfAbsent(game.getConnectedPlayers().size(), ArrayList::new).add(game);
});

if (availableGames.isEmpty()) {
return null;
}

List<Game> gamesWithMinimumPlayers = availableGames.lastEntry().getValue();
List<Game> gamesWithMaximumPlayers = availableGames.lastEntry().getValue();

return gamesWithMinimumPlayers.get(MiscUtils.randInt(0, gamesWithMinimumPlayers.size() - 1));
return gamesWithMaximumPlayers.get(MiscUtils.randInt(0, gamesWithMaximumPlayers.size() - 1));
}

public org.screamingsandals.bedwars.api.game.Game getFirstRunningGame() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean execute(CommandSender sender, List<String> args) {
return true;
}

Game game = Main.getInstance().getGameWithHighestPlayers(); // prioritizing player count - scorp
Game game = Main.getInstance().getRandomWaitingGameForBungeeMode();
if (game == null) {
player.sendMessage(i18n("there_is_no_empty_game"));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean execute(CommandSender sender, List<String> args) {
player.sendMessage(i18n("no_arena_found"));
}
} else {
final Game game = Main.getInstance().getGameWithHighestPlayers();
final Game game = Main.getInstance().getRandomWaitingGameForBungeeMode();
if (game != null) {
game.joinToGame(player);
return true;
Expand Down

0 comments on commit 14dd90c

Please sign in to comment.