mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Get things back compiling
This commit is contained in:
@@ -71,6 +71,7 @@ public class BukkitCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
this.formatters.put(MessageType.ERROR, defaultFormatter = new BukkitMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED));
|
||||
this.formatters.put(MessageType.SYNTAX, new BukkitMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE));
|
||||
this.formatters.put(MessageType.INFO, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN));
|
||||
this.formatters.put(MessageType.HELP, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.GREEN, ChatColor.YELLOW));
|
||||
Bukkit.getPluginManager().registerEvents(new ACFBukkitListener(plugin), plugin);
|
||||
getLocales(); // auto load locales
|
||||
}
|
||||
@@ -265,9 +266,4 @@ public class BukkitCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHelp generateCommandHelp(BaseCommand command) {
|
||||
return new CommandHelp(this, command, getCurrentCommandOperationContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,10 @@ package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -57,12 +55,13 @@ public class BukkitRootCommand extends Command implements RootCommand {
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
return tabComplete(new BukkitCommandIssuer(manager, sender), alias, args);
|
||||
return tabComplete(manager.getCommandIssuer(sender), alias, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
return execute(new BukkitCommandIssuer(manager, sender), commandLabel, args);
|
||||
execute(manager.getCommandIssuer(sender), commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<String> tabComplete(CommandIssuer sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
@@ -71,19 +70,7 @@ public class BukkitRootCommand extends Command implements RootCommand {
|
||||
return new ArrayList<>(completions);
|
||||
}
|
||||
|
||||
private boolean execute(CommandIssuer sender, String commandLabel, String[] args) {
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
String checkSub = StringUtils.join(args, " ", 0, i).toLowerCase();
|
||||
Set<RegisteredCommand> registeredCommands = this.subCommands.get(checkSub);
|
||||
if (!registeredCommands.isEmpty()) {
|
||||
registeredCommands.iterator().next().scope.execute(sender, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.defCommand.execute(sender, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addChild(BaseCommand command) {
|
||||
if (this.defCommand == null || !command.subCommands.get("__default").isEmpty()) {
|
||||
|
||||
@@ -51,6 +51,7 @@ public class BungeeCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
this.formatters.put(MessageType.ERROR, defaultFormatter = new BungeeMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED));
|
||||
this.formatters.put(MessageType.SYNTAX, new BungeeMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE));
|
||||
this.formatters.put(MessageType.INFO, new BungeeMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN));
|
||||
this.formatters.put(MessageType.HELP, new BungeeMessageFormatter(ChatColor.BLUE, ChatColor.GREEN, ChatColor.YELLOW));
|
||||
getLocales(); // auto load locales
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
@@ -35,7 +36,7 @@ public class BungeeRootCommand extends Command implements RootCommand, TabExecut
|
||||
private final BungeeCommandManager manager;
|
||||
private final String name;
|
||||
private BaseCommand defCommand;
|
||||
private Map<String, BaseCommand> subCommands = new HashMap<>();
|
||||
private SetMultimap<String, RegisteredCommand> subCommands = HashMultimap.create();
|
||||
private List<BaseCommand> children = new ArrayList<>();
|
||||
boolean isRegistered = false;
|
||||
|
||||
@@ -65,26 +66,18 @@ public class BungeeRootCommand extends Command implements RootCommand, TabExecut
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
execute(new BungeeCommandIssuer(manager, sender), getName(), args);
|
||||
public SetMultimap<String, RegisteredCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
private void execute(CommandIssuer sender, String commandLabel, String[] args) {
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
String checkSub = ApacheCommonsLangUtil.join(args, " ", 0, i).toLowerCase();
|
||||
BaseCommand subHandler = this.subCommands.get(checkSub);
|
||||
if (subHandler != null) {
|
||||
subHandler.execute(sender, commandLabel, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.defCommand.execute(sender, commandLabel, args);
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
execute(manager.getCommandIssuer(sender), getName(), args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
|
||||
return onTabComplete(new BungeeCommandIssuer(manager, commandSender), getName(), strings);
|
||||
return onTabComplete(manager.getCommandIssuer(commandSender), getName(), strings);
|
||||
}
|
||||
|
||||
private List<String> onTabComplete(CommandIssuer sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
|
||||
@@ -512,8 +512,8 @@ public abstract class BaseCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
public CommandHelp getCommandHelp(){
|
||||
return manager.generateCommandHelp(this);
|
||||
public CommandHelp getCommandHelp() {
|
||||
return manager.generateCommandHelp();
|
||||
}
|
||||
|
||||
public void help(Object issuer, String[] args) {
|
||||
|
||||
@@ -27,29 +27,27 @@ import com.google.common.collect.SetMultimap;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class CommandHelp {
|
||||
private final CommandManager manager;
|
||||
private final List<HelpEntry> helpEntries;
|
||||
private final CommandOperationContext currentContext;
|
||||
private final CommandIssuer issuer;
|
||||
private final List<HelpEntry> helpEntries = new ArrayList<>();
|
||||
|
||||
protected CommandHelp(CommandManager manager, BaseCommand command, CommandOperationContext currentContext) {
|
||||
public CommandHelp(CommandManager manager, RootCommand rootCommand, CommandIssuer issuer) {
|
||||
this.manager = manager;
|
||||
this.currentContext = currentContext;
|
||||
this.issuer = issuer;
|
||||
|
||||
List<HelpEntry> entries = new ArrayList<>();
|
||||
for (RootCommand root : command.registeredCommands.values()) {
|
||||
SetMultimap<String, RegisteredCommand> subCommands = root.getSubCommands();
|
||||
subCommands.entries().forEach(e -> {
|
||||
if (e.getKey().equals("__default") || e.getKey().equals("__unknown")){
|
||||
return;
|
||||
}
|
||||
RegisteredCommand regCommand = e.getValue();
|
||||
entries.add(new HelpEntry(regCommand));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
this.helpEntries = entries;
|
||||
SetMultimap<String, RegisteredCommand> subCommands = rootCommand.getSubCommands();
|
||||
subCommands.entries().forEach(e -> {
|
||||
String key = e.getKey();
|
||||
if (key.equals("__default") || key.equals("__unknown")){
|
||||
return;
|
||||
}
|
||||
RegisteredCommand regCommand = e.getValue();
|
||||
if (regCommand.hasPermission(issuer)) {
|
||||
this.helpEntries.add(new HelpEntry(regCommand));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CommandManager getManager() {
|
||||
@@ -57,28 +55,20 @@ public class CommandHelp {
|
||||
}
|
||||
|
||||
public void showHelp() {
|
||||
showHelp(currentContext.getCommandIssuer());
|
||||
showHelp(issuer);
|
||||
}
|
||||
|
||||
public void showHelp(CommandIssuer issuer) {
|
||||
getHelpEntries().forEach(h -> {
|
||||
issuer.sendMessage(MessageType.HELP, MessageKeys.HELP_FORMAT,
|
||||
//{command} {parameters} {seperator} {helptext}
|
||||
"{command}", h.getCommand(),
|
||||
"{parameters}", h.getParameterSyntax(),
|
||||
"{seperator}", h.getHelpText().isEmpty() ? "" : " - ",
|
||||
"{helptext}", h.getHelpText()
|
||||
);
|
||||
});
|
||||
|
||||
getHelpEntries().forEach(e -> issuer.sendMessage(MessageType.HELP, MessageKeys.HELP_FORMAT,
|
||||
//{command} {parameters} {seperator} {helptext}
|
||||
"{command}", e.getCommand(),
|
||||
"{parameters}", e.getParameterSyntax(),
|
||||
"{seperator}", e.getHelpText().isEmpty() ? "" : " - ",
|
||||
"{helptext}", e.getHelpText()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public List<HelpEntry> getHelpEntries() {
|
||||
return helpEntries;
|
||||
}
|
||||
|
||||
public CommandOperationContext getCurrentContext() {
|
||||
return currentContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ package co.aikar.commands;
|
||||
|
||||
import co.aikar.locales.MessageKeyProvider;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
@@ -106,7 +107,29 @@ public abstract class CommandManager <I, FT, F extends MessageFormatter<FT>> {
|
||||
*/
|
||||
public abstract CommandCompletions<?> getCommandCompletions();
|
||||
|
||||
public abstract CommandHelp generateCommandHelp(BaseCommand command);
|
||||
public CommandHelp generateCommandHelp(@NotNull String command) {
|
||||
CommandOperationContext context = getCurrentCommandOperationContext();
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("This method can only be called as part of a command execution.");
|
||||
}
|
||||
return generateCommandHelp(context.getCommandIssuer(), command);
|
||||
}
|
||||
public CommandHelp generateCommandHelp(CommandIssuer issuer, @NotNull String command) {
|
||||
return generateCommandHelp(issuer, obtainRootCommand(ACFPatterns.SPACE.split(command, 2)[0]));
|
||||
}
|
||||
|
||||
public CommandHelp generateCommandHelp() {
|
||||
CommandOperationContext context = getCurrentCommandOperationContext();
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("This method can only be called as part of a command execution.");
|
||||
}
|
||||
String commandLabel = context.getCommandLabel();
|
||||
return generateCommandHelp(context.getCommandIssuer(), this.obtainRootCommand(commandLabel));
|
||||
}
|
||||
|
||||
public CommandHelp generateCommandHelp(CommandIssuer issuer, RootCommand rootCommand) {
|
||||
return new CommandHelp(this, rootCommand, issuer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command with ACF
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
import java.util.List;
|
||||
@@ -57,6 +58,21 @@ interface RootCommand {
|
||||
children.add(command);
|
||||
}
|
||||
|
||||
default BaseCommand execute(CommandIssuer sender, String commandLabel, String[] args) {
|
||||
BaseCommand command = getDefCommand();
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
String checkSub = ApacheCommonsLangUtil.join(args, " ", 0, i).toLowerCase();
|
||||
Set<RegisteredCommand> registeredCommands = getSubCommands().get(checkSub);
|
||||
if (!registeredCommands.isEmpty()) {
|
||||
command = registeredCommands.iterator().next().scope;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
command.execute(sender, commandLabel, args);
|
||||
return command;
|
||||
}
|
||||
|
||||
default BaseCommand getDefCommand(){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class SpongeCommandManager extends CommandManager<CommandSource, TextColo
|
||||
this.formatters.put(MessageType.ERROR, defaultFormatter = new SpongeMessageFormatter(TextColors.RED, TextColors.YELLOW, TextColors.RED));
|
||||
this.formatters.put(MessageType.SYNTAX, new SpongeMessageFormatter(TextColors.YELLOW, TextColors.GREEN, TextColors.WHITE));
|
||||
this.formatters.put(MessageType.INFO, new SpongeMessageFormatter(TextColors.BLUE, TextColors.DARK_GREEN, TextColors.GREEN));
|
||||
this.formatters.put(MessageType.HELP, new SpongeMessageFormatter(TextColors.BLUE, TextColors.GREEN, TextColors.YELLOW));
|
||||
getLocales(); // auto load locales
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
@@ -34,10 +35,8 @@ import org.spongepowered.api.world.Location;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,9 +45,9 @@ import javax.annotation.Nullable;
|
||||
public class SpongeRootCommand implements CommandCallable, RootCommand {
|
||||
|
||||
private final SpongeCommandManager manager;
|
||||
final String name;
|
||||
private final String name;
|
||||
private BaseCommand defCommand;
|
||||
private Map<String, BaseCommand> subCommands = new HashMap<>();
|
||||
private SetMultimap<String, RegisteredCommand> subCommands = HashMultimap.create();
|
||||
private List<BaseCommand> children = new ArrayList<>();
|
||||
boolean isRegistered = false;
|
||||
|
||||
@@ -65,13 +64,13 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
|
||||
@Override
|
||||
public CommandResult process(@NotNull CommandSource source, @NotNull String arguments) throws CommandException {
|
||||
String[] args = arguments.isEmpty() ? new String[0] : arguments.split(" ");
|
||||
return this.execute(new SpongeCommandIssuer(manager, source), this.name, args);
|
||||
return this.executeSponge(manager.getCommandIssuer(source), this.name, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(@NotNull CommandSource source, @NotNull String arguments, @Nullable Location<World> location) throws CommandException {
|
||||
String[] args = arguments.isEmpty() ? new String[0] : arguments.split(" ");
|
||||
return tabComplete(new SpongeCommandIssuer(manager, source), this.name, args);
|
||||
return tabComplete(manager.getCommandIssuer(source), this.name, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,18 +99,8 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
|
||||
return new ArrayList<>(completions);
|
||||
}
|
||||
|
||||
private CommandResult execute(CommandIssuer sender, String commandLabel, String[] args) {
|
||||
BaseCommand cmd = this.defCommand;
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
String checkSub = ApacheCommonsLangUtil.join(args, " ", 0, i).toLowerCase();
|
||||
BaseCommand subHandler = this.subCommands.get(checkSub);
|
||||
if (subHandler != null) {
|
||||
cmd = subHandler;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cmd.execute(sender, commandLabel, args);
|
||||
private CommandResult executeSponge(CommandIssuer sender, String commandLabel, String[] args) {
|
||||
BaseCommand cmd = execute(sender, commandLabel, args);
|
||||
return ((SpongeCommandOperationContext) cmd.lastCommandOperationContext).getResult();
|
||||
}
|
||||
|
||||
@@ -126,4 +115,9 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetMultimap<String, RegisteredCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user