Last change
on this file since 412 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
|
Rev | Line | |
---|
[224] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[325] | 4 | namespace AllocsFixes.CustomCommands {
|
---|
| 5 | public class ListItems : ConsoleCmdAbstract {
|
---|
| 6 | public override string GetDescription () {
|
---|
[224] | 7 | return "lists all items that contain the given substring";
|
---|
| 8 | }
|
---|
| 9 |
|
---|
[325] | 10 | public override string[] GetCommands () {
|
---|
| 11 | return new[] {"listitems", "li"};
|
---|
[224] | 12 | }
|
---|
| 13 |
|
---|
[306] | 14 | public override string GetHelp () {
|
---|
| 15 | return "List all available item names\n" +
|
---|
[325] | 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.";
|
---|
[306] | 21 | }
|
---|
| 22 |
|
---|
[325] | 23 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
[359] | 24 | if (_params.Count != 1 || _params [0].Length == 0) {
|
---|
| 25 | SdtdConsole.Instance.Output ("Usage: listitems <searchString>");
|
---|
| 26 | return;
|
---|
| 27 | }
|
---|
[224] | 28 |
|
---|
[359] | 29 | int count = ItemClass.ItemNames.Count;
|
---|
| 30 | bool showAll = _params [0].Trim ().Equals ("*");
|
---|
[306] | 31 |
|
---|
[359] | 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++;
|
---|
[224] | 38 | }
|
---|
[359] | 39 | }
|
---|
[224] | 40 |
|
---|
[359] | 41 | SdtdConsole.Instance.Output ("Listed " + listed + " matching items.");
|
---|
[224] | 42 | }
|
---|
| 43 | }
|
---|
[325] | 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.