[113] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[130] | 4 | namespace AllocsFixes.CustomCommands
|
---|
[113] | 5 | {
|
---|
[130] | 6 | public class ListLandProtection : ConsoleCommand
|
---|
[113] | 7 | {
|
---|
[130] | 8 | public ListLandProtection (ConsoleSdtd cons) : base(cons)
|
---|
| 9 | {
|
---|
| 10 | }
|
---|
[113] | 11 |
|
---|
[130] | 12 | public override string Description ()
|
---|
| 13 | {
|
---|
| 14 | return "lists all land protection blocks and owners";
|
---|
| 15 | }
|
---|
[113] | 16 |
|
---|
[130] | 17 | public override string[] Names ()
|
---|
| 18 | {
|
---|
| 19 | return new string[] { "listlandprotection", "llp" };
|
---|
| 20 | }
|
---|
[113] | 21 |
|
---|
[130] | 22 | public override void Run (string[] _params)
|
---|
| 23 | {
|
---|
| 24 | try {
|
---|
| 25 | World w = CommonMappingFunctions.GetGameManager ().World;
|
---|
| 26 | PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
|
---|
[113] | 27 |
|
---|
[139] | 28 | bool summaryOnly = false;
|
---|
| 29 | string steamIdFilter = string.Empty;
|
---|
| 30 |
|
---|
| 31 | if (_params.Length == 1) {
|
---|
| 32 | long tempLong;
|
---|
| 33 |
|
---|
| 34 | if (_params [0].ToLower ().Equals ("summary")) {
|
---|
| 35 | summaryOnly = true;
|
---|
| 36 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
|
---|
| 37 | steamIdFilter = _params [0];
|
---|
| 38 | } else {
|
---|
| 39 | ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true);
|
---|
| 40 | if (ci != null) {
|
---|
| 41 | steamIdFilter = CommonMappingFunctions.GetSteamID (ci);
|
---|
| 42 | } else {
|
---|
| 43 | m_Console.SendResult ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
| 44 | return;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[130] | 49 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
|
---|
| 50 | if (d != null) {
|
---|
| 51 | Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
|
---|
| 52 | foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
|
---|
| 53 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
| 54 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
| 55 | }
|
---|
| 56 | owners [kvp.Value].Add (kvp.Key);
|
---|
[113] | 57 | }
|
---|
| 58 |
|
---|
[130] | 59 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
[139] | 60 | if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
|
---|
[146] | 61 | string name = PersistentData.PersistentContainer.Instance.Players[kvp.Key.PlayerId].Name;
|
---|
[139] | 62 | name += " (" + kvp.Key.PlayerId + ")";
|
---|
[113] | 63 |
|
---|
[139] | 64 | 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));
|
---|
| 65 | if (!summaryOnly) {
|
---|
| 66 | foreach (Vector3i v in kvp.Value) {
|
---|
| 67 | m_Console.SendResult (" (" + v.ToString () + ")");
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
[130] | 70 | }
|
---|
[113] | 71 | }
|
---|
| 72 | }
|
---|
[130] | 73 |
|
---|
[139] | 74 | if (steamIdFilter.Length == 0)
|
---|
| 75 | m_Console.SendResult ("Total of " + d.Count + " keystones in the game");
|
---|
[130] | 76 | } catch (Exception e) {
|
---|
| 77 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
[113] | 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|