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

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

Binary improvements

File size: 3.4 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
[230]6 public class RemoveLandProtection : ConsoleCmdAbstract
[224]7 {
[230]8 public override string GetDescription ()
[224]9 {
10 return "removes the association of a land protection block to the owner";
11 }
12
[230]13 public override string[] GetCommands ()
[224]14 {
15 return new string[] { "removelandprotection", "rlp" };
16 }
17
18 private void removeById (string _id)
19 {
20 try {
[230]21 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]22
23 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) {
[230]24 SdtdConsole.Instance.Output ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones.");
[224]25 return;
26 }
27 if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {
[230]28 SdtdConsole.Instance.Output ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones.");
[224]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 }
[230]37 GameManager.Instance.SetBlocksRPC (changes);
[224]38
[230]39 SdtdConsole.Instance.Output ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+
[224]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:");
[230]42 SdtdConsole.Instance.Output(" listlandprotection " + _id);
[224]43 } catch (Exception e) {
44 Log.Out ("Error in RemoveLandProtection.removeById: " + e);
45 }
46 }
47
[230]48 private void removeByPosition (List<string> _coords)
[224]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) {
[230]59 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
[224]60 return;
61 }
62
63 Vector3i v = new Vector3i (x, y, z);
64
[230]65 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]66
67 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
68 if (d == null || !d.ContainsKey (v)) {
[230]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.");
[224]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
[230]78 GameManager.Instance.SetBlocksRPC (changes);
[224]79
[230]80 SdtdConsole.Instance.Output ("Land protection block at (" + v.ToString () + ") removed");
[224]81 } catch (Exception e) {
82 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
83 }
84 }
85
[230]86 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]87 {
88 try {
[230]89 if (_params.Count == 1) {
[224]90 removeById (_params [0]);
[230]91 } else if (_params.Count == 3) {
[224]92 removeByPosition (_params);
93 } else {
[230]94 SdtdConsole.Instance.Output ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
[224]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.