Fix suggestions and add a bukkit test module
This commit is contained in:
parent
2cb367903f
commit
e7c59b2062
10 changed files with 248 additions and 26 deletions
|
|
@ -141,6 +141,9 @@ public abstract class CommandManager<C extends CommandSender, M extends CommandM
|
||||||
while (stringTokenizer.hasMoreElements()) {
|
while (stringTokenizer.hasMoreElements()) {
|
||||||
tokens.add(stringTokenizer.nextToken());
|
tokens.add(stringTokenizer.nextToken());
|
||||||
}
|
}
|
||||||
|
if (input.endsWith(" ")) {
|
||||||
|
tokens.add("");
|
||||||
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -272,25 +272,18 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
final Node<CommandComponent<C, ?>> child = children.get(0);
|
final Node<CommandComponent<C, ?>> child = children.get(0);
|
||||||
if (child.getValue() != null) {
|
if (child.getValue() != null) {
|
||||||
if (commandQueue.isEmpty()) {
|
if (commandQueue.isEmpty()) {
|
||||||
if (child.isLeaf()) {
|
return child.getValue().getParser().suggestions(commandContext, "");
|
||||||
/* Child is leaf, and so no suggestions should be sent */
|
} else if (child.isLeaf() && commandQueue.size() < 2) {
|
||||||
return Collections.emptyList();
|
return child.getValue().getParser().suggestions(commandContext, commandQueue.peek());
|
||||||
} else {
|
} else if (child.isLeaf()) {
|
||||||
/* Send all suggestions */
|
return Collections.emptyList();
|
||||||
return child.getValue().getParser().suggestions(commandContext, "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final ComponentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
|
final ComponentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
|
||||||
if (result.getParsedValue().isPresent()) {
|
if (result.getParsedValue().isPresent()) {
|
||||||
if (child.isLeaf()) {
|
|
||||||
/* Child is leaf, and so no suggestions should be sent */
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
||||||
return this.getSuggestions(commandContext, commandQueue, child);
|
return this.getSuggestions(commandContext, commandQueue, child);
|
||||||
} else if (result.getFailure().isPresent()) {
|
} else if (result.getFailure().isPresent()) {
|
||||||
/* I need to return ze error */
|
return child.getValue().getParser().suggestions(commandContext, commandQueue.peek());
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,23 @@ import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class StringComponent<C extends CommandSender> extends CommandComponent<C, String> {
|
public final class StringComponent<C extends CommandSender> extends CommandComponent<C, String> {
|
||||||
|
|
||||||
private final StringMode stringMode;
|
private final StringMode stringMode;
|
||||||
|
|
||||||
private StringComponent(final boolean required, @Nonnull final String name,
|
private StringComponent(final boolean required,
|
||||||
@Nonnull final StringMode stringMode, @Nonnull final String defaultValue) {
|
@Nonnull final String name,
|
||||||
super(required, name, new StringParser<>(stringMode), defaultValue);
|
@Nonnull final StringMode stringMode,
|
||||||
|
@Nonnull final String defaultValue,
|
||||||
|
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
||||||
|
super(required, name, new StringParser<>(stringMode, suggestionsProvider), defaultValue);
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +121,7 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, String> {
|
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, String> {
|
||||||
|
|
||||||
private StringMode stringMode = StringMode.SINGLE;
|
private StringMode stringMode = StringMode.SINGLE;
|
||||||
|
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@Nonnull final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
@ -153,6 +160,19 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the suggestions provider
|
||||||
|
*
|
||||||
|
* @param suggestionsProvider Suggestions provider
|
||||||
|
* @return Builder instance
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Builder<C> withSuggestionsProvider(@Nonnull final BiFunction<CommandContext<C>,
|
||||||
|
String, List<String>> suggestionsProvider) {
|
||||||
|
this.suggestionsProvider = suggestionsProvider;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder a new string component
|
* Builder a new string component
|
||||||
*
|
*
|
||||||
|
|
@ -161,7 +181,8 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public StringComponent<C> build() {
|
public StringComponent<C> build() {
|
||||||
return new StringComponent<>(this.isRequired(), this.getName(), this.stringMode, this.getDefaultValue());
|
return new StringComponent<>(this.isRequired(), this.getName(), this.stringMode,
|
||||||
|
this.getDefaultValue(), this.suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -170,9 +191,12 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
private static final class StringParser<C extends CommandSender> implements ComponentParser<C, String> {
|
private static final class StringParser<C extends CommandSender> implements ComponentParser<C, String> {
|
||||||
|
|
||||||
private final StringMode stringMode;
|
private final StringMode stringMode;
|
||||||
|
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
||||||
|
|
||||||
private StringParser(@Nonnull final StringMode stringMode) {
|
private StringParser(@Nonnull final StringMode stringMode,
|
||||||
|
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
|
this.suggestionsProvider = suggestionsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
@ -228,6 +252,12 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
|
|
||||||
return ComponentParseResult.success(sj.toString());
|
return ComponentParseResult.success(sj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext, @Nonnull final String input) {
|
||||||
|
return this.suggestionsProvider.apply(commandContext, input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
75
cloud-minecraft/cloud-bukkit-test/pom.xml
Normal file
75
cloud-minecraft/cloud-bukkit-test/pom.xml
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~
|
||||||
|
~ MIT License
|
||||||
|
~
|
||||||
|
~ Copyright (c) 2020 Alexander Söderberg
|
||||||
|
~
|
||||||
|
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
~ of this software and associated documentation files (the "Software"), to deal
|
||||||
|
~ in the Software without restriction, including without limitation the rights
|
||||||
|
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
~ copies of the Software, and to permit persons to whom the Software is
|
||||||
|
~ furnished to do so, subject to the following conditions:
|
||||||
|
~
|
||||||
|
~ The above copyright notice and this permission notice shall be included in all
|
||||||
|
~ copies or substantial portions of the Software.
|
||||||
|
~
|
||||||
|
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
~ SOFTWARE.
|
||||||
|
~
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>cloud</artifactId>
|
||||||
|
<groupId>com.intellectualsites</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>cloud-bukkit-test</artifactId>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.intellectualsites</groupId>
|
||||||
|
<artifactId>cloud-bukkit</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
//
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2020 Alexander Söderberg
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
|
import com.intellectualsites.commands.components.StaticComponent;
|
||||||
|
import com.intellectualsites.commands.components.standard.EnumComponent;
|
||||||
|
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||||
|
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public final class BukkitTest extends JavaPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
try {
|
||||||
|
final BukkitCommandManager commandManager = new BukkitCommandManager(this,
|
||||||
|
CommandExecutionCoordinator.simpleCoordinator());
|
||||||
|
commandManager.registerCommand(commandManager.commandBuilder("gamemode",
|
||||||
|
Collections.singleton("gajmöde"),
|
||||||
|
BukkitCommandMetaBuilder.builder()
|
||||||
|
.withDescription("Your ugli")
|
||||||
|
.build())
|
||||||
|
.withComponent(EnumComponent.required(GameMode.class, "gamemode"))
|
||||||
|
.withComponent(StringComponent.<BukkitCommandSender>newBuilder("player")
|
||||||
|
.withSuggestionsProvider((v1, v2) -> {
|
||||||
|
final List<String> suggestions = new ArrayList<>(Bukkit.getOnlinePlayers().stream()
|
||||||
|
.map(Player::getName).collect(Collectors.toList()));
|
||||||
|
suggestions.add("dog");
|
||||||
|
suggestions.add("cat");
|
||||||
|
return suggestions;
|
||||||
|
}).build())
|
||||||
|
.withHandler(c -> c.getCommandSender()
|
||||||
|
.asPlayer()
|
||||||
|
.setGameMode(c.<GameMode>get("gamemode")
|
||||||
|
.orElse(GameMode.SURVIVAL)))
|
||||||
|
.build())
|
||||||
|
.registerCommand(commandManager.commandBuilder("kenny")
|
||||||
|
.withComponent(StaticComponent.required("sux"))
|
||||||
|
.build());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2020 Alexander Söderberg
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stuff
|
||||||
|
*/
|
||||||
|
package com.intellectualsites.commands;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: Command-Test
|
||||||
|
author: Citymonstret
|
||||||
|
main: com.intellectualsites.commands.BukkitTest
|
||||||
|
version: 1.0
|
||||||
|
api-version: 1.13
|
||||||
|
|
@ -35,12 +35,15 @@ final class BukkitCommand extends org.bukkit.command.Command implements PluginId
|
||||||
|
|
||||||
private final CommandComponent<BukkitCommandSender, ?> command;
|
private final CommandComponent<BukkitCommandSender, ?> command;
|
||||||
private final BukkitCommandManager bukkitCommandManager;
|
private final BukkitCommandManager bukkitCommandManager;
|
||||||
|
private final com.intellectualsites.commands.Command<BukkitCommandSender, BukkitCommandMeta> cloudCommand;
|
||||||
|
|
||||||
BukkitCommand(@Nonnull final CommandComponent<BukkitCommandSender, ?> command,
|
BukkitCommand(@Nonnull final com.intellectualsites.commands.Command<BukkitCommandSender, BukkitCommandMeta> cloudCommand,
|
||||||
|
@Nonnull final CommandComponent<BukkitCommandSender, ?> command,
|
||||||
@Nonnull final BukkitCommandManager bukkitCommandManager) {
|
@Nonnull final BukkitCommandManager bukkitCommandManager) {
|
||||||
super(command.getName());
|
super(command.getName());
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.bukkitCommandManager = bukkitCommandManager;
|
this.bukkitCommandManager = bukkitCommandManager;
|
||||||
|
this.cloudCommand = cloudCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -62,6 +65,11 @@ final class BukkitCommand extends org.bukkit.command.Command implements PluginId
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return this.cloudCommand.getCommandMeta().getOrDefault("description", "");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) throws
|
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) throws
|
||||||
IllegalArgumentException {
|
IllegalArgumentException {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
import org.bukkit.help.GenericCommandHelpTopic;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
@ -41,6 +42,7 @@ final class BukkitPluginRegistrationHandler implements CommandRegistrationHandle
|
||||||
|
|
||||||
private Map<String, org.bukkit.command.Command> bukkitCommands;
|
private Map<String, org.bukkit.command.Command> bukkitCommands;
|
||||||
private BukkitCommandManager bukkitCommandManager;
|
private BukkitCommandManager bukkitCommandManager;
|
||||||
|
private CommandMap commandMap;
|
||||||
|
|
||||||
BukkitPluginRegistrationHandler() {
|
BukkitPluginRegistrationHandler() {
|
||||||
}
|
}
|
||||||
|
|
@ -48,14 +50,14 @@ final class BukkitPluginRegistrationHandler implements CommandRegistrationHandle
|
||||||
void initialize(@Nonnull final BukkitCommandManager bukkitCommandManager) throws Exception {
|
void initialize(@Nonnull final BukkitCommandManager bukkitCommandManager) throws Exception {
|
||||||
final Method getCommandMap = Bukkit.getServer().getClass().getDeclaredMethod("getCommandMap");
|
final Method getCommandMap = Bukkit.getServer().getClass().getDeclaredMethod("getCommandMap");
|
||||||
getCommandMap.setAccessible(true);
|
getCommandMap.setAccessible(true);
|
||||||
final CommandMap commandMap = (CommandMap) getCommandMap.invoke(Bukkit.getServer());
|
this.commandMap = (CommandMap) getCommandMap.invoke(Bukkit.getServer());
|
||||||
final Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
final Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||||
knownCommands.setAccessible(true);
|
knownCommands.setAccessible(true);
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL") final Map<String, org.bukkit.command.Command> bukkitCommands =
|
||||||
final Map<String, org.bukkit.command.Command> bukkitCommands =
|
|
||||||
(Map<String, org.bukkit.command.Command>) knownCommands.get(commandMap);
|
(Map<String, org.bukkit.command.Command>) knownCommands.get(commandMap);
|
||||||
this.bukkitCommands = bukkitCommands;
|
this.bukkitCommands = bukkitCommands;
|
||||||
this.bukkitCommandManager = bukkitCommandManager;
|
this.bukkitCommandManager = bukkitCommandManager;
|
||||||
|
Bukkit.getHelpMap().registerHelpTopicFactory(BukkitCommand.class, GenericCommandHelpTopic::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -71,11 +73,13 @@ final class BukkitPluginRegistrationHandler implements CommandRegistrationHandle
|
||||||
} else {
|
} else {
|
||||||
label = commandComponent.getName();
|
label = commandComponent.getName();
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") final BukkitCommand bukkitCommand = new BukkitCommand(
|
||||||
final BukkitCommand bukkitCommand = new BukkitCommand((CommandComponent<BukkitCommandSender, ?>) commandComponent,
|
(Command<BukkitCommandSender, BukkitCommandMeta>) command,
|
||||||
this.bukkitCommandManager);
|
(CommandComponent<BukkitCommandSender, ?>) commandComponent,
|
||||||
this.bukkitCommands.put(label, bukkitCommand);
|
this.bukkitCommandManager);
|
||||||
this.registeredCommands.put(commandComponent, bukkitCommand);
|
this.registeredCommands.put(commandComponent, bukkitCommand);
|
||||||
|
this.commandMap.register(commandComponent.getName(), this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(),
|
||||||
|
bukkitCommand);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -12,6 +12,8 @@
|
||||||
<module>cloud-minecraft/cloud-bukkit</module>
|
<module>cloud-minecraft/cloud-bukkit</module>
|
||||||
<module>cloud-core</module>
|
<module>cloud-core</module>
|
||||||
<module>cloud-pipeline</module>
|
<module>cloud-pipeline</module>
|
||||||
|
<!-- REMOVE THIS -->
|
||||||
|
<module>cloud-minecraft/cloud-bukkit-test</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<inceptionYear>2020</inceptionYear>
|
<inceptionYear>2020</inceptionYear>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue