From b4c05848c289c74884e21c70ff99fc36fc8b36e9 Mon Sep 17 00:00:00 2001 From: Thinkofdeath 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 8d33f56..ddce3d9 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -121,6 +121,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; @@ -388,8 +389,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(); @@ -401,51 +405,64 @@ public final class CraftServer implements Server { pluginManager.disablePlugins(); } - private void setVanillaCommands() { - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandAchievement(), "/achievement give [player]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBan(), "/ban [reason]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanIp(), "/ban-ip ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandBanList(), "/banlist [ips]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandClear(), "/clear [item] [metadata]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemodeDefault(), "/defaultgamemode ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDeop(), "/deop ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandDifficulty(), "/difficulty ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEffect(), "/effect [seconds] [amplifier]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandEnchant(), "/enchant [enchantment level]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamemode(), "/gamemode [player]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGamerule(), "/gamerule [true|false]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandGive(), "/give [amount] [metadata] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandHelp(), "/help [page|commandname]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandIdleTimeout(), "/setidletimeout ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandKick(), "/kick [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 ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandOp(), "/op ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardon(), "/pardon ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPardonIP(), "/pardon-ip ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandPlaySound(), "/playsound [x] [y] [z] [volume] [pitch] [minimumVolume]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSay(), "/say ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandScoreboard(), "/scoreboard")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSeed(), "/seed")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetBlock(), "/setblock [datavalue] [oldblockHandling] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSetWorldSpawn(), "/setworldspawn [x] [y] [z]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpawnpoint(), "/spawnpoint [x] [y] [z]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSpreadPlayers(), "/spreadplayers [spreadDistance] [maxRange] [respectTeams] ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandSummon(), "/summon [x] [y] [z] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTp(), "/tp [player] \n/tp [player] ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTell(), "/tell ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTellRaw(), "/tellraw ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestFor(), "/testfor [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTestForBlock(), "/testforblock [datavalue] [dataTag]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandTime(), "/time set \n/time add ")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandToggleDownfall(), "/toggledownfall")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWeather(), "/weather [duration in seconds]")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandWhitelist(), "/whitelist (add|remove) \n/whitelist (on|off|list|reload)")); - commandMap.register("minecraft", new VanillaCommandWrapper(new CommandXp(), "/xp [player]\n/xp 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 [player]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBan(), "/ban [reason]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBanIp(), "/ban-ip " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandBanList(), "/banlist [ips]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandClear(), "/clear [item] [metadata]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamemodeDefault(), "/defaultgamemode " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandDeop(), "/deop " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandDifficulty(), "/difficulty " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandEffect(), "/effect [seconds] [amplifier]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandEnchant(), "/enchant [enchantment level]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamemode(), "/gamemode [player]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGamerule(), "/gamerule [true|false]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandGive(), "/give [amount] [metadata] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandHelp(), "/help [page|commandname]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandIdleTimeout(), "/setidletimeout " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandKick(), "/kick [reason]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandKill(), "/kill [playername]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandList(), "/list" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandMe(), "/me " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandOp(), "/op " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPardon(), "/pardon " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPardonIP(), "/pardon-ip " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandPlaySound(), "/playsound [x] [y] [z] [volume] [pitch] [minimumVolume]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSay(), "/say " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandScoreboard(), "/scoreboard" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSeed(), "/seed" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSetBlock(), "/setblock [datavalue] [oldblockHandling] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSetWorldSpawn(), "/setworldspawn [x] [y] [z]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSpawnpoint(), "/spawnpoint [x] [y] [z]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSpreadPlayers(), "/spreadplayers [spreadDistance] [maxRange] [respectTeams] " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandSummon(), "/summon [x] [y] [z] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTp(), "/tp [player] \n/tp [player] " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTell(), "/tell " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTellRaw(), "/tellraw " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTestFor(), "/testfor [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTestForBlock(), "/testforblock [datavalue] [dataTag]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandTime(), "/time set \n/time add " ), first ); + tryRegister( new VanillaCommandWrapper( new CommandToggleDownfall(), "/toggledownfall" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandWeather(), "/weather [duration in seconds]" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandWhitelist(), "/whitelist (add|remove) \n/whitelist (on|off|list|reload)" ), first ); + tryRegister( new VanillaCommandWrapper( new CommandXp(), "/xp [player]\n/xp 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 0d0c7b0..4703768 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 gnu.trove.map.hash.TObjectIntHashMap; @@ -284,4 +286,16 @@ public class SpigotConfig { filterCreativeItems = getBoolean( "settings.filter-creative-items", true ); } + + public static Set 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( (List) getList( "commands.replace-commands", + Arrays.asList( "setblock", "summon", "testforblock", "tellraw" ) ) ); + } } -- 1.8.3.2