From 9c8d5eefd0c0e62ec5b9052b0eb76fede3d6b24c Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 12 Feb 2014 20:44:14 +0000 Subject: [PATCH] Allow vanilla commands to be the main version of a command By: Thinkofdeath --- .../org/bukkit/craftbukkit/CraftServer.java | 18 +++++++++++++++--- .../main/java/org/spigotmc/SpigotConfig.java | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 2bc2206625..e6d4e4e532 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -491,8 +491,11 @@ public final class CraftServer implements Server { } if (type == PluginLoadOrder.POSTWORLD) { + // Spigot start - Allow vanilla commands to be forced to be the main command + this.setVanillaCommands(true); this.commandMap.setFallbackCommands(); - this.setVanillaCommands(); + this.setVanillaCommands(false); + // Spigot end this.commandMap.registerServerAliases(); DefaultPermissions.registerCorePermissions(); CraftDefaultPermissions.registerCorePermissions(); @@ -506,12 +509,21 @@ public final class CraftServer implements Server { this.pluginManager.disablePlugins(); } - private void setVanillaCommands() { + private void setVanillaCommands(boolean first) { // Spigot Commands dispatcher = this.console.vanillaCommandDispatcher; // Build a list of all Vanilla commands and create wrappers for (CommandNode cmd : dispatcher.getDispatcher().getRoot().getChildren()) { - this.commandMap.register("minecraft", new VanillaCommandWrapper(dispatcher, cmd)); + // Spigot start + VanillaCommandWrapper wrapper = new VanillaCommandWrapper(dispatcher, cmd); + if (org.spigotmc.SpigotConfig.replaceCommands.contains( wrapper.getName() ) ) { + if (first) { + this.commandMap.register("minecraft", wrapper); + } + } else if (!first) { + this.commandMap.register("minecraft", wrapper); + } + // Spigot end } } diff --git a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java index c0e9517fed..7366c020ea 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java +++ b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java @@ -8,8 +8,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -300,4 +302,16 @@ public class SpigotConfig { SpigotConfig.silentCommandBlocks = SpigotConfig.getBoolean( "commands.silent-commandblock-console", false ); } + + public static Set replaceCommands; + private static void replaceCommands() + { + if ( SpigotConfig.config.contains( "replace-commands" ) ) + { + SpigotConfig.set( "commands.replace-commands", SpigotConfig.config.getStringList( "replace-commands" ) ); + SpigotConfig.config.set( "replace-commands", null ); + } + SpigotConfig.replaceCommands = new HashSet( (List) SpigotConfig.getList( "commands.replace-commands", + Arrays.asList( "setblock", "summon", "testforblock", "tellraw" ) ) ); + } }