Prevent infinite recursion in command aliases.

This commit is contained in:
Wertik 2020-09-19 23:51:23 +02:00 committed by Brianna
parent 4317d6db46
commit a4a3a18c30
2 changed files with 29 additions and 16 deletions

View File

@ -21,7 +21,12 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -145,10 +150,18 @@ public class CommandManager implements CommandExecutor, TabCompleter {
sendConsoleHelpCommands(sender);
} else {
String commandToExecute;
String defaultCommand;
if (plugin.getIslandManager().getIsland(player) == null) {
commandToExecute = mainConfig.getString("Command.Island.Aliases.NoIsland", "island create");
defaultCommand = "island create";
commandToExecute = mainConfig.getString("Command.Island.Aliases.NoIsland", defaultCommand);
} else {
commandToExecute = mainConfig.getString("Command.Island.Aliases.IslandOwned", "island controlpanel");
defaultCommand = "island controlpanel";
commandToExecute = mainConfig.getString("Command.Island.Aliases.IslandOwned", defaultCommand);
}
if (commandToExecute.trim().equalsIgnoreCase("island") || commandToExecute.trim().equalsIgnoreCase("is")) {
commandToExecute = defaultCommand;
Bukkit.getLogger().warning("Cannot redirect /island to /island or /is, would result in an endless loop. Using the default.");
}
if (commandToExecute.startsWith("/")) {