source: binary-improvements/AllocsCommands/Commands/ListLandProtection.cs@ 367

Last change on this file since 367 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: 4.5 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
[325]3using AllocsFixes.PersistentData;
[224]4
[325]5namespace AllocsFixes.CustomCommands {
6 public class ListLandProtection : ConsoleCmdAbstract {
7 public override string GetDescription () {
[224]8 return "lists all land protection blocks and owners";
9 }
10
[238]11 public override string GetHelp () {
12 return "Usage:\n" +
[325]13 " 1. listlandprotection summary\n" +
14 " 2. listlandprotection <steam id / player name / entity id> [parseable]\n" +
15 " 3. listlandprotection nearby [length]\n" +
16 "1. Lists only players that own claimstones, the number they own and the protection status\n" +
17 "2. Lists only the claims of the player given by his SteamID / entity id / playername, including the individual claim positions.\n" +
18 " If \"parseable\" is specified the output of the individual claims will be in a format better suited for programmatical readout.\n" +
19 "3. Lists claims in a square with edge length of 64 (or the optionally specified size) around the executing player\n";
[238]20 }
21
[325]22 public override string[] GetCommands () {
23 return new[] {"listlandprotection", "llp"};
[224]24 }
25
[325]26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[359]27 if (_senderInfo.RemoteClientInfo != null) {
28 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {
29 _params.Add (_senderInfo.RemoteClientInfo.playerId);
[224]30 }
[359]31 }
[224]32
[359]33 World w = GameManager.Instance.World;
34 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]35
[359]36 bool summaryOnly = false;
37 string steamIdFilter = string.Empty;
38 Vector3i closeTo = default (Vector3i);
39 bool onlyCloseToPlayer = false;
40 int closeToDistance = 32;
41 bool parseableOutput = false;
[224]42
[359]43 if (_params.Contains ("parseable")) {
44 parseableOutput = true;
45 _params.Remove ("parseable");
46 }
[273]47
[359]48 if (_params.Count == 1) {
49 long tempLong;
[224]50
[359]51 if (_params [0].EqualsCaseInsensitive ("summary")) {
52 summaryOnly = true;
53 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
54 steamIdFilter = _params [0];
55 } else {
56 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
57 if (ci != null) {
58 steamIdFilter = ci.playerId;
[224]59 } else {
[359]60 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
61 return;
[224]62 }
[359]63 }
64 } else if (_params.Count >= 2) {
65 if (_params [0].EqualsCaseInsensitive ("nearby")) {
66 try {
67 if (_params.Count == 3) {
68 if (!int.TryParse (_params [1], out closeToDistance)) {
69 SdtdConsole.Instance.Output ("Given length is not an integer!");
70 return;
[224]71 }
[325]72
[359]73 closeToDistance /= 2;
[224]74 }
[359]75
76 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
77 EntityPlayer ep = w.Players.dict [ci.entityId];
78 closeTo = new Vector3i (ep.GetPosition ());
79 onlyCloseToPlayer = true;
80 } catch (Exception e) {
81 SdtdConsole.Instance.Output ("Error getting current player's position");
82 Log.Out ("Error in ListLandProtection.Run: " + e);
[224]83 return;
84 }
[359]85 } else {
86 SdtdConsole.Instance.Output ("Illegal parameter list");
87 return;
[224]88 }
[359]89 }
[224]90
91
[359]92 LandClaimList.OwnerFilter[] ownerFilters = null;
93 if (!string.IsNullOrEmpty (steamIdFilter)) {
94 ownerFilters = new[] {LandClaimList.SteamIdFilter (steamIdFilter)};
95 }
[325]96
[359]97 LandClaimList.PositionFilter[] posFilters = null;
98 if (onlyCloseToPlayer) {
99 posFilters = new[] {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)};
100 }
[224]101
[359]102 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
[253]103
[359]104 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) {
105 SdtdConsole.Instance.Output (string.Format (
106 "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
107 kvp.Key.Name,
108 kvp.Key.SteamID,
109 kvp.Key.LandProtectionActive,
110 kvp.Key.LandProtectionMultiplier,
111 kvp.Value.Count));
112 if (!summaryOnly) {
113 foreach (Vector3i v in kvp.Value) {
114 if (parseableOutput) {
115 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.SteamID +
116 ", playerName=" + kvp.Key.Name + ", location=" + v);
117 } else {
118 SdtdConsole.Instance.Output (" (" + v + ")");
[224]119 }
120 }
121 }
[359]122 }
[224]123
[359]124 if (string.IsNullOrEmpty (steamIdFilter)) {
125 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
[224]126 }
127 }
128 }
[325]129}
Note: See TracBrowser for help on using the repository browser.