source: binary-improvements/AllocsCommands/Commands/ListItems.cs@ 409

Last change on this file since 409 was 359, checked in by alloc, 5 years ago

Removed unnecessary try-catch-blocks from commands (command handler catches exceptions anyway and provides more detailed output)

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands {
5 public class ListItems : ConsoleCmdAbstract {
6 public override string GetDescription () {
7 return "lists all items that contain the given substring";
8 }
9
10 public override string[] GetCommands () {
11 return new[] {"listitems", "li"};
12 }
13
14 public override string GetHelp () {
15 return "List all available item names\n" +
16 "Usage:\n" +
17 " 1. listitems <searchString>\n" +
18 " 2. listitems *\n" +
19 "1. List only names that contain the given string.\n" +
20 "2. List all names.";
21 }
22
23 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
24 if (_params.Count != 1 || _params [0].Length == 0) {
25 SdtdConsole.Instance.Output ("Usage: listitems <searchString>");
26 return;
27 }
28
29 int count = ItemClass.ItemNames.Count;
30 bool showAll = _params [0].Trim ().Equals ("*");
31
32 int listed = 0;
33 for (int i = 0; i < count; i++) {
34 string s = ItemClass.ItemNames [i];
35 if (showAll || s.IndexOf (_params [0], StringComparison.OrdinalIgnoreCase) >= 0) {
36 SdtdConsole.Instance.Output (" " + s);
37 listed++;
38 }
39 }
40
41 SdtdConsole.Instance.Output ("Listed " + listed + " matching items.");
42 }
43 }
44}
Note: See TracBrowser for help on using the repository browser.