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

Last change on this file since 302 was 266, checked in by alloc, 9 years ago

Fix RLP

File size: 3.8 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 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
21 public override string[] GetCommands ()
22 {
23 return new string[] { "removelandprotection", "rlp" };
24 }
25
26 private void removeById (string _id)
27 {
28 try {
29 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
30
31 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) {
32 SdtdConsole.Instance.Output ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones.");
33 return;
34 }
35 if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {
36 SdtdConsole.Instance.Output ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones.");
37 return;
38 }
39
40 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
41 foreach (Vector3i pos in ppl.Players[_id].LPBlocks) {
42 BlockChangeInfo bci = new BlockChangeInfo (pos, new BlockValue (0), true, false);
43 changes.Add (bci);
44 }
45 GameManager.Instance.SetBlocksRPC (changes);
46
47 SdtdConsole.Instance.Output ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+
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:");
50 SdtdConsole.Instance.Output(" listlandprotection " + _id);
51 } catch (Exception e) {
52 Log.Out ("Error in RemoveLandProtection.removeById: " + e);
53 }
54 }
55
56 private void removeByPosition (List<string> _coords)
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) {
67 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
68 return;
69 }
70
71 Vector3i v = new Vector3i (x, y, z);
72
73 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
74
75 Dictionary<Vector3i, PersistentPlayerData> d = ppl.m_lpBlockMap;
76 if (d == null || !d.ContainsKey (v)) {
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.");
78 return;
79 }
80
81 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false);
82
83 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
84 changes.Add (bci);
85
86 GameManager.Instance.SetBlocksRPC (changes);
87
88 SdtdConsole.Instance.Output ("Land protection block at (" + v.ToString () + ") removed");
89 } catch (Exception e) {
90 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
91 }
92 }
93
94 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
95 {
96 try {
97 if (_params.Count == 1) {
98 removeById (_params [0]);
99 } else if (_params.Count == 3) {
100 removeByPosition (_params);
101 } else {
102 SdtdConsole.Instance.Output ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
103 }
104 } catch (Exception e) {
105 Log.Out ("Error in RemoveLandProtection.Run: " + e);
106 }
107 }
108 }
109}
Note: See TracBrowser for help on using the repository browser.