mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-15 23:25:37 +01:00
Allow plugin aliases to override vanilla commands (#11186)
fixes #11035
This commit is contained in:
parent
227544cfc7
commit
67d414a927
@ -686,10 +686,10 @@ index 0000000000000000000000000000000000000000..1b1642f306771f029e6214a2e2ebebb6
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
diff --git a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..a3e128bde0fa4ab0ecab4172f02288a29b9fddc7
|
index 0000000000000000000000000000000000000000..da50ca4c6524e4f99ea4de2157d7ef900178d0f1
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
+++ b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
||||||
@@ -0,0 +1,194 @@
|
@@ -0,0 +1,198 @@
|
||||||
+package io.papermc.paper.command.brigadier;
|
+package io.papermc.paper.command.brigadier;
|
||||||
+
|
+
|
||||||
+import com.google.common.base.Preconditions;
|
+import com.google.common.base.Preconditions;
|
||||||
@ -699,6 +699,7 @@ index 0000000000000000000000000000000000000000..a3e128bde0fa4ab0ecab4172f02288a2
|
|||||||
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
+import com.mojang.brigadier.tree.CommandNode;
|
+import com.mojang.brigadier.tree.CommandNode;
|
||||||
+import com.mojang.brigadier.tree.LiteralCommandNode;
|
+import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
+import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode;
|
||||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||||
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
|
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
|
||||||
+import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar;
|
+import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar;
|
||||||
@ -839,9 +840,12 @@ index 0000000000000000000000000000000000000000..a3e128bde0fa4ab0ecab4172f02288a2
|
|||||||
+ return this.registerIntoDispatcher(new PluginCommandNode(aliasLiteral, plugin, redirect, description), override);
|
+ return this.registerIntoDispatcher(new PluginCommandNode(aliasLiteral, plugin, redirect, description), override);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ private boolean registerIntoDispatcher(final PluginCommandNode node, final boolean override) {
|
+ private boolean registerIntoDispatcher(final PluginCommandNode node, boolean override) {
|
||||||
+ final boolean hasChild = this.getDispatcher().getRoot().getChild(node.getLiteral()) != null;
|
+ final @Nullable CommandNode<CommandSourceStack> existingChild = this.getDispatcher().getRoot().getChild(node.getLiteral());
|
||||||
+ if (!hasChild || override) { // Avoid merging behavior. Maybe something to look into in the future
|
+ if (existingChild != null && !(existingChild instanceof PluginCommandNode) && !(existingChild instanceof BukkitCommandNode)) {
|
||||||
|
+ override = true; // override vanilla commands
|
||||||
|
+ }
|
||||||
|
+ if (existingChild == null || override) { // Avoid merging behavior. Maybe something to look into in the future
|
||||||
+ if (override) {
|
+ if (override) {
|
||||||
+ this.getDispatcher().getRoot().removeCommand(node.getLiteral());
|
+ this.getDispatcher().getRoot().removeCommand(node.getLiteral());
|
||||||
+ }
|
+ }
|
||||||
|
Loading…
Reference in New Issue
Block a user