Skip to content

Commit

Permalink
Fix joining dynamic arenas without a map specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Dec 9, 2024
1 parent 2389b1e commit 1793151
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

public class ArenaCommandExecutor extends BaseCommandExecutor {
private static final CompetitionMap RANDOM_MAP_MARKER = new CompetitionMap() {
Expand Down Expand Up @@ -92,14 +93,21 @@ public void join(Player player, @Argument(name = "map") CompetitionMap map) {

Messages.ARENA_JOINED.send(player, competition.getMap().getName());
} else {
if (map == RANDOM_MAP_MARKER) {
Messages.NO_OPEN_ARENAS.send(player);
List<LiveCompetitionMap> maps = this.arena.getPlugin().getMaps(this.arena);
if (maps.isEmpty()) {
Messages.NO_MAPS_FOR_ARENA.send(player);
return;
}

String mapName = map.getName();
if (map == RANDOM_MAP_MARKER) {
// Select a random map
mapName = maps.get(ThreadLocalRandom.current().nextInt(maps.size())).getName();
}

// Try and create a dynamic competition if possible
this.arena.getPlugin()
.getOrCreateCompetition(this.arena, player, PlayerRole.PLAYING, map.getName())
.getOrCreateCompetition(this.arena, player, PlayerRole.PLAYING, mapName)
.whenComplete((newResult, ex) -> {
if (ex != null) {
Messages.ARENA_ERROR.send(player, ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class Messages {

// Arena messages
public static final Message NO_OPEN_ARENAS = error("arena-no-open-arenas", "There are no open arenas!");
public static final Message NO_MAPS_FOR_ARENA = error("arena-no-open-maps-for-arena", "There arena has no open maps!");
public static final Message NO_MAPS_FOR_ARENA = error("arena-no-open-maps-for-arena", "This arena has no open maps!");
public static final Message NO_RUNNING_COMPETITIONS = error("arena-no-running competitions", "No running competitions.");
public static final Message NO_ARENA_WITH_NAME = error("arena-arena-with-name", "There is no arena with that name!");
public static final Message ARENA_FULL = error("arena-full", "This arena is full!");
Expand Down

0 comments on commit 1793151

Please sign in to comment.