[224] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
| 4 | namespace AllocsFixes.CustomCommands
|
---|
| 5 | {
|
---|
[230] | 6 | public class ListLandProtection : ConsoleCmdAbstract
|
---|
[224] | 7 | {
|
---|
[230] | 8 | public override string GetDescription ()
|
---|
[224] | 9 | {
|
---|
| 10 | return "lists all land protection blocks and owners";
|
---|
| 11 | }
|
---|
| 12 |
|
---|
[230] | 13 | public override string[] GetCommands ()
|
---|
[224] | 14 | {
|
---|
| 15 | return new string[] { "listlandprotection", "llp" };
|
---|
| 16 | }
|
---|
| 17 |
|
---|
[230] | 18 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
---|
[224] | 19 | {
|
---|
| 20 | try {
|
---|
[230] | 21 | if (_senderInfo.RemoteClientInfo != null) {
|
---|
| 22 | if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
|
---|
| 23 | _params.Add (_senderInfo.RemoteClientInfo.playerId);
|
---|
| 24 | }
|
---|
[224] | 25 | }
|
---|
| 26 |
|
---|
[230] | 27 | World w = GameManager.Instance.World;
|
---|
| 28 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
[224] | 29 |
|
---|
| 30 | bool summaryOnly = false;
|
---|
| 31 | string steamIdFilter = string.Empty;
|
---|
| 32 | Vector3i closeTo = default(Vector3i);
|
---|
| 33 | bool onlyCloseToPlayer = false;
|
---|
| 34 | int closeToDistance = 32;
|
---|
| 35 |
|
---|
[230] | 36 | if (_params.Count == 1) {
|
---|
[224] | 37 | long tempLong;
|
---|
| 38 |
|
---|
| 39 | if (_params [0].ToLower ().Equals ("summary")) {
|
---|
| 40 | summaryOnly = true;
|
---|
| 41 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
|
---|
| 42 | steamIdFilter = _params [0];
|
---|
| 43 | } else {
|
---|
[230] | 44 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
[224] | 45 | if (ci != null) {
|
---|
[230] | 46 | steamIdFilter = ci.playerId;
|
---|
[224] | 47 | } else {
|
---|
[230] | 48 | SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
[224] | 49 | return;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
[230] | 52 | } else if (_params.Count >= 2) {
|
---|
[224] | 53 | if (_params [0].ToLower ().Equals ("nearby")) {
|
---|
| 54 | try {
|
---|
[230] | 55 | if (_params.Count == 3) {
|
---|
[224] | 56 | if (!int.TryParse (_params[1], out closeToDistance)) {
|
---|
[230] | 57 | SdtdConsole.Instance.Output ("Given radius is not an integer!");
|
---|
[224] | 58 | }
|
---|
| 59 | }
|
---|
[230] | 60 | ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
|
---|
| 61 | EntityPlayer ep = w.Players.dict [ci.entityId];
|
---|
[224] | 62 | closeTo = new Vector3i (ep.GetPosition ());
|
---|
| 63 | onlyCloseToPlayer = true;
|
---|
| 64 | } catch (Exception e) {
|
---|
[230] | 65 | SdtdConsole.Instance.Output ("Error getting current player's position");
|
---|
[224] | 66 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
| 67 | }
|
---|
| 68 | } else {
|
---|
[230] | 69 | SdtdConsole.Instance.Output ("Illegal parameter list");
|
---|
[224] | 70 | return;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
|
---|
| 75 | if (d != null) {
|
---|
| 76 | Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
|
---|
| 77 | foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
|
---|
| 78 | if (!onlyCloseToPlayer || (Math.Abs (kvp.Key.x - closeTo.x) <= closeToDistance && Math.Abs (kvp.Key.z - closeTo.z) <= closeToDistance)) {
|
---|
| 79 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
| 80 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
| 81 | }
|
---|
| 82 | owners [kvp.Value].Add (kvp.Key);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
| 87 | if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
|
---|
| 88 | string name = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId].Name;
|
---|
| 89 | name += " (" + kvp.Key.PlayerId + ")";
|
---|
| 90 |
|
---|
[230] | 91 | SdtdConsole.Instance.Output (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));
|
---|
[224] | 92 | if (!summaryOnly) {
|
---|
| 93 | foreach (Vector3i v in kvp.Value) {
|
---|
[230] | 94 | SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
|
---|
[224] | 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (steamIdFilter.Length == 0)
|
---|
[230] | 102 | SdtdConsole.Instance.Output ("Total of " + d.Count + " keystones in the game");
|
---|
[224] | 103 | } catch (Exception e) {
|
---|
| 104 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|