1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | namespace AllocsFixes.CustomCommands
|
---|
5 | {
|
---|
6 | public class ListLandProtection : ConsoleCommand
|
---|
7 | {
|
---|
8 | public ListLandProtection (ConsoleSdtd cons) : base(cons)
|
---|
9 | {
|
---|
10 | }
|
---|
11 |
|
---|
12 | public override string Description ()
|
---|
13 | {
|
---|
14 | return "lists all land protection blocks and owners";
|
---|
15 | }
|
---|
16 |
|
---|
17 | public override string[] Names ()
|
---|
18 | {
|
---|
19 | return new string[] { "listlandprotection", "llp" };
|
---|
20 | }
|
---|
21 |
|
---|
22 | public override void ExecuteRemote (string _sender, string[] _params)
|
---|
23 | {
|
---|
24 | try {
|
---|
25 | if (_params.Length >= 1 && _params [0].ToLower ().Equals ("nearby")) {
|
---|
26 | string[] params2 = new string[_params.Length + 1];
|
---|
27 | for (int i = 0; i < _params.Length; i++)
|
---|
28 | params2 [i] = _params [i];
|
---|
29 | params2 [_params.Length] = _sender;
|
---|
30 | _params = params2;
|
---|
31 | }
|
---|
32 | Run (_params);
|
---|
33 | } catch (Exception e) {
|
---|
34 | Log.Out ("Error in ListLandProtection.ExecuteRemote: " + e);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public override void Run (string[] _params)
|
---|
39 | {
|
---|
40 | try {
|
---|
41 | World w = CommonMappingFunctions.GetGameManager ().World;
|
---|
42 | PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().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.Length == 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 = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true);
|
---|
59 | if (ci != null) {
|
---|
60 | steamIdFilter = CommonMappingFunctions.GetSteamID (ci);
|
---|
61 | } else {
|
---|
62 | m_Console.SendResult ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
63 | return;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | } else if (_params.Length >= 2) {
|
---|
67 | if (_params [0].ToLower ().Equals ("nearby")) {
|
---|
68 | try {
|
---|
69 | if (_params.Length == 3) {
|
---|
70 | if (!int.TryParse (_params[1], out closeToDistance)) {
|
---|
71 | m_Console.SendResult ("Given radius is not an integer!");
|
---|
72 | }
|
---|
73 | }
|
---|
74 | ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_params [_params.Length - 1]);
|
---|
75 | EntityPlayer ep = CommonMappingFunctions.GetEntityPlayer (ci);
|
---|
76 | closeTo = new Vector3i (ep.GetPosition ());
|
---|
77 | onlyCloseToPlayer = true;
|
---|
78 | } catch (Exception e) {
|
---|
79 | m_Console.SendResult ("Error getting current player's position");
|
---|
80 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
81 | }
|
---|
82 | } else {
|
---|
83 | m_Console.SendResult ("Illegal parameter list");
|
---|
84 | return;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
|
---|
89 | if (d != null) {
|
---|
90 | Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
|
---|
91 | foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
|
---|
92 | if (!onlyCloseToPlayer || (Math.Abs (kvp.Key.x - closeTo.x) <= closeToDistance && Math.Abs (kvp.Key.z - closeTo.z) <= closeToDistance)) {
|
---|
93 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
94 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
95 | }
|
---|
96 | owners [kvp.Value].Add (kvp.Key);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
101 | if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
|
---|
102 | string name = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId].Name;
|
---|
103 | name += " (" + kvp.Key.PlayerId + ")";
|
---|
104 |
|
---|
105 | m_Console.SendResult (String.Format ("Player \"{0}\" owns {3} keystones (protected: {1}, current hardness multiplier: {2})", name, w.LandClaimIsActive (kvp.Key), w.LandClaimPower (kvp.Key), kvp.Value.Count));
|
---|
106 | if (!summaryOnly) {
|
---|
107 | foreach (Vector3i v in kvp.Value) {
|
---|
108 | m_Console.SendResult (" (" + v.ToString () + ")");
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (steamIdFilter.Length == 0)
|
---|
116 | m_Console.SendResult ("Total of " + d.Count + " keystones in the game");
|
---|
117 | } catch (Exception e) {
|
---|
118 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|