[224] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
| 4 | namespace AllocsFixes.CustomCommands
|
---|
| 5 | {
|
---|
[230] | 6 | public class RemoveLandProtection : ConsoleCmdAbstract
|
---|
[224] | 7 | {
|
---|
[230] | 8 | public override string GetDescription ()
|
---|
[224] | 9 | {
|
---|
| 10 | return "removes the association of a land protection block to the owner";
|
---|
| 11 | }
|
---|
| 12 |
|
---|
[238] | 13 | public override string GetHelp () {
|
---|
| 14 | return "Usage:" +
|
---|
| 15 | " 1. removelandprotection <steamid>\n" +
|
---|
| 16 | " 2. removelandprotection <x> <y> <z>\n" +
|
---|
| 17 | "1. Remove all land claims owned by the user with the given SteamID\n" +
|
---|
| 18 | "2. Remove only the claim block on the exactly given block position";
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[230] | 21 | public override string[] GetCommands ()
|
---|
[224] | 22 | {
|
---|
| 23 | return new string[] { "removelandprotection", "rlp" };
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | private void removeById (string _id)
|
---|
| 27 | {
|
---|
| 28 | try {
|
---|
[230] | 29 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
[224] | 30 |
|
---|
| 31 | if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) {
|
---|
[230] | 32 | SdtdConsole.Instance.Output ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones.");
|
---|
[224] | 33 | return;
|
---|
| 34 | }
|
---|
| 35 | if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {
|
---|
[230] | 36 | SdtdConsole.Instance.Output ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones.");
|
---|
[224] | 37 | return;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
|
---|
| 41 | foreach (Vector3i pos in ppl.Players[_id].LPBlocks) {
|
---|
[266] | 42 | BlockChangeInfo bci = new BlockChangeInfo (pos, new BlockValue (0), true, false);
|
---|
[224] | 43 | changes.Add (bci);
|
---|
| 44 | }
|
---|
[230] | 45 | GameManager.Instance.SetBlocksRPC (changes);
|
---|
[224] | 46 |
|
---|
[230] | 47 | SdtdConsole.Instance.Output ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+
|
---|
[224] | 48 | "that only blocks in chunks that are currently loaded (close to any player) could be removed. "+
|
---|
| 49 | "Please check for remaining blocks by running:");
|
---|
[230] | 50 | SdtdConsole.Instance.Output(" listlandprotection " + _id);
|
---|
[224] | 51 | } catch (Exception e) {
|
---|
| 52 | Log.Out ("Error in RemoveLandProtection.removeById: " + e);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[230] | 56 | private void removeByPosition (List<string> _coords)
|
---|
[224] | 57 | {
|
---|
| 58 | try {
|
---|
| 59 | int x = int.MinValue;
|
---|
| 60 | int.TryParse (_coords [0], out x);
|
---|
| 61 | int y = int.MinValue;
|
---|
| 62 | int.TryParse (_coords [1], out y);
|
---|
| 63 | int z = int.MinValue;
|
---|
| 64 | int.TryParse (_coords [2], out z);
|
---|
| 65 |
|
---|
| 66 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
---|
[230] | 67 | SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
|
---|
[224] | 68 | return;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | Vector3i v = new Vector3i (x, y, z);
|
---|
| 72 |
|
---|
[230] | 73 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
[224] | 74 |
|
---|
[238] | 75 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.m_lpBlockMap;
|
---|
[224] | 76 | if (d == null || !d.ContainsKey (v)) {
|
---|
[230] | 77 | SdtdConsole.Instance.Output ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones.");
|
---|
[224] | 78 | return;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[266] | 81 | BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false);
|
---|
[224] | 82 |
|
---|
| 83 | List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
|
---|
| 84 | changes.Add (bci);
|
---|
| 85 |
|
---|
[230] | 86 | GameManager.Instance.SetBlocksRPC (changes);
|
---|
[224] | 87 |
|
---|
[230] | 88 | SdtdConsole.Instance.Output ("Land protection block at (" + v.ToString () + ") removed");
|
---|
[224] | 89 | } catch (Exception e) {
|
---|
| 90 | Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[230] | 94 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
---|
[224] | 95 | {
|
---|
| 96 | try {
|
---|
[230] | 97 | if (_params.Count == 1) {
|
---|
[224] | 98 | removeById (_params [0]);
|
---|
[230] | 99 | } else if (_params.Count == 3) {
|
---|
[224] | 100 | removeByPosition (_params);
|
---|
| 101 | } else {
|
---|
[230] | 102 | SdtdConsole.Instance.Output ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
|
---|
[224] | 103 | }
|
---|
| 104 | } catch (Exception e) {
|
---|
| 105 | Log.Out ("Error in RemoveLandProtection.Run: " + e);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | }
|
---|