private void RemoveConsoleCommand(Command.ConsoleCommand command) { if (this.consoleCommands.ContainsKey(command.Name)) { this.consoleCommands.Remove(command.Name); if (command.OriginalCallback == null) { ConsoleSystem.Index.Server.Dict.Remove(command.RustCommand.FullName); if (command.Name.StartsWith("global.")) { ConsoleSystem.Index.Server.GlobalDict.Remove(command.RustCommand.Name); } ConsoleSystem.Index.All = ConsoleSystem.Index.Server.Dict.Values.ToArray <ConsoleSystem.Command>(); } else { ConsoleSystem.Index.Server.Dict[command.RustCommand.FullName].Call = command.OriginalCallback; if (command.RustCommand.FullName.StartsWith("global.")) { ConsoleSystem.Index.Server.GlobalDict[command.RustCommand.Name].Call = command.OriginalCallback; return; } } } }
public void RemoveConsoleCommand(string command, Plugin plugin) { Command.ConsoleCommand consoleCommand = ( from x in this.consoleCommands.Values where x.Callback.Plugin == plugin select x).FirstOrDefault <Command.ConsoleCommand>((Command.ConsoleCommand x) => x.Name == command); if (consoleCommand != null) { this.RemoveConsoleCommand(consoleCommand); } }
public void AddConsoleCommand(string command, Plugin plugin, Func <ConsoleSystem.Arg, bool> callback) { Command.ConsoleCommand consoleCommand; RustCommandSystem.RegisteredCommand registeredCommand; ConsoleSystem.Command command1; object name; object obj; object name1; object obj1; object name2; object obj2; if (plugin != null && !this.pluginRemovedFromManager.ContainsKey(plugin)) { this.pluginRemovedFromManager[plugin] = plugin.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.plugin_OnRemovedFromManager)); } string[] strArray = command.Split(new Char[] { '.' }); string str = ((int)strArray.Length >= 2 ? strArray[0].Trim() : "global"); string rustCommand = ((int)strArray.Length >= 2 ? String.Join(".", strArray.Skip <string>(1).ToArray <string>()) : strArray[0].Trim()); string rustCommand1 = String.Concat(str, ".", rustCommand); Command.ConsoleCommand originalCallback = new Command.ConsoleCommand(rustCommand1); if (!this.CanOverrideCommand((str == "global" ? rustCommand : rustCommand1), "console")) { if (plugin != null) { obj2 = plugin.Name; } else { obj2 = null; } if (obj2 == null) { obj2 = "An unknown plugin"; } string str1 = obj2; Interface.Oxide.LogError("{0} tried to register command '{1}', this command already exists and cannot be overridden!", new Object[] { str1, rustCommand1 }); return; } if (this.consoleCommands.TryGetValue(rustCommand1, out consoleCommand)) { if (consoleCommand.OriginalCallback != null) { originalCallback.OriginalCallback = consoleCommand.OriginalCallback; } Plugin plugin1 = consoleCommand.Callback.Plugin; if (plugin1 != null) { obj1 = plugin1.Name; } else { obj1 = null; } if (obj1 == null) { obj1 = "an unknown plugin"; } string str2 = obj1; if (plugin != null) { name2 = plugin.Name; } else { name2 = null; } if (name2 == null) { name2 = "An unknown plugin"; } string str3 = name2; string str4 = String.Concat(new String[] { str3, " has replaced the '", command, "' console command previously registered by ", str2 }); Interface.Oxide.LogWarning(str4, Array.Empty <object>()); ConsoleSystem.Index.Server.Dict.Remove(consoleCommand.RustCommand.FullName); if (str == "global") { ConsoleSystem.Index.Server.GlobalDict.Remove(consoleCommand.RustCommand.Name); } ConsoleSystem.Index.All = ConsoleSystem.Index.Server.Dict.Values.ToArray <ConsoleSystem.Command>(); } if (RustCore.Covalence.CommandSystem.registeredCommands.TryGetValue((str == "global" ? rustCommand : rustCommand1), out registeredCommand)) { if (registeredCommand.OriginalCallback != null) { originalCallback.OriginalCallback = registeredCommand.OriginalCallback; } Plugin source = registeredCommand.Source; if (source != null) { obj = source.Name; } else { obj = null; } if (obj == null) { obj = "an unknown plugin"; } string str5 = obj; if (plugin != null) { name1 = plugin.Name; } else { name1 = null; } if (name1 == null) { name1 = "An unknown plugin"; } string str6 = name1; string str7 = String.Concat(new String[] { str6, " has replaced the '", rustCommand1, "' command previously registered by ", str5 }); Interface.Oxide.LogWarning(str7, Array.Empty <object>()); RustCore.Covalence.CommandSystem.UnregisterCommand((str == "global" ? rustCommand : rustCommand1), registeredCommand.Source); } originalCallback.AddCallback(plugin, callback); if (ConsoleSystem.Index.Server.Dict.TryGetValue(rustCommand1, out command1)) { if (command1.Variable) { if (plugin != null) { name = plugin.Name; } else { name = null; } if (name == null) { name = "An unknown plugin"; } string str8 = name; Interface.Oxide.LogError(String.Concat(str8, " tried to register the ", rustCommand, " console variable as a command!"), Array.Empty <object>()); return; } originalCallback.OriginalCallback = command1.Call; } ConsoleSystem.Index.Server.Dict[rustCommand1] = originalCallback.RustCommand; if (str == "global") { ConsoleSystem.Index.Server.GlobalDict[rustCommand] = originalCallback.RustCommand; } ConsoleSystem.Index.All = ConsoleSystem.Index.Server.Dict.Values.ToArray <ConsoleSystem.Command>(); this.consoleCommands[rustCommand1] = originalCallback; }