Fixes infinite error with commit f14676f.

The lambdas were missing the input argument to the execute method so
were calling the parent's execute method.
This commit is contained in:
Tastybento 2018-02-19 11:01:48 -08:00
parent 382f195015
commit 25b4f674bb
2 changed files with 18 additions and 11 deletions

View File

@ -6,11 +6,13 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
@ -271,16 +273,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @return CompositeCommand or null if none found
*/
public Optional<CompositeCommand> getSubCommand(String label) {
for (Map.Entry<String, CompositeCommand> entry : subCommands.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) {
return Optional.of(subCommands.get(label));
}
if (subCommands.containsKey(label.toLowerCase())) {
return Optional.ofNullable(subCommands.get(label));
}
// Try aliases
for (Map.Entry<String, CompositeCommand> entry : subCommandAliases.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) {
return Optional.of(subCommandAliases.get(label));
}
if (subCommandAliases.containsKey(label.toLowerCase())) {
return Optional.ofNullable(subCommandAliases.get(label));
}
return Optional.empty();
}

View File

@ -6,7 +6,14 @@ import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.island.*;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand;
import us.tastybento.bskyblock.commands.island.IslandCreateCommand;
import us.tastybento.bskyblock.commands.island.IslandGoCommand;
import us.tastybento.bskyblock.commands.island.IslandResetCommand;
import us.tastybento.bskyblock.commands.island.IslandResetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSethomeCommand;
import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSettingsCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
public class IslandCommand extends CompositeCommand {
@ -43,12 +50,14 @@ public class IslandCommand extends CompositeCommand {
@Override
public boolean execute(User user, List<String> args) {
// If this player does not have an island, create one
if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) {
getSubCommand("create").ifPresent(createCmd -> execute(user, new ArrayList<>()));
getSubCommand("create").ifPresent(createCmd -> createCmd.execute(user, new ArrayList<>()));
return true;
}
// Otherwise, currently, just go home
getSubCommand("go").ifPresent(goCmd -> execute(user, new ArrayList<>()));
getSubCommand("go").ifPresent(goCmd -> goCmd.execute(user, new ArrayList<>()));
return true;
}