ModernUO/Projects/UOContent/Commands
Kamron Batman f4a87a8629
fix: Fixes adding items with ambiguous type lookup (#2307)
Fix [add command failing with ambiguous type names + refactor for performance

### Problem

[add blight would fail with "No type with that name was found" because multiple types contain "blight" (e.g., Server.Items.Blight, Server.Ethics.Evil.Blight, Server.Items.BlightGrippedLongbow, Server.Items.QuiverOfBlight). The old code only succeeded when exactly one type matched the search regardless of constructability and inheriting Mobi les/Items.

### Solution

Exact match takes priority: If a type's name exactly equals the search string (case-insensitive), use it directly. Otherwise, show the AddGump with all partial matches.

- [add blight → Creates Blight (exact name match)
- [add bligh → Shows gump with Blight, BlightGrippedLongbow, etc.

### Refactoring

- CommandEventArgs context: Added GetContext<T>/SetContext<T> to pass resolved type through the command chain without method signature changes
- Removed TrySetupTarget duplication: Validation now happens only in ValidateArgs, eliminating redundant code paths
- Split type matching:
  - ExactMatch(string) → Returns Type for exact name match (used by [add)
  - MatchEmptyCtor(string) → Returns ConstructorInfo[] for gump display (empty-callable constructors only)

### Memory & Performance Improvements

| Optimization                  | Benefit                                                                                      |
|-------------------------------|----------------------------------------------------------------------------------------------|
| _mobileItemTypes cache        | Filters Mobile/Item types once per assembly, reused on all subsequent searches               |
| ReadOnlySpan<string> for args | Avoids string[] heap allocations when slicing arguments                                      |
| ValueStringBuilder            | Stack-allocated string building, avoids StringBuilder heap allocation                        |
| Single type resolution        | Type resolved once in ValidateArgs, passed via context to Execute (was resolved 2-3x before) |
2026-01-06 21:21:29 -08:00
..
Generic fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Object Creation fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
AddonGenerator.cs chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Batch.cs fix: Cleans up FixHtml (#1757) 2024-05-03 21:24:31 -07:00
BoundingBoxPicker.cs chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
ClearCommands.cs feat: Adds ClearXY command (#2229) 2025-07-06 20:15:50 -07:00
DragEffects.cs fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Dupe.cs fix: Fixes duping bags (#2148) 2025-04-07 22:27:41 -07:00
ExportWSC.cs fix: Fixes missing methods. Adds more admin gump world building (#1675) 2024-02-10 20:31:25 -08:00
GenCommands.cs feat: Adds Network Packet Documentation (#2302) 2026-01-01 17:52:56 -08:00
Handlers.cs fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
HelpInfo.cs feat: Adds grid support for the DynamicGump system (#2306) 2026-01-03 10:12:22 -08:00
LocationCommand.cs chore: Cleans up pattern checks. (#892) 2021-12-24 15:53:59 -08:00
Logging.cs fix: Update LabelTo, SendMessage, etc to Interpolated Strings (#1283) 2022-11-28 19:58:12 -08:00
Properties.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
ResetLocalization.cs fix: Fixes language casing and adds localization reset command (#1703) 2024-03-09 11:02:56 -08:00
ResetRng.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
ResetStaffDress.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
ShardTime.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
SignParser.cs fix: Fixes GetInRange to use GetAt instead (#1768) 2024-05-09 14:01:25 -07:00
Skills.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
SkillsMenu.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00
StaffAccess.cs chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
VisibilityList.cs feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00
Wipe.cs fix: Adds command help, webpage, and fixes issues with other commands (#1669) 2024-02-10 00:19:19 -08:00