| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 |
|
|---|
| 4 | public class RemoveLandProtection : ConsoleCommand
|
|---|
| 5 | {
|
|---|
| 6 | public RemoveLandProtection (ConsoleSdtd cons) : base(cons)
|
|---|
| 7 | {
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | public override string Description ()
|
|---|
| 11 | {
|
|---|
| 12 | return "removes the association of a land protection block to the owner";
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | public override string[] Names ()
|
|---|
| 16 | {
|
|---|
| 17 | return new string[] { "removelandprotection", "rlp" };
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | private void removeById (string _id)
|
|---|
| 21 | {
|
|---|
| 22 | try {
|
|---|
| 23 | PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
|
|---|
| 24 |
|
|---|
| 25 | if (_id.Length < 1 || !ppl.Players.ContainsKey(_id)) {
|
|---|
| 26 | m_Console.SendResult ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones.");
|
|---|
| 27 | return;
|
|---|
| 28 | }
|
|---|
| 29 | if (ppl.Players[_id].LPBlocks == null || ppl.Players[_id].LPBlocks.Count == 0) {
|
|---|
| 30 | m_Console.SendResult ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones.");
|
|---|
| 31 | return;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
|
|---|
| 35 | foreach (Vector3i pos in ppl.Players[_id].LPBlocks) {
|
|---|
| 36 | BlockChangeInfo bci = new BlockChangeInfo (pos, 0, true);
|
|---|
| 37 | changes.Add (bci);
|
|---|
| 38 | }
|
|---|
| 39 | CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);
|
|---|
| 40 |
|
|---|
| 41 | m_Console.SendResult ("#"+changes.Count + " Land protection blocks for player \"" + _id + "\" removed");
|
|---|
| 42 | } catch (Exception e) {
|
|---|
| 43 | Log.Out ("Error in RemoveLandProtection.removeById: " + e);
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | private void removeByPosition (string[] _coords)
|
|---|
| 48 | {
|
|---|
| 49 | try {
|
|---|
| 50 | int x = int.MinValue;
|
|---|
| 51 | int.TryParse (_coords [0], out x);
|
|---|
| 52 | int y = int.MinValue;
|
|---|
| 53 | int.TryParse (_coords [1], out y);
|
|---|
| 54 | int z = int.MinValue;
|
|---|
| 55 | int.TryParse (_coords [2], out z);
|
|---|
| 56 |
|
|---|
| 57 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
|---|
| 58 | m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
|
|---|
| 59 | return;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Vector3i v = new Vector3i (x, y, z);
|
|---|
| 63 |
|
|---|
| 64 | PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
|
|---|
| 65 |
|
|---|
| 66 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
|
|---|
| 67 | if (d == null || !d.ContainsKey (v)) {
|
|---|
| 68 | m_Console.SendResult ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones.");
|
|---|
| 69 | return;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | BlockChangeInfo bci = new BlockChangeInfo (v, 0, true);
|
|---|
| 73 |
|
|---|
| 74 | List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
|
|---|
| 75 | changes.Add (bci);
|
|---|
| 76 |
|
|---|
| 77 | CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);
|
|---|
| 78 |
|
|---|
| 79 | m_Console.SendResult ("Land protection block at (" + v.ToString () + ") removed");
|
|---|
| 80 | } catch (Exception e) {
|
|---|
| 81 | Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | public override void Run (string[] _params)
|
|---|
| 86 | {
|
|---|
| 87 | try {
|
|---|
| 88 | if (_params.Length == 1) {
|
|---|
| 89 | removeById (_params [0]);
|
|---|
| 90 | } else if (_params.Length == 3) {
|
|---|
| 91 | removeByPosition (_params);
|
|---|
| 92 | } else {
|
|---|
| 93 | m_Console.SendResult ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
|
|---|
| 94 | }
|
|---|
| 95 | } catch (Exception e) {
|
|---|
| 96 | Log.Out ("Error in RemoveLandProtection.Run: " + e);
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|