diff --git a/plugin/src/main/java/org/battleplugins/arena/command/ArenaCommandExecutor.java b/plugin/src/main/java/org/battleplugins/arena/command/ArenaCommandExecutor.java index e11b5d1a..b1d049e0 100644 --- a/plugin/src/main/java/org/battleplugins/arena/command/ArenaCommandExecutor.java +++ b/plugin/src/main/java/org/battleplugins/arena/command/ArenaCommandExecutor.java @@ -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() { @@ -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 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()); diff --git a/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java b/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java index a5a280d3..fe7e780e 100644 --- a/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java +++ b/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java @@ -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!");