Exemplo n.º 1
0
        /// <summary>
        /// Handles the plugin console command.
        /// </summary>
        /// <param name="e"></param>
        private void OnPluginCommand(ConsoleCommandArgs e)
        {
            if (e.Arguments.Count == 3 && e.Arguments[1].ToLower() == "load")
            {
                // Attempt to load the given plugin..
                var ret = DetoxPluginManager.LoadPlugin(e.Arguments[2].ToLower());
                if (ret != 0)
                {
                    this.LogConsoleMessage(new DetoxAPI.ConsoleMessage(string.Format(
                        "Failed to load plugin: {0} -- {1}",
                        e.Arguments[2].ToLower(), DetoxPluginErrorReason.ErrorStrings[(int)ret]), ConsoleMessageType.Error));
                }
            }
            else if (e.Arguments.Count == 2 && e.Arguments[1].ToLower() == "list")
            {
                var plugins = DetoxPluginManager.Plugins.OrderBy(p => p.Plugin.Name).ToList();
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("Loaded plugins:", ConsoleMessageType.About));
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("----------------------------------------------------", ConsoleMessageType.About));
                plugins.ForEach(p => this.LogConsoleMessage(new DetoxAPI.ConsoleMessage(string.Format(
                    " {0} v{1} by {2} -- {3}", p.Plugin.Name, p.Plugin.Version, p.Plugin.Author, p.Plugin.Description), ConsoleMessageType.Warning)));
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage(string.Format("{0} loaded plugins.", plugins.Count), ConsoleMessageType.About));
            }
            else
            {
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("Invalid command syntax; valid plugin commands are:", ConsoleMessageType.Error));
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("  /plugin load [pluginname]", ConsoleMessageType.Error));
                this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("  /plugin list", ConsoleMessageType.Error));
            }

            e.Handled = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the help console command.
        /// </summary>
        /// <param name="e"></param>
        private void OnHelpCommand(ConsoleCommandArgs e)
        {
            // Sort the console commands by primary name..
            var cmds = DetoxAPI.ConsoleCommands.Commands.OrderBy(c => c.Name).ToList();

            // Print each command..
            this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("Registered console commands:", ConsoleMessageType.About));
            this.LogConsoleMessage(new DetoxAPI.ConsoleMessage("----------------------------------------------------", ConsoleMessageType.About));
            cmds.ForEach(c => this.LogConsoleMessage(new DetoxAPI.ConsoleMessage(string.Format("    /{0} - {1} [{2}]", c.Name, c.Description, string.Join(", ", c.Names)), ConsoleMessageType.Warning)));
            this.LogConsoleMessage(new DetoxAPI.ConsoleMessage(string.Format("{0} total console commands.", cmds.Count), ConsoleMessageType.About));

            e.Handled = true;
        }
Exemplo n.º 3
0
 void OnGiveCommand(ConsoleCommandArgs args)
 {
     if (args.Arguments.Count > 1)
     {
         var allItemNames = Terraria.GetMainField<string[]>("itemName");
         var itemIds = new List<int>();
         var player = DetoxPlayers.LocalPlayer;
         int successes = 0;
         for (int i = 1; i < args.Arguments.Count; i += 2)
         {
             var itemId = GetItemId(args.Arguments[i]);
             var count = -1;
             if (itemId != -1)
             {
                 if (Int32.TryParse(args.Arguments[i + 1], out count))
                 {
                     for (int j = 0; j < count; j++)
                     {
                         player.Invoke("PutItemInInventory", itemId, -1);
                     }
                     successes++;
                 }
                 else
                 {
                     Console.PrintConsole(args.Arguments[i + 1] + " is not a valid integer!", ConsoleMessageType.Warning);
                 }
             }
             else
             {
                 Console.PrintConsole("Item \"" + args.Arguments[i] + "\" not found!", ConsoleMessageType.Warning);
             }
         }
         if (successes > 0)
         {
             Console.PrintConsole("Put " + successes + " item" + (successes > 1 ? "s" : "") + "into your inventory!", ConsoleMessageType.About);
         }
         else
         {
             Console.PrintConsole("Couldn't put any item into your inventory.", ConsoleMessageType.Warning);
         }
     }
     else
     {
         Console.PrintConsole("No item specified!", ConsoleMessageType.Error);
         Console.PrintConsole("Usage: /give <item1> <count1> (<item2> <count2> ...)", ConsoleMessageType.Normal);
     }
     args.Handled = true;
 }
Exemplo n.º 4
0
 void OnTimeCommand(ConsoleCommandArgs args)
 {
     args.Handled = true;
     if (args.Arguments.Count == 2)
     {
         double time;
         if (Double.TryParse(args.Arguments[1], out time))
         {
             Terraria.SetMainField("time", time);
             Console.PrintConsole("Time set!", ConsoleMessageType.About);
         }
         else
         {
             Console.PrintConsole("Invalid time specified!", ConsoleMessageType.Error);
             Console.PrintConsole("Usage: /time <time>", ConsoleMessageType.Normal);
         }
     }
     else
     {
         Console.PrintConsole("No time specified!", ConsoleMessageType.Error);
         Console.PrintConsole("Usage: /time <time>", ConsoleMessageType.Normal);
     }
 }
Exemplo n.º 5
0
 void OnGridCommand(ConsoleCommandArgs args)
 {
     buildgrid = !buildgrid;
     Console.PrintConsole("Building grid toggled", ConsoleMessageType.About);
     args.Handled = true;
 }
Exemplo n.º 6
0
 void OnGodmodeCommand(ConsoleCommandArgs args)
 {
     godmode = !godmode;
     Console.PrintConsole("Godmode toggled", ConsoleMessageType.About);
     args.Handled = true;
 }