| 23 | import org.jetbrains.annotations.Nullable; |
| 24 | |
| 25 | public class SimpleCommandMap implements CommandMap { |
| 26 | protected final Map<String, Command> knownCommands = new HashMap<String, Command>(); |
| 27 | private final Server server; |
| 28 | |
| 29 | public SimpleCommandMap(@NotNull final Server server) { |
| 30 | this.server = server; |
| 31 | setDefaultCommands(); |
| 32 | } |
| 33 | |
| 34 | private void setDefaultCommands() { |
| 35 | register("bukkit", new VersionCommand("version")); |
| 36 | register("bukkit", new ReloadCommand("reload")); |
| 37 | register("bukkit", new PluginsCommand("plugins")); |
| 38 | register("bukkit", new TimingsCommand("timings")); |
| 39 | } |
| 40 | |
| 41 | public void setFallbackCommands() { |
| 42 | register("bukkit", new HelpCommand()); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * {@inheritDoc} |
| 47 | */ |
| 48 | @Override |
| 49 | public void registerAll(@NotNull String fallbackPrefix, @NotNull List<Command> commands) { |
| 50 | if (commands != null) { |
| 51 | for (Command c : commands) { |
| 52 | register(fallbackPrefix, c); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | */ |
| 60 | @Override |
| 61 | public boolean register(@NotNull String fallbackPrefix, @NotNull Command command) { |
| 62 | return register(command.getName(), fallbackPrefix, command); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritDoc} |
| 67 | */ |
| 68 | @Override |
| 69 | public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) { |
| 70 | label = label.toLowerCase(java.util.Locale.ENGLISH).trim(); |
| 71 | fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim(); |
| 72 | boolean registered = register(label, command, false, fallbackPrefix); |
| 73 | |
| 74 | Iterator<String> iterator = command.getAliases().iterator(); |
| 75 | while (iterator.hasNext()) { |
| 76 | if (!register(iterator.next(), command, true, fallbackPrefix)) { |
| 77 | iterator.remove(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // If we failed to register under the real name, we need to set the command label to the direct address |
| 82 | if (!registered) { |
nothing calls this directly
no outgoing calls
no test coverage detected