Add GameType#getMapNames (to be used later in ListCommand)

This commit is contained in:
Spencer 2017-12-30 17:19:33 -05:00 committed by Alexander Meech
parent 1a1a52c0da
commit 46eadf1b70
2 changed files with 68 additions and 18 deletions

View File

@ -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<String> getMapNames()
{
File mapsFolder = new File("map" + File.separator + GetName());
if (!mapsFolder.exists())
{
return null;
}
List<String> 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;
}
}

View File

@ -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 = "";