✨ Improve Bukkit conflict management
Conflicting commands will now obey plugin load order. Brigadier aliases will be created for namespaced aliases. No asynchronous completions will be provided for conflicting commands and will only be provided for the namespaced label. Furthermore, error handling the command tree has been improved and the methods now return a pair, rather than an optional. This means that there's no need to catch and unwrap exceptions and they will be forwarded in the correct form.
This commit is contained in:
parent
8eaf0ac772
commit
22993a46d7
10 changed files with 271 additions and 172 deletions
|
|
@ -23,6 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.paper;
|
||||
|
||||
import cloud.commandframework.bukkit.BukkitPluginRegistrationHandler;
|
||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -51,6 +52,12 @@ class AsyncCommandSuggestionsListener<C> implements Listener {
|
|||
if (paperCommandManager.getCommandTree().getNamedNode(arguments[0]) == null) {
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
final BukkitPluginRegistrationHandler<C> bukkitPluginRegistrationHandler =
|
||||
(BukkitPluginRegistrationHandler<C>) this.paperCommandManager.getCommandRegistrationHandler();
|
||||
if (!bukkitPluginRegistrationHandler.isRecognized(arguments[0])) {
|
||||
return;
|
||||
}
|
||||
final CommandSender sender = event.getSender();
|
||||
final C cloudSender = this.paperCommandManager.getCommandSenderMapper().apply(sender);
|
||||
final List<String> suggestions = new ArrayList<>(this.paperCommandManager.suggest(cloudSender,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
|||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -49,6 +50,7 @@ import java.util.UUID;
|
|||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class PaperBrigadierListener<C> implements Listener {
|
||||
|
||||
|
|
@ -168,8 +170,21 @@ class PaperBrigadierListener<C> implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||
if (!(event.getCommand() instanceof PluginIdentifiableCommand)) {
|
||||
return;
|
||||
} else if (!((PluginIdentifiableCommand) event.getCommand())
|
||||
.getPlugin().equals(this.paperCommandManager.getOwningPlugin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CommandTree<C> commandTree = this.paperCommandManager.getCommandTree();
|
||||
final CommandTree.Node<CommandArgument<C, ?>> node = commandTree.getNamedNode(event.getCommandLabel());
|
||||
|
||||
String label = event.getCommandLabel();
|
||||
if (label.contains(":")) {
|
||||
label = label.split(Pattern.quote(":"))[1];
|
||||
}
|
||||
|
||||
final CommandTree.Node<CommandArgument<C, ?>> node = commandTree.getNamedNode(label);
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue