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

Last change on this file since 268 was 253, checked in by alloc, 9 years ago

Fixes 6_8_10

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