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

Last change on this file since 323 was 306, checked in by alloc, 7 years ago

Fixes update A16.2

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