From 46eadf1b70acd951bd2e87af41caa6bab5252d8c Mon Sep 17 00:00:00 2001 From: Spencer Date: Sat, 30 Dec 2017 17:19:33 -0500 Subject: [PATCH] Add GameType#getMapNames (to be used later in ListCommand) --- .../src/mineplex/mapparser/GameType.java | 35 +++++++++++++ .../mapparser/command/ListCommand.java | 51 ++++++++++++------- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java index 595a0348b..2a358a9cc 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java @@ -1,5 +1,9 @@ package mineplex.mapparser; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + public enum GameType { // Stand Alone @@ -122,4 +126,35 @@ public enum GameType } return gameType; } + + public List getMapNames() + { + File mapsFolder = new File("map" + File.separator + GetName()); + + if (!mapsFolder.exists()) + { + return null; + } + + List mapNames = new ArrayList<>(); + + File[] files = mapsFolder.listFiles(); + + if (files == null) + { + return null; + } + + for (File file : files) + { + if (!file.isDirectory()) + { + continue; + } + + mapNames.add(file.getName()); + } + + return mapNames; + } } \ No newline at end of file diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java index 3d03dbed5..75aad6395 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ListCommand.java @@ -9,6 +9,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayerBase; import mineplex.mapparser.GameType; +import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; /** @@ -43,31 +44,45 @@ public class ListCommand extends BaseCommand } else if (args.length == 1) { - GameType gameType = null; - if (args[0].equalsIgnoreCase("p")) + String input = args[0]; + + GameType gameType = getGameType(input); + + if (gameType != null) { - gameType = GameType.InProgress; + UtilPlayerBase.message(player, F.main("Parser", "Listing Maps for gametype " + F.elem(gameType.GetName()))); + listMaps(player, gameType, false); + return true; } - else - { - try - { - gameType = GameType.valueOf(args[0]); - } - catch (Exception e) - { - getPlugin().sendValidGameTypes(player); - return true; - } - } - - UtilPlayerBase.message(player, F.main("Parser", "Listing Maps for gametype " + F.elem(gameType.GetName()))); - listMaps(player, gameType, false); + + } return true; } + private GameType getGameType(String input) + { + GameType gameType; + if (input.equalsIgnoreCase("p")) + { + gameType = GameType.InProgress; + } + else + { + try + { + gameType = GameType.valueOf(input); + } + catch (Exception e) + { + return null; + } + } + + return gameType; + } + private boolean listMaps(Player player, GameType gameType, boolean colorSwitch) { String maps = "";