source: TFP-WebServer/CommandExtensions/src/Commands/ListItems.cs@ 493

Last change on this file since 493 was 487, checked in by alloc, 5 months ago

1.1.0.1 Release for V 1.0

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