diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java index c091c9e9b..f2cccf0a2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java @@ -4,9 +4,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.function.Consumer; +import java.util.Locale; +import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -80,11 +82,31 @@ public abstract class CommandBase implements ICom } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { return null; } + protected List getMatches(String start, Collection possibleMatches, Function toString) + { + List matches = new ArrayList(); + + for (T possibleMatch : possibleMatches) + { + String str = toString.apply(possibleMatch); + if (str.toLowerCase().startsWith(start.toLowerCase())) + matches.add(str); + } + + return matches; + } + + protected List getMatches(String start, Stream possibleMatches) + { + String lcase = start.toLowerCase(Locale.ENGLISH); + return possibleMatches.filter(str -> str.toLowerCase(Locale.ENGLISH).startsWith(lcase)).collect(Collectors.toList()); + } + protected List getMatches(String start, Collection possibleMatches) { List matches = new ArrayList(); @@ -113,33 +135,22 @@ public abstract class CommandBase implements ICom return matches; } - protected List tabCompletePlayerNames(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + protected List tabCompletePlayerNames(CommandSender sender, String commandLabel, String[] args) { - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace, t -> true); + return tabCompletePlayerNames(sender, commandLabel, args, t -> true); } - protected List tabCompletePlayerNames(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace, Predicate filter) + protected List tabCompletePlayerNames(CommandSender sender, String commandLabel, String[] args, Predicate filter) { if (sender instanceof Player) { if (args.length == 1) { - if (!endsWithSpace) - { - return PlayerSelector.selectPlayers( - UtilLambda.and( - ((Player) sender)::canSee, - player -> player.getName().toLowerCase().startsWith(args[0]), - filter - ) - ).stream().map(Player::getName).collect(Collectors.toList()); - } - } - else if (args.length == 0) - { + String lcase = args[0].toLowerCase(Locale.ENGLISH); return PlayerSelector.selectPlayers( UtilLambda.and( ((Player) sender)::canSee, + player -> player.getName().toLowerCase(Locale.ENGLISH).startsWith(lcase), filter ) ).stream().map(Player::getName).collect(Collectors.toList()); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java index 1f5b17151..dad9e99c4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java @@ -172,14 +172,12 @@ public class CommandCenter implements Listener, IPacketHandler List results = new ArrayList<>(); - boolean endsWithSpace = message.endsWith(" "); - String commandName = message.substring(1); String[] args = new String[0]; if (commandName.contains(" ")) { - String[] splits = commandName.split(" "); + String[] splits = commandName.split(" ", -1); commandName = splits[0]; args = new String[splits.length - 1]; System.arraycopy(splits, 1, args, 0, args.length); @@ -187,7 +185,7 @@ public class CommandCenter implements Listener, IPacketHandler // System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args) + " " + endsWithSpace); - if (endsWithSpace || args.length > 0) + if (args.length > 0) { // System.out.println("Path 1"); ICommand command = Commands.get(commandName.toLowerCase()); @@ -197,7 +195,7 @@ public class CommandCenter implements Listener, IPacketHandler if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), true) || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) { - List tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args, endsWithSpace); + List tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); if (tmpres != null) { results.addAll(tmpres); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/ICommand.java b/Plugins/Mineplex.Core/src/mineplex/core/command/ICommand.java index 5ea9b5db3..f1ba3deaf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/ICommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/ICommand.java @@ -33,5 +33,5 @@ public interface ICommand extends Component CommandCenter.Instance.removeCommand(this); } - List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace); + List onTabComplete(CommandSender sender, String commandLabel, String[] args); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java b/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java index 2b36eba71..2ba7c8c21 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java @@ -1,10 +1,8 @@ package mineplex.core.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; +import java.util.Collection; import java.util.List; -import java.util.Set; +import java.util.Locale; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,27 +13,27 @@ import mineplex.core.common.util.NautHashMap; public abstract class MultiCommandBase extends CommandBase { - protected NautHashMap Commands; + private NautHashMap Commands; public MultiCommandBase(PluginType plugin, Rank rank, String... aliases) { super(plugin, rank, aliases); - Commands = new NautHashMap(); + Commands = new NautHashMap<>(); } public MultiCommandBase(PluginType plugin, Rank rank, Rank[] specificRanks, String... aliases) { super(plugin, rank, specificRanks, aliases); - Commands = new NautHashMap(); + Commands = new NautHashMap<>(); } public void AddCommand(ICommand command) { for (String commandRoot : command.Aliases()) { - Commands.put(commandRoot, command); + Commands.put(commandRoot.toLowerCase(Locale.ENGLISH), command); command.SetCommandCenter(_commandCenter); } } @@ -86,12 +84,11 @@ public abstract class MultiCommandBase extends Co } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { -// System.out.println("Handling MultiCommandBase tab complete " + sender.getName() + " " + commandLabel + " " + Arrays.toString(args) + " " + endsWithSpace); if (args.length > 1) { - String commandName = args[0]; + String commandName = args[0].toLowerCase(Locale.ENGLISH); ICommand command = Commands.get(commandName); @@ -99,44 +96,12 @@ public abstract class MultiCommandBase extends Co { String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, newArgs.length); - return command.onTabComplete(sender, args[0], newArgs, endsWithSpace); + return command.onTabComplete(sender, args[0], newArgs); } } else if (args.length == 1) { - ICommand possibleCommand = Commands.get(args[0]); - // Tab completing a non-existant command, probably trying to tab-complete a command - if (possibleCommand == null) - { - if (!endsWithSpace) - { - Set possibleMatches = new HashSet<>(); - - for (ICommand command : Commands.values()) - { - possibleMatches.addAll(command.Aliases()); - } - - return getMatches(args[0], possibleMatches); - } - } - else if (endsWithSpace) - { - String[] newArgs = new String[args.length - 1]; - System.arraycopy(args, 1, newArgs, 0, newArgs.length); - return possibleCommand.onTabComplete(sender, args[0], newArgs, endsWithSpace); - } - } - else - { - Set possibleMatches = new HashSet<>(); - - for (ICommand command : Commands.values()) - { - possibleMatches.addAll(command.Aliases()); - } - - return new ArrayList<>(possibleMatches); + return getMatches(args[0], Commands.values().stream().map(ICommand::Aliases).flatMap(Collection::stream)); } return null; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java index e75cff044..691c350f0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java @@ -1,10 +1,14 @@ package mineplex.core.friend.command; +import java.util.List; + import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.friend.FriendManager; import mineplex.core.friend.ui.FriendsGUI; import mineplex.core.preferences.Preference; + +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class AddFriend extends CommandBase @@ -39,4 +43,10 @@ public class AddFriend extends CommandBase }); } } + + @Override + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) + { + return tabCompletePlayerNames(sender, commandLabel, args); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageAdminCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageAdminCommand.java index 738bf5e9d..021c87684 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageAdminCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageAdminCommand.java @@ -1,5 +1,8 @@ package mineplex.core.message.commands; +import java.util.List; + +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -28,4 +31,10 @@ public class MessageAdminCommand extends CommandBase Plugin.sendMessage(caller, args[0], message, false, true); } } + + @Override + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) + { + return tabCompletePlayerNames(sender, commandLabel, args); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageCommand.java index 53db5de4e..bdc02920f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/MessageCommand.java @@ -1,5 +1,8 @@ package mineplex.core.message.commands; +import java.util.List; + +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -10,38 +13,38 @@ import mineplex.core.message.MessageManager; public class MessageCommand extends CommandBase { - public MessageCommand(MessageManager plugin) - { - super(plugin, Rank.ALL, "m", "msg", "message", "tell", "t", "w", "whisper", "MSG"); - } + public MessageCommand(MessageManager plugin) + { + super(plugin, Rank.ALL, "m", "msg", "message", "tell", "t", "w", "whisper", "MSG"); + } - @Override - public void Execute(Player caller, String[] args) - { - if (args == null || args.length == 0) - { - Plugin.Help(caller); - } - else - { - if (args.length == 0) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), "Player argument missing.")); - return; - } + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length == 0) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "You didn't specify someone to message!")); + } + else + { + // Parse Message + String message; + if (args.length > 1) + { + message = F.combine(args, 1, null, false); + } + else + { + message = Plugin.GetRandomMessage(); + } - // Parse Message - String message = "Beep!"; - if (args.length > 1) - { - message = F.combine(args, 1, null, false); - } - else - { - message = Plugin.GetRandomMessage(); - } + Plugin.sendMessage(caller, args[0], message, false, false); + } + } - Plugin.sendMessage(caller, args[0], message, false, false); - } - } + @Override + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) + { + return tabCompletePlayerNames(sender, commandLabel, args); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java index a9124403e..0fbaf7373 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/PartyCommand.java @@ -54,7 +54,7 @@ public class PartyCommand extends MultiCommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { @@ -75,7 +75,7 @@ public class PartyCommand extends MultiCommandBase args = newArgs; } } - return super.onTabComplete(sender, commandLabel, args, endsWithSpace); + return super.onTabComplete(sender, commandLabel, args); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyAcceptCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyAcceptCommand.java index 80342f605..349e2fec6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyAcceptCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyAcceptCommand.java @@ -1,19 +1,15 @@ package mineplex.core.party.command.cli; import java.util.List; -import java.util.stream.Collectors; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import mineplex.core.PlayerSelector; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilLambda; import mineplex.core.common.util.UtilPlayer; import mineplex.core.party.InviteData; -import mineplex.core.party.Party; import mineplex.core.party.PartyManager; public class PartyAcceptCommand extends CommandBase @@ -36,22 +32,15 @@ public class PartyAcceptCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { - Player player = (Player) sender; - if (args.length == 1) { - if (!endsWithSpace) - { - return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList())); - } - } - else if (args.length == 0) - { - return Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList()); + Player player = (Player) sender; + + return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyDenyCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyDenyCommand.java index 0379ab470..5d0f52d47 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyDenyCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyDenyCommand.java @@ -32,22 +32,14 @@ public class PartyDenyCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { - Player player = (Player) sender; - if (args.length == 1) { - if (!endsWithSpace) - { - return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList())); - } - } - else if (args.length == 0) - { - return Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList()); + Player player = (Player) sender; + return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList())); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyInviteCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyInviteCommand.java index e2de76429..b2435ca04 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyInviteCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyInviteCommand.java @@ -32,14 +32,14 @@ public class PartyInviteCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; Party party = Plugin.getPartyByPlayer(player); - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace, other -> party == null || !party.isMember(other)); + return tabCompletePlayerNames(sender, commandLabel, args, other -> party == null || !party.isMember(other)); } return null; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyKickCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyKickCommand.java index 8adb22a5d..7612a7325 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyKickCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyKickCommand.java @@ -41,7 +41,7 @@ public class PartyKickCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { @@ -50,7 +50,7 @@ public class PartyKickCommand extends CommandBase if (party != null && party.isOwner(player)) { - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace, other -> other != player && party.isMember(other)); + return tabCompletePlayerNames(sender, commandLabel, args, other -> other != player && party.isMember(other)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyTransferOwnerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyTransferOwnerCommand.java index 53fdac5e6..402b0be83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyTransferOwnerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/cli/PartyTransferOwnerCommand.java @@ -68,7 +68,7 @@ public class PartyTransferOwnerCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (sender instanceof Player) { @@ -77,7 +77,7 @@ public class PartyTransferOwnerCommand extends CommandBase if (party != null && party.isOwner(player)) { - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace, other -> other != player && party.isMember(other)); + return tabCompletePlayerNames(sender, commandLabel, args, other -> other != player && party.isMember(other)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIInviteCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIInviteCommand.java index 335647975..f3832cbad 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIInviteCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIInviteCommand.java @@ -31,8 +31,16 @@ public class PartyGUIInviteCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace); + if (sender instanceof Player) + { + Player player = (Player) sender; + Party party = Plugin.getPartyByPlayer(player); + + return tabCompletePlayerNames(sender, commandLabel, args, other -> party == null || !party.isMember(other)); + } + + return null; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/Command/PunishCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/Command/PunishCommand.java index 1fef95936..1f9166e6e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/Command/PunishCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/Command/PunishCommand.java @@ -141,8 +141,8 @@ public class PunishCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { - return tabCompletePlayerNames(sender, commandLabel, args, endsWithSpace); + return tabCompletePlayerNames(sender, commandLabel, args); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java index 9368c0b29..0365b2441 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java @@ -344,103 +344,92 @@ public class SetCommand extends CommandBase } @Override - public List onTabComplete(CommandSender sender, String commandLabel, String[] args, - boolean endsWithSpace) + public List onTabComplete(CommandSender sender, String commandLabel, String[] args) { if (!(sender instanceof Player) || !Plugin.canPlayerUseGameCmd((Player) sender)) { return null; } - if (args.length == 0) + if (args.length == 1) { - return matchGameType("", true).stream().map(Enum::name).collect(Collectors.toList()); - } - else if (args.length == 1) - { - if (!endsWithSpace) - { - return matchGameType(args[0], true).stream().map(Enum::name).collect(Collectors.toList()); - } + return matchGameType(args[0], true).stream().map(Enum::name).collect(Collectors.toList()); } else { - if (!endsWithSpace) + if (isValid(args)) { - if (isValid(args)) + List matches = matchGameType(args[0], true); + + if (matches.size() == 1) { - List matches = matchGameType(args[0], true); + GameType gameType = matches.get(0); - if (matches.size() == 1) + String gameModeStr = findGameMode(args); + String gameSourceStr = findGameSource(args); + String mapStr = findMap(args); + + String lastArg = args[args.length - 1]; + if (lastArg.startsWith(MODE_PREFIX)) { - GameType gameType = matches.get(0); - - String gameModeStr = findGameMode(args); - String gameSourceStr = findGameSource(args); - String mapStr = findMap(args); - - String lastArg = args[args.length - 1]; - if (lastArg.startsWith(MODE_PREFIX)) + if (gameType.hasGamemodes()) { - if (gameType.hasGamemodes()) - { - return matchGameMode(gameType, gameModeStr, true).stream().map(mode -> MODE_PREFIX + mode.getName().replaceAll(" ", "")).collect(Collectors.toList()); - } + return matchGameMode(gameType, gameModeStr, true).stream().map(mode -> MODE_PREFIX + mode.getName().replaceAll(" ", "")).collect(Collectors.toList()); } - else if (lastArg.startsWith(SOURCE_PREFIX)) + } + else if (lastArg.startsWith(SOURCE_PREFIX)) + { + Class gameClass = gameType.getGameClass(); + if (gameType.hasGamemodes()) { - Class gameClass = gameType.getGameClass(); - if (gameType.hasGamemodes()) - { - // If there are gamemodes, you must provide a gamemode type - if (gameModeStr == null) - return null; - - List matchedModes = matchGameMode(gameType, gameModeStr, true); - - // If more than one mode has been matched, we can't show sources - if (matchedModes.size() != 1) - return null; - - gameClass = matchedModes.get(0).getGameClass(); - } - - return getSources(gameType, gameClass, gameSourceStr, true).stream().map(type -> SOURCE_PREFIX + type.name().replaceAll(" ", "")).collect(Collectors.toList()); - } - else if (lastArg.startsWith(MAP_PREFIX)) - { - Class gameClass = gameType.getGameClass(); - - if (gameType.hasGamemodes()) - { - // If the game has a gamemode, the mode type must be set - if (gameModeStr == null) - return null; - - List matchedModes = matchGameMode(gameType, gameModeStr, true); - - // If more than one mode has been matched, we can't show maps - if (matchedModes.size() != 1) - return null; - - gameClass = matchedModes.get(0).getGameClass(); - } - - // No particular source specified, we'll use all of them - if (gameSourceStr == null) - { - List mapTypes = Arrays.asList(Game.GetWorldHostNames(gameType, gameClass)); - return matchMaps(mapTypes, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList()); - } - - List sources = getSources(gameType, gameClass, gameSourceStr, true); - - // If a source has been provided, it must be valid - if (sources.size() != 1) + // If there are gamemodes, you must provide a gamemode type + if (gameModeStr == null) return null; - return matchMaps(sources, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList()); + List matchedModes = matchGameMode(gameType, gameModeStr, true); + + // If more than one mode has been matched, we can't show sources + if (matchedModes.size() != 1) + return null; + + gameClass = matchedModes.get(0).getGameClass(); } + + return getSources(gameType, gameClass, gameSourceStr, true).stream().map(type -> SOURCE_PREFIX + type.name().replaceAll(" ", "")).collect(Collectors.toList()); + } + else if (lastArg.startsWith(MAP_PREFIX)) + { + Class gameClass = gameType.getGameClass(); + + if (gameType.hasGamemodes()) + { + // If the game has a gamemode, the mode type must be set + if (gameModeStr == null) + return null; + + List matchedModes = matchGameMode(gameType, gameModeStr, true); + + // If more than one mode has been matched, we can't show maps + if (matchedModes.size() != 1) + return null; + + gameClass = matchedModes.get(0).getGameClass(); + } + + // No particular source specified, we'll use all of them + if (gameSourceStr == null) + { + List mapTypes = Arrays.asList(Game.GetWorldHostNames(gameType, gameClass)); + return matchMaps(mapTypes, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList()); + } + + List sources = getSources(gameType, gameClass, gameSourceStr, true); + + // If a source has been provided, it must be valid + if (sources.size() != 1) + return null; + + return matchMaps(sources, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList()); } } }