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