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

Last change on this file since 226 was 224, checked in by alloc, 10 years ago

A11 preps

File size: 3.4 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace 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 ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+
44 "that only blocks in chunks that are currently loaded (close to any player) could be removed. "+
45 "Please check for remaining blocks by running:");
46 m_Console.SendResult(" listlandprotection " + _id);
47 } catch (Exception e) {
48 Log.Out ("Error in RemoveLandProtection.removeById: " + e);
49 }
50 }
51
52 private void removeByPosition (string[] _coords)
53 {
54 try {
55 int x = int.MinValue;
56 int.TryParse (_coords [0], out x);
57 int y = int.MinValue;
58 int.TryParse (_coords [1], out y);
59 int z = int.MinValue;
60 int.TryParse (_coords [2], out z);
61
62 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
63 m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
64 return;
65 }
66
67 Vector3i v = new Vector3i (x, y, z);
68
69 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
70
71 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
72 if (d == null || !d.ContainsKey (v)) {
73 m_Console.SendResult ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones.");
74 return;
75 }
76
77 BlockChangeInfo bci = new BlockChangeInfo (v, 0, true);
78
79 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
80 changes.Add (bci);
81
82 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);
83
84 m_Console.SendResult ("Land protection block at (" + v.ToString () + ") removed");
85 } catch (Exception e) {
86 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
87 }
88 }
89
90 public override void Run (string[] _params)
91 {
92 try {
93 if (_params.Length == 1) {
94 removeById (_params [0]);
95 } else if (_params.Length == 3) {
96 removeByPosition (_params);
97 } else {
98 m_Console.SendResult ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
99 }
100 } catch (Exception e) {
101 Log.Out ("Error in RemoveLandProtection.Run: " + e);
102 }
103 }
104 }
105}
Note: See TracBrowser for help on using the repository browser.