Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java
xXVevzZXx 6e9b0e4fa5 Merge branch 'develop' of github.com:Mineplex-LLC/Minecraft-PC into feature/game-variants
# Conflicts:
#	Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java
2016-05-17 14:41:17 +02:00

118 lines
2.7 KiB
Java

package nautilus.game.arcade.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SetCommand extends CommandBase<ArcadeManager>
{
public SetCommand(ArcadeManager plugin)
{
super(plugin, Rank.ALL, "set");
}
@Override
public void Execute(Player caller, String[] args)
{
if (Plugin.GetGame() == null)
return;
if (!Plugin.canPlayerUseGameCmd(caller))
{
return;
}
if (args.length == 0)
{
caller.sendMessage(F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN));
return;
}
String game = args[0].toLowerCase();
if (args.length >= 2)
{
String map = "";
String source = game;
Plugin.GetGameCreationManager().MapSource = game;
for(String token : args)
{
if(token.startsWith("@s"))
{
Plugin.GetGameCreationManager().MapSource = token.substring(1);
source = token.substring(2);
}
else if(token.startsWith("@m"))
{
Plugin.GetGameCreationManager().MapPref = token.substring(1);
map = token.substring(2);
}
else if(token.startsWith("@e"))
{
Plugin.GetGameCreationManager().ModePref = token.substring(2);
}
}
UtilPlayer.message(caller, C.cAqua + C.Bold + "Map Preference: " + ChatColor.RESET + source + ":" + map);
}
//Parse Game
ArrayList<GameType> matches = new ArrayList<>();
for (GameType type : GameType.values())
{
if (type.toString().toLowerCase().equals(game))
{
matches.clear();
matches.add(type);
break;
}
if (type.toString().toLowerCase().contains(game))
{
matches.add(type);
}
}
if (matches.size() == 0)
{
caller.sendMessage("No results for: " + game);
return;
}
if (matches.size() > 1)
{
caller.sendMessage("Matched multiple games;");
for (GameType cur : matches)
caller.sendMessage(cur.toString());
return;
}
GameType type = matches.get(0);
Plugin.GetGame().setGame(type, caller, true);
if(Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing"))
{
Plugin.GetGameList().clear();
Plugin.GetGameList().add(type);
}
}
@Override
public List<String> onTabComplete(CommandSender sender, String commandLabel, String[] args)
{
String lastArg = args[args.length - 1];
return getMatches(lastArg, GameType.values());
}
}