- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/AllocsCommands/Commands/RemoveLandProtection.cs
r306 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using AllocsFixes.PersistentData; 3 4 4 namespace AllocsFixes.CustomCommands 5 { 6 public class RemoveLandProtection : ConsoleCmdAbstract 7 { 8 public override string GetDescription () 9 { 5 namespace AllocsFixes.CustomCommands { 6 public class RemoveLandProtection : ConsoleCmdAbstract { 7 public override string GetDescription () { 10 8 return "removes the association of a land protection block to the owner"; 11 9 } … … 13 11 public override string GetHelp () { 14 12 return "Usage:" + 15 16 17 18 19 20 13 " 1. removelandprotection <steamid>\n" + 14 " 2. removelandprotection <x> <y> <z>\n" + 15 " 3. removelandprotection nearby [length]\n" + 16 "1. Remove all land claims owned by the user with the given SteamID\n" + 17 "2. Remove only the claim block on the exactly given block position\n" + 18 "3. Remove all claims in a square with edge length of 64 (or the optionally specified size) around the executing player"; 21 19 } 22 20 23 public override string[] GetCommands () 24 { 25 return new string[] { "removelandprotection", "rlp" }; 21 public override string[] GetCommands () { 22 return new[] {"removelandprotection", "rlp"}; 26 23 } 27 24 28 private void removeById (string _id) 29 { 25 private void removeById (string _id) { 30 26 try { 31 27 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList (); 32 28 33 29 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) { 34 SdtdConsole.Instance.Output ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 30 SdtdConsole.Instance.Output ( 31 "Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 35 32 return; 36 33 } 34 37 35 if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) { 38 SdtdConsole.Instance.Output ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); 36 SdtdConsole.Instance.Output ( 37 "Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); 39 38 return; 40 39 } 41 40 42 41 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 43 foreach (Vector3i pos in ppl.Players [_id].LPBlocks) {42 foreach (Vector3i pos in ppl.Players [_id].LPBlocks) { 44 43 BlockChangeInfo bci = new BlockChangeInfo (pos, new BlockValue (0), true, false); 45 44 changes.Add (bci); 46 45 } 46 47 47 GameManager.Instance.SetBlocksRPC (changes); 48 48 49 SdtdConsole.Instance.Output ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+ 50 "that only blocks in chunks that are currently loaded (close to any player) could be removed. "+ 51 "Please check for remaining blocks by running:"); 52 SdtdConsole.Instance.Output(" listlandprotection " + _id); 49 SdtdConsole.Instance.Output ("Tried to remove #" + changes.Count + 50 " land protection blocks for player \"" + _id + "\". Note " + 51 "that only blocks in chunks that are currently loaded (close to any player) could be removed. " + 52 "Please check for remaining blocks by running:"); 53 SdtdConsole.Instance.Output (" listlandprotection " + _id); 53 54 } catch (Exception e) { 54 55 Log.Out ("Error in RemoveLandProtection.removeById: " + e); … … 56 57 } 57 58 58 private void removeByPosition (List<string> _coords) 59 { 59 private void removeByPosition (List<string> _coords) { 60 60 try { 61 61 int x = int.MinValue; … … 77 77 Dictionary<Vector3i, PersistentPlayerData> d = ppl.m_lpBlockMap; 78 78 if (d == null || !d.ContainsKey (v)) { 79 SdtdConsole.Instance.Output ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones."); 79 SdtdConsole.Instance.Output ( 80 "No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones."); 80 81 return; 81 82 } … … 88 89 GameManager.Instance.SetBlocksRPC (changes); 89 90 90 SdtdConsole.Instance.Output ("Land protection block at (" + v .ToString ()+ ") removed");91 SdtdConsole.Instance.Output ("Land protection block at (" + v + ") removed"); 91 92 } catch (Exception e) { 92 93 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e); … … 94 95 } 95 96 96 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) 97 { 97 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 98 98 try { 99 99 if (_senderInfo.RemoteClientInfo != null) { … … 107 107 int closeToDistance = 32; 108 108 if (_params.Count == 3) { 109 if (!int.TryParse (_params [1], out closeToDistance)) {109 if (!int.TryParse (_params [1], out closeToDistance)) { 110 110 SdtdConsole.Instance.Output ("Given length is not an integer!"); 111 111 return; 112 112 } 113 113 114 closeToDistance /= 2; 114 115 } 116 115 117 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]); 116 118 EntityPlayer ep = GameManager.Instance.World.Players.dict [ci.entityId]; 117 119 Vector3i closeTo = new Vector3i (ep.GetPosition ()); 118 LandClaimList.PositionFilter[] posFilters = new LandClaimList.PositionFilter[] { LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance) }; 119 Dictionary<PersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 120 LandClaimList.PositionFilter[] posFilters = 121 {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)}; 122 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 120 123 121 124 try { 122 125 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 123 foreach (KeyValuePair<P ersistentData.Player, List<Vector3i>> kvp in claims) {126 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 124 127 foreach (Vector3i v in kvp.Value) { 125 128 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); … … 127 130 } 128 131 } 132 129 133 GameManager.Instance.SetBlocksRPC (changes); 130 134 } catch (Exception e) { 131 135 SdtdConsole.Instance.Output ("Error removing claims"); 132 136 Log.Out ("Error in RemoveLandProtection.Run: " + e); 133 return;134 137 } 135 138 } catch (Exception e) { 136 139 SdtdConsole.Instance.Output ("Error getting current player's position"); 137 140 Log.Out ("Error in RemoveLandProtection.Run: " + e); 138 return;139 141 } 140 142 } else if (_params.Count == 1) {
Note:
See TracChangeset
for help on using the changeset viewer.