source: binary-improvements/AllocsCommands/Commands/RemoveLandProtection.cs@ 235

Last change on this file since 235 was 230, checked in by alloc, 10 years ago

Binary improvements

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