From 185cb53721e2c071a2b3c062b964fb167441867e Mon Sep 17 00:00:00 2001 From: Thinkofdeath <thethinkofdeath@gmail.com> Date: Wed, 12 Feb 2014 20:44:14 +0000 Subject: [PATCH] Allow vanilla commands to be the main version of a command diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 5a08283..a235ce8 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -120,6 +120,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.command.SimpleCommandMap; +import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerialization; @@ -395,8 +396,11 @@ public final class CraftServer implements Server { } if (type == PluginLoadOrder.POSTWORLD) { + // Spigot start - Allow vanilla commands to be forced to be the main command + setVanillaCommands(true); commandMap.setFallbackCommands(); - setVanillaCommands(); + setVanillaCommands(false); + // Spigot end commandMap.registerServerAliases(); loadCustomPermissions(); DefaultPermissions.registerCorePermissions(); @@ -408,51 +412,64 @@ public final class CraftServer implements Server { pluginManager.disablePlugins(); } - private void setVanillaCommands() { - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandAchievement(), "/achievement give <stat_name> [player]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBan(), "/ban <playername> [reason]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanIp(), "/ban-ip <ip-address|playername>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanList(), "/banlist [ips]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandClear(), "/clear <playername> [item] [metadata]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemodeDefault(), "/defaultgamemode <mode>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDeop(), "/deop <playername>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDifficulty(), "/difficulty <new difficulty>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEffect(), "/effect <player> <effect|clear> [seconds] [amplifier]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEnchant(), "/enchant <playername> <enchantment ID> [enchantment level]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemode(), "/gamemode <mode> [player]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamerule(), "/gamerule <rulename> [true|false]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGive(), "/give <playername> <item> [amount] [metadata] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandHelp(), "/help [page|commandname]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandIdleTimeout(), "/setidletimeout <Minutes until kick>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandKick(), "/kick <playername> [reason]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandKill(), "/kill [playername]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandList(), "/list")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandMe(), "/me <actiontext>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandOp(), "/op <playername>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardon(), "/pardon <playername>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardonIP(), "/pardon-ip <ip-address>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPlaySound(), "/playsound <sound> <playername> [x] [y] [z] [volume] [pitch] [minimumVolume]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSay(), "/say <message>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandScoreboard(), "/scoreboard")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSeed(), "/seed")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetBlock(), "/setblock <x> <y> <z> <tilename> [datavalue] [oldblockHandling] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetWorldSpawn(), "/setworldspawn [x] [y] [z]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpawnpoint(), "/spawnpoint <playername> [x] [y] [z]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpreadPlayers(), "/spreadplayers <x> <z> [spreadDistance] [maxRange] [respectTeams] <playernames>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSummon(), "/summon <EntityName> [x] [y] [z] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTp(), "/tp [player] <target>\n/tp [player] <x> <y> <z>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTell(), "/tell <playername> <message>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTellRaw(), "/tellraw <playername> <raw message>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestFor(), "/testfor <playername | selector> [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestForBlock(), "/testforblock <x> <y> <z> <tilename> [datavalue] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTime(), "/time set <value>\n/time add <value>")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandToggleDownfall(), "/toggledownfall")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWeather(), "/weather <clear/rain/thunder> [duration in seconds]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWhitelist(), "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandXp(), "/xp <amount> [player]\n/xp <amount>L [player]")); + // Spigot start + private void tryRegister(VanillaCommandWrapper commandWrapper, boolean first) { + if (org.spigotmc.SpigotConfig.replaceCommands.contains( commandWrapper.getName() ) ) { + if (first) { + commandMap.register( "minecraft", commandWrapper ); + } + } else if (!first) { + commandMap.register( "minecraft", commandWrapper ); + } + } + + private void setVanillaCommands(boolean first) + { + tryRegister( new VanillaCommandWrapper( new CommandAchievement(), "/achievement give <stat_name> [player]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBan(), "/ban <playername> [reason]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBanIp(), "/ban-ip <ip-address|playername>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBanList(), "/banlist [ips]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandClear(), "/clear <playername> [item] [metadata]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamemodeDefault(), "/defaultgamemode <mode>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandDeop(), "/deop <playername>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandDifficulty(), "/difficulty <new difficulty>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandEffect(), "/effect <player> <effect|clear> [seconds] [amplifier]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandEnchant(), "/enchant <playername> <enchantment ID> [enchantment level]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamemode(), "/gamemode <mode> [player]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamerule(), "/gamerule <rulename> [true|false]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGive(), "/give <playername> <item> [amount] [metadata] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandHelp(), "/help [page|commandname]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandIdleTimeout(), "/setidletimeout <Minutes until kick>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandKick(), "/kick <playername> [reason]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandKill(), "/kill [playername]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandList(), "/list" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandMe(), "/me <actiontext>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandOp(), "/op <playername>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPardon(), "/pardon <playername>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPardonIP(), "/pardon-ip <ip-address>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPlaySound(), "/playsound <sound> <playername> [x] [y] [z] [volume] [pitch] [minimumVolume]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSay(), "/say <message>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandScoreboard(), "/scoreboard" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSeed(), "/seed" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSetBlock(), "/setblock <x> <y> <z> <tilename> [datavalue] [oldblockHandling] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSetWorldSpawn(), "/setworldspawn [x] [y] [z]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSpawnpoint(), "/spawnpoint <playername> [x] [y] [z]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSpreadPlayers(), "/spreadplayers <x> <z> [spreadDistance] [maxRange] [respectTeams] <playernames>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSummon(), "/summon <EntityName> [x] [y] [z] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTp(), "/tp [player] <target>\n/tp [player] <x> <y> <z>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTell(), "/tell <playername> <message>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTellRaw(), "/tellraw <playername> <raw message>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTestFor(), "/testfor <playername | selector> [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTestForBlock(), "/testforblock <x> <y> <z> <tilename> [datavalue] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTime(), "/time set <value>\n/time add <value>" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandToggleDownfall(), "/toggledownfall" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandWeather(), "/weather <clear/rain/thunder> [duration in seconds]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandWhitelist(), "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandXp(), "/xp <amount> [player]\n/xp <amount>L [player]" ), first ); // This is what is in the lang file, I swear. - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandNetstat(), "/list")); + tryRegister( new VanillaCommandWrapper(new CommandNetstat(), "/list"), first ); } + // Spigot end private void loadPlugin(Plugin plugin) { try { diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java index 6957c17..e4ee00e 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/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.util.gnu.trove.map.hash.TObjectIntHashMap; import net.minecraft.server.MinecraftServer; @@ -295,4 +297,16 @@ public class SpigotConfig { filterCreativeItems = getBoolean( "settings.filter-creative-items", true ); } + + public static Set<String> replaceCommands; + private static void replaceCommands() + { + if ( config.contains( "replace-commands" ) ) + { + set( "commands.replace-commands", config.getStringList( "replace-commands" ) ); + config.set( "replace-commands", null ); + } + replaceCommands = new HashSet<String>( (List<String>) getList( "commands.replace-commands", + Arrays.asList( "setblock", "summon", "testforblock", "tellraw" ) ) ); + } } -- 1.9.1