Advertisement
JimDeadlock

NoRaid

Jan 8th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. using Oxide.Core;
  5. using Oxide.Core.Plugins;
  6. using UnityEngine;
  7. using Oxide.Game.Rust.Cui;
  8.  
  9. // Tweaked for exceptions by RedNicStone ages ago
  10.  
  11. namespace Oxide.Plugins
  12. {
  13. [Info("NoRaid", "Ryan", "1.3.22", ResourceId = 2530)]
  14. [Description("Prevents players destroying buildings of those they're not associated with")]
  15.  
  16. class NoRaid : RustPlugin
  17. {
  18. #region Declaration
  19.  
  20. // Helpers
  21. private string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
  22.  
  23. // Config, instance, plugin references
  24. [PluginReference] private Plugin Friends, Clans;
  25. private static ConfigFile cFile;
  26. private static NoRaid _instance;
  27.  
  28. // Variables
  29. private bool _canWipeRaid;
  30. private bool _canRaid;
  31. private float _startMinutes;
  32.  
  33. // Timers
  34. private Timer _uiTimer;
  35. private Timer _startTimer;
  36. private Timer _wipeCheckTimer;
  37. private Timer _startUiTimer;
  38.  
  39. // Cached dates
  40. private DateTime _cachedWipeTime;
  41. private DateTime _cachedRaidTime;
  42.  
  43. // Active UI players, cached UI container, UI parent constants
  44. private HashSet<ulong> _uiPlayers = new HashSet<ulong>();
  45. private CuiElementContainer _cachedContainer;
  46. private const string _uiParent = "Timer_Body";
  47. private const string _timerParent = "Timer_Parent";
  48.  
  49. // Permissions
  50. private const string _perm = "noraid.admin";
  51.  
  52. #endregion
  53.  
  54. #region Config
  55.  
  56. private class ConfigFile
  57. {
  58. public FriendBypass FriendBypass;
  59.  
  60. public bool StopAllRaiding;
  61.  
  62. public WipeRaiding WipeRaiding;
  63.  
  64. public NoRaidCommand NoRaidCommand;
  65.  
  66. public UiSettings Ui;
  67.  
  68. public static ConfigFile DefaultConfig()
  69. {
  70. return new ConfigFile
  71. {
  72. FriendBypass = new FriendBypass()
  73. {
  74. Enabled = true,
  75. FriendsApi = new FriendsAPI()
  76. {
  77. Enabled = true
  78. },
  79. PlayerOwner = new PlayerOwner()
  80. {
  81. Enabled = true
  82. },
  83. RustIoClans = new RustIOClans()
  84. {
  85. Enabled = true
  86. }
  87. },
  88. WipeRaiding = new WipeRaiding()
  89. {
  90. Enabled = false,
  91. MinsFromWipe = 60f,
  92. CheckInterval = 5f
  93. },
  94. NoRaidCommand = new NoRaidCommand()
  95. {
  96. Enabled = true,
  97. DefaultMin = 30f,
  98. CheckInterval = 2.5f
  99. },
  100. Ui = new UiSettings()
  101. {
  102. Enabled = false,
  103. RefreshInterval = 1f,
  104. PrimaryColor = new Rgba(196, 65, 50, 1),
  105. DarkColor = new Rgba(119, 38, 0, 1),
  106. TextColor = new Rgba(255, 255, 255, 1),
  107. AnchorMin = new Anchor(0.75f, 0.92f),
  108. AnchorMax = new Anchor(0.98f, 0.98f)
  109. },
  110. StopAllRaiding = true
  111. };
  112. }
  113. }
  114.  
  115. private class FriendBypass
  116. {
  117. public bool Enabled { get; set; }
  118. public FriendsAPI FriendsApi { get; set; }
  119. public RustIOClans RustIoClans { get; set; }
  120. public PlayerOwner PlayerOwner { get; set; }
  121. }
  122.  
  123. private class FriendsAPI
  124. {
  125. public bool Enabled { get; set; }
  126. }
  127.  
  128. private class RustIOClans
  129. {
  130. public bool Enabled { get; set; }
  131. }
  132.  
  133. private class PlayerOwner
  134. {
  135. public bool Enabled { get; set; }
  136. }
  137.  
  138. private class WipeRaiding
  139. {
  140. public bool Enabled { get; set; }
  141.  
  142. [JsonProperty("Amount of time from wipe people can raid (minutes)")]
  143. public float MinsFromWipe { get; set; }
  144.  
  145. [JsonProperty("Amount of seconds to check if players can raid")]
  146. public float CheckInterval { get; set; }
  147. }
  148.  
  149. private class NoRaidCommand
  150. {
  151. public bool Enabled { get; set; }
  152. public float DefaultMin { get; set; }
  153. public float CheckInterval { get; set; }
  154. }
  155.  
  156. private class UiSettings
  157. {
  158. public bool Enabled { get; set; }
  159. public float RefreshInterval { get; set; }
  160. public Rgba PrimaryColor { get; set; }
  161. public Rgba DarkColor { get; set; }
  162. public Anchor AnchorMin { get; set; }
  163. public Anchor AnchorMax { get; set; }
  164. public Rgba TextColor { get; set; }
  165. }
  166.  
  167. private class Rgba
  168. {
  169. public float R { get; set; }
  170. public float G { get; set; }
  171. public float B { get; set; }
  172. public float A { get; set; }
  173.  
  174. public Rgba()
  175. {
  176. }
  177.  
  178. public Rgba(float r, float g, float b, float a)
  179. {
  180. R = r;
  181. G = g;
  182. B = b;
  183. A = a;
  184. }
  185.  
  186. public static string Format(Rgba rgba)
  187. {
  188. return $"{rgba.R / 255} {rgba.G / 255} {rgba.B / 255} {rgba.A}";
  189. }
  190. }
  191.  
  192. private class Anchor
  193. {
  194. public float X { get; set; }
  195. public float Y { get; set; }
  196.  
  197. public Anchor()
  198. {
  199. }
  200.  
  201. public Anchor(float x, float y)
  202. {
  203. X = x;
  204. Y = y;
  205. }
  206. }
  207.  
  208. protected override void LoadDefaultConfig()
  209. {
  210. PrintWarning("Generating default configuration file...");
  211. cFile = ConfigFile.DefaultConfig();
  212. }
  213.  
  214. protected override void LoadConfig()
  215. {
  216. base.LoadConfig();
  217. cFile = Config.ReadObject<ConfigFile>();
  218. }
  219.  
  220. protected override void SaveConfig() => Config.WriteObject(cFile);
  221.  
  222. #endregion
  223.  
  224. #region Lang
  225.  
  226. protected override void LoadDefaultMessages()
  227. {
  228. lang.RegisterMessages(new Dictionary<string, string>
  229. {
  230. ["CantDamage"] = "You cannot damage that entity because you are not associated with the building owner",
  231. ["CanRaid"] = "The raid cooldown has now been lifted, you're now able to raid!",
  232.  
  233. ["Cmd_CanRaid"] = "The cooldown has been lifted, you're able to raid whoever you want!",
  234. ["Cmd_CantRaid"] = "You can't raid just yet, wait another <color=orange>{0}</color>",
  235. ["Cmd_Permission"] = "You don't have permission to use that command",
  236. ["Cmd_InvalidArgs"] = "Invalid arguments. Usage: </color=orange>/noraid</color> <color=silver><start/stop> OPTIONAL: <min></color>",
  237. ["Cmd_CantStart"] = "Cannot start a no raid period, there's already one running.",
  238. ["Cmd_NoRaid"] = "A no raid period has begun, you can raid in <color=orange>{0}</color>",
  239.  
  240. ["Ui_Title"] = "RAID COOLDOWN",
  241.  
  242. ["Msg_DayFormat"] = "{0}D {1}H",
  243. ["Msg_DaysFormat"] = "{0}D {1}H",
  244. ["Msg_HourFormat"] = "{0}H {1}M",
  245. ["Msg_HoursFormat"] = "{0}H {1}M",
  246. ["Msg_MinFormat"] = "{0}M {1}S",
  247. ["Msg_MinsFormat"] = "{0}M {1}S",
  248. ["Msg_SecsFormat"] = "{0}S",
  249. }, this);
  250. }
  251.  
  252. #endregion
  253.  
  254. #region Methods
  255.  
  256. private string GetFormattedTime(double time)
  257. {
  258. TimeSpan timeSpan = TimeSpan.FromSeconds(time);
  259. if (timeSpan.TotalSeconds < 1) return null;
  260.  
  261. if (Math.Floor(timeSpan.TotalDays) >= 1)
  262. return string.Format(timeSpan.Days > 1 ? Lang("Msg_DaysFormat", null, timeSpan.Days, timeSpan.Hours) : Lang("Msg_DayFormat", null, timeSpan.Days, timeSpan.Hours));
  263. if (Math.Floor(timeSpan.TotalMinutes) >= 60)
  264. return string.Format(timeSpan.Hours > 1 ? Lang("Msg_HoursFormat", null, timeSpan.Hours, timeSpan.Minutes) : Lang("Msg_HourFormat", null, timeSpan.Hours, timeSpan.Minutes));
  265. if (Math.Floor(timeSpan.TotalSeconds) >= 60)
  266. return string.Format(timeSpan.Minutes > 1 ? Lang("Msg_MinsFormat", null, timeSpan.Minutes, timeSpan.Seconds) : Lang("Msg_MinFormat", null, timeSpan.Minutes, timeSpan.Seconds));
  267. return Lang("Msg_SecsFormat", null, timeSpan.Seconds);
  268. }
  269.  
  270. private void StartPeriod()
  271. {
  272. _cachedRaidTime = DateTime.UtcNow;
  273. _canRaid = false;
  274. foreach (var p in BasePlayer.activePlayerList)
  275. {
  276. PrintToChat(p, Lang("Cmd_NoRaid", p.UserIDString, GetFormattedTime((_cachedRaidTime.AddMinutes(_startMinutes)
  277. - DateTime.UtcNow).TotalSeconds)));
  278. }
  279. _startTimer = timer.Every(cFile.NoRaidCommand.CheckInterval, () =>
  280. {
  281. if (UI.ShouldDestroy(_cachedRaidTime, _startMinutes))
  282. {
  283. _canRaid = true;
  284. PrintToChat(Lang("CanRaid"));
  285. _startTimer?.Destroy();
  286. _startUiTimer?.Destroy();
  287. _startTimer = null;
  288. _startUiTimer = null;
  289. foreach (var p in BasePlayer.activePlayerList)
  290. {
  291. if (_uiPlayers.Contains(p.userID))
  292. _uiPlayers.Remove(p.userID);
  293. CuiHelper.DestroyUi(p, _uiParent);
  294. }
  295. }
  296.  
  297. });
  298. if (cFile.Ui.Enabled)
  299. {
  300. UI.ConstructCachedUi();
  301. _startUiTimer = timer.Every(cFile.Ui.RefreshInterval, () =>
  302. {
  303. if (UI.ShouldDestroy(_cachedRaidTime, _startMinutes))
  304. return;
  305.  
  306. var container = UI.ConstructTimer(_cachedRaidTime, _startMinutes);
  307.  
  308. foreach (var p in BasePlayer.activePlayerList)
  309. {
  310. if (!_uiPlayers.Contains(p.userID))
  311. {
  312. CuiHelper.AddUi(p, _cachedContainer);
  313. _uiPlayers.Add(p.userID);
  314. }
  315. CuiHelper.DestroyUi(p, _timerParent);
  316. CuiHelper.AddUi(p, container);
  317. }
  318. });
  319. }
  320. }
  321.  
  322. private void StopPeriod()
  323. {
  324. if (_startTimer != null)
  325. {
  326. _canRaid = true;
  327. PrintToChat(Lang("CanRaid"));
  328. _startTimer?.Destroy();
  329. _startUiTimer?.Destroy();
  330. _startTimer = null;
  331. _startUiTimer = null;
  332. foreach (var p in BasePlayer.activePlayerList)
  333. {
  334. if (_uiPlayers.Contains(p.userID))
  335. _uiPlayers.Remove(p.userID);
  336. CuiHelper.DestroyUi(p, _uiParent);
  337. }
  338. }
  339. }
  340.  
  341. #region UI
  342.  
  343. private class UI
  344. {
  345. public static CuiElementContainer Container(string name, string bgColor, Anchor Min, Anchor Max,
  346. string parent = "Overlay", float fadeOut = 0f, float fadeIn = 0f)
  347. {
  348. var newElement = new CuiElementContainer()
  349. {
  350. new CuiElement()
  351. {
  352. Name = name,
  353. Parent = parent,
  354. FadeOut = fadeOut,
  355. Components =
  356. {
  357. new CuiImageComponent()
  358. {
  359. Color = bgColor,
  360. FadeIn = fadeIn
  361. },
  362. new CuiRectTransformComponent()
  363. {
  364. AnchorMin = $"{Min.X} {Min.Y}",
  365. AnchorMax = $"{Max.X} {Max.Y}"
  366. }
  367. }
  368. },
  369. };
  370. return newElement;
  371. }
  372.  
  373. public static void Text(string name, string parent, ref CuiElementContainer container, TextAnchor anchor,
  374. string color, int fontSize, string text,
  375. Anchor Min, Anchor Max, string font = "robotocondensed-regular.ttf", float fadeOut = 0f,
  376. float fadeIn = 0f)
  377. {
  378. container.Add(new CuiElement()
  379. {
  380. Name = name,
  381. Parent = parent,
  382. FadeOut = fadeOut,
  383. Components =
  384. {
  385. new CuiTextComponent()
  386. {
  387. Text = text,
  388. Align = anchor,
  389. FontSize = fontSize,
  390. Font = font,
  391. FadeIn = fadeIn,
  392. Color = color
  393. },
  394. new CuiRectTransformComponent()
  395. {
  396. AnchorMin = $"{Min.X} {Min.Y}",
  397. AnchorMax = $"{Max.X} {Max.Y}"
  398. }
  399. }
  400. });
  401. }
  402.  
  403. public static void Element(string name, string parent, ref CuiElementContainer container, Anchor Min, Anchor Max,
  404. string bgColor, float fadeOut = 0f, float fadeIn = 0f)
  405. {
  406. container.Add(new CuiElement()
  407. {
  408. Name = name,
  409. Parent = parent,
  410. FadeOut = fadeOut,
  411. Components =
  412. {
  413. new CuiImageComponent()
  414. {
  415. Color = bgColor,
  416. Material = "",
  417. FadeIn = fadeIn
  418. },
  419. new CuiRectTransformComponent()
  420. {
  421. AnchorMin = $"{Min.X} {Min.Y}",
  422. AnchorMax = $"{Max.X} {Max.Y}"
  423. }
  424. }
  425. });
  426. }
  427.  
  428. public static void Image(string name, string parent, ref CuiElementContainer container, Anchor Min, Anchor Max, string img, string color)
  429. {
  430. container.Add(new CuiElement
  431. {
  432. Name = name,
  433. Parent = parent,
  434. Components =
  435. {
  436. new CuiRawImageComponent()
  437. {
  438. Url = img,
  439. Sprite = "assets/content/textures/generic/fulltransparent.tga",
  440. Color = color,
  441. Material = "Assets/Icons/IconMaterial.mat"
  442. },
  443. new CuiRectTransformComponent()
  444. {
  445. AnchorMin = $"{Min.X} {Min.Y}",
  446. AnchorMax = $"{Max.X} {Max.Y}"
  447. }
  448. }
  449. });
  450. }
  451.  
  452. public static bool ShouldDestroy(DateTime time, float minutes)
  453. {
  454. if (time.AddMinutes(minutes) <= DateTime.UtcNow ||
  455. _instance.GetFormattedTime((time.AddMinutes(minutes) -
  456. DateTime.UtcNow).TotalSeconds) == null)
  457. {
  458. return true;
  459. }
  460. return false;
  461. }
  462.  
  463. public static void ConstructCachedUi()
  464. {
  465. _instance._cachedContainer = Container(_uiParent, "0 0 0 0.1", cFile.Ui.AnchorMin, cFile.Ui.AnchorMax);
  466.  
  467. Element("Title_Element", _uiParent, ref _instance._cachedContainer, new Anchor(0.2f, 0f), new Anchor(0.75f, 1f), Rgba.Format(cFile.Ui.PrimaryColor));
  468.  
  469. Element("Title_Padded", "Title_Element", ref _instance._cachedContainer, new Anchor(0.05f, 0.05f), new Anchor(0.95f, 0.95f), "0 0 0 0");
  470.  
  471. Text("Title_Text", "Title_Padded", ref _instance._cachedContainer, TextAnchor.MiddleLeft, Rgba.Format(cFile.Ui.TextColor), 15, _instance.Lang("Ui_Title"), new Anchor(0f, 0f),
  472. new Anchor(1f, 1f), "robotocondensed-bold.ttf");
  473.  
  474. Element("Icon_Element", _uiParent, ref _instance._cachedContainer, new Anchor(0f, 0f), new Anchor(0.2f, 1f), Rgba.Format(cFile.Ui.PrimaryColor));
  475.  
  476. Element("Icon_Padded", "Icon_Element", ref _instance._cachedContainer, new Anchor(0.2f, 0.15f), new Anchor(0.8f, 0.85f), "0 0 0 0");
  477.  
  478. Image("Icon_Image", "Icon_Padded", ref _instance._cachedContainer, new Anchor(0f, 0f), new Anchor(1f, 1f), "http://i.imgur.com/jDo2bgn.png", Rgba.Format(cFile.Ui.DarkColor));
  479. }
  480.  
  481. public static CuiElementContainer ConstructTimer(DateTime time, float minutes)
  482. {
  483. var container = Container(_timerParent, Rgba.Format(cFile.Ui.DarkColor), new Anchor(0.75f, 0f), new Anchor(1, 1f), _uiParent);
  484.  
  485. Text("Timer_Time", _timerParent, ref container, TextAnchor.MiddleCenter, Rgba.Format(cFile.Ui.TextColor), 15,
  486. _instance.GetFormattedTime((time.AddMinutes(minutes) - DateTime.UtcNow).TotalSeconds),
  487. new Anchor(0.05f, 0.05f), new Anchor(0.95f, 0.95f));
  488.  
  489. return container;
  490. }
  491. }
  492.  
  493. #endregion
  494.  
  495. #endregion
  496.  
  497. #region Hooks
  498.  
  499. private void Init()
  500. {
  501. _instance = this;
  502. permission.RegisterPermission(_perm, this);
  503. SaveConfig();
  504. if (cFile.NoRaidCommand.Enabled && cFile.WipeRaiding.Enabled)
  505. {
  506. PrintWarning("It is not recomended to have NoRaidCommand and WipeRaiding enabled at the same time. They could conflict!");
  507. cFile.NoRaidCommand.Enabled = false;
  508. }
  509. }
  510.  
  511. private void OnServerInitialized()
  512. {
  513. if (!Clans && cFile.FriendBypass.RustIoClans.Enabled)
  514. {
  515. cFile.FriendBypass.RustIoClans.Enabled = false;
  516. PrintWarning("RustIO Clans not detected, disabling RustIO Clans integration");
  517. }
  518. if (!Friends && cFile.FriendBypass.FriendsApi.Enabled)
  519. {
  520. cFile.FriendBypass.FriendsApi.Enabled = false;
  521. PrintWarning("FriendsAPI not detected, disabling FriendsAPI integration");
  522. }
  523.  
  524. _cachedWipeTime = SaveRestore.SaveCreatedTime;
  525. _canRaid = true;
  526.  
  527. if (cFile.WipeRaiding.Enabled && _cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe) > DateTime.UtcNow)
  528. {
  529. _wipeCheckTimer = timer.Every(cFile.WipeRaiding.CheckInterval, () =>
  530. {
  531. if (UI.ShouldDestroy(_cachedWipeTime, cFile.WipeRaiding.MinsFromWipe))
  532. {
  533. _canWipeRaid = true;
  534. PrintToChat(Lang("CanRaid"));
  535. _wipeCheckTimer?.Destroy();
  536. _uiTimer?.Destroy();
  537. foreach (var player in BasePlayer.activePlayerList)
  538. CuiHelper.DestroyUi(player, _uiParent);
  539. }
  540. });
  541. if (cFile.Ui.Enabled)
  542. {
  543. UI.ConstructCachedUi();
  544.  
  545. _uiTimer = timer.Every(cFile.Ui.RefreshInterval, () =>
  546. {
  547. if (UI.ShouldDestroy(_cachedWipeTime, cFile.WipeRaiding.MinsFromWipe))
  548. return;
  549.  
  550. var container = UI.ConstructTimer(_cachedWipeTime, cFile.WipeRaiding.MinsFromWipe);
  551.  
  552. foreach (var player in BasePlayer.activePlayerList)
  553. {
  554. if (!_uiPlayers.Contains(player.userID))
  555. {
  556. CuiHelper.AddUi(player, _cachedContainer);
  557. _uiPlayers.Add(player.userID);
  558. }
  559. CuiHelper.DestroyUi(player, _timerParent);
  560. CuiHelper.AddUi(player, container);
  561. }
  562. });
  563. }
  564. }
  565. else
  566. {
  567. _canWipeRaid = true;
  568. }
  569. }
  570.  
  571. private void Unload()
  572. {
  573. foreach (var player in BasePlayer.activePlayerList)
  574. CuiHelper.DestroyUi(player, _uiParent);
  575. }
  576.  
  577. private void OnPlayerConnected(BasePlayer player)
  578. {
  579. if (cFile.WipeRaiding.Enabled && _cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe) > DateTime.UtcNow && cFile.Ui.Enabled)
  580. {
  581. timer.Once(3f, () =>
  582. {
  583. if (!_uiPlayers.Contains(player.userID))
  584. {
  585. CuiHelper.AddUi(player, _cachedContainer);
  586. _uiPlayers.Add(player.userID);
  587. }
  588. });
  589. }
  590. }
  591.  
  592. private void OnPlayerDisconnected(BasePlayer player, string reason)
  593. {
  594. if (_uiPlayers.Contains(player.userID))
  595. _uiPlayers.Remove(player.userID);
  596. }
  597.  
  598. private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
  599. {
  600. if (entity is BuildingBlock || entity.name.Contains("deploy") || entity.name.Contains("building") || entity.name.Contains("industrialdoora") || entity.name.Contains("factorydoor"))
  601. {
  602. var player = info?.Initiator?.ToPlayer();
  603.  
  604. if (!player || player.IsNpc || !entity.OwnerID.IsSteamId()
  605. || (entity is BuildingBlock && ((BuildingBlock)entity).grade == BuildingGrade.Enum.Twigs)
  606. || entity.name.Contains("box.wooden.large")
  607. || entity.name.Contains("woodbox")
  608. || entity.name.Contains("sleepingbag")
  609. || entity.name.Contains("beachtowel")
  610. || entity.name.Contains("bed")
  611. || entity.name.Contains("cupboard")
  612. || entity.name.Contains("turret")
  613. || entity.name.Contains("landmine")
  614. || entity.name.Contains("wall.frame.cell")
  615. || entity.name.Contains("fence")
  616. || entity.name.Contains("landmine")
  617. || entity.name.Contains("watchtower")
  618. || entity.name.Contains("guntrap")
  619. || entity.name.Contains("external"))
  620. {
  621. return null;
  622. }
  623.  
  624. if (cFile.FriendBypass.Enabled)
  625. {
  626. // Owner checks
  627. if (cFile.FriendBypass.PlayerOwner.Enabled && player.userID == entity.OwnerID)
  628. {
  629. return null;
  630. }
  631. // Friend checks
  632.  
  633. if (Friends)
  634. {
  635. var hasFriend = Friends?.Call("HasFriend", entity.OwnerID.ToString(), player.UserIDString) ?? false;
  636. if (cFile.FriendBypass.FriendsApi.Enabled && (bool)hasFriend)
  637. {
  638. return null;
  639. }
  640. }
  641.  
  642. if (Clans)
  643. {
  644. // Clan checks
  645. var targetClan = (string)Clans?.Call("GetClanOf", entity.OwnerID.ToString());
  646. var playerClan = (string)Clans?.Call("GetClanOf", player.UserIDString);
  647. if (cFile.FriendBypass.RustIoClans.Enabled && playerClan != null && targetClan != null && targetClan == playerClan)
  648. {
  649. return null;
  650. }
  651. }
  652. }
  653.  
  654. // Prevents player from damaging after friendbypass checks
  655. if (cFile.StopAllRaiding)
  656. {
  657. PrintToChat(player, Lang("CantDamage", player.UserIDString));
  658. return true;
  659. }
  660.  
  661. // No raid command checks
  662. if (!_canRaid)
  663. {
  664. PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedRaidTime.AddMinutes(_startMinutes)
  665. - DateTime.UtcNow).TotalSeconds)));
  666. return true;
  667. }
  668.  
  669. // Wipe raid checks
  670. if (cFile.WipeRaiding.Enabled && !_canWipeRaid)
  671. {
  672. PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe)
  673. - DateTime.UtcNow).TotalSeconds)));
  674. return true;
  675. }
  676. if (cFile.WipeRaiding.Enabled)
  677. {
  678. return null;
  679. }
  680. }
  681. return null;
  682. }
  683.  
  684. [ChatCommand("canraid")]
  685. private void RaidCmd(BasePlayer player, string command, string[] args)
  686. {
  687. if (cFile.WipeRaiding.Enabled && !_canWipeRaid)
  688. {
  689. PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe)
  690. - DateTime.UtcNow).TotalSeconds)));
  691. return;
  692. }
  693. PrintToChat(player, Lang("Cmd_CanRaid", player.UserIDString));
  694. }
  695.  
  696. [ChatCommand("noraid")]
  697. private void NoRaidCmd(BasePlayer player, string command, string[] args)
  698. {
  699. if (!cFile.NoRaidCommand.Enabled)
  700. return;
  701.  
  702. if (!permission.UserHasPermission(player.UserIDString, _perm))
  703. {
  704. PrintToChat(player, Lang("Cmd_Permission", player.UserIDString));
  705. return;
  706. }
  707. if (args.Length == 0)
  708. {
  709. PrintToChat(player, Lang("Cmd_InvalidArgs", player.UserIDString));
  710. return;
  711. }
  712. switch (args[0].ToLower())
  713. {
  714. case "start":
  715. {
  716. if (_startTimer != null)
  717. {
  718. PrintToChat(player, Lang("Cmd_CantStart", player.UserIDString));
  719. return;
  720. }
  721. float outNum;
  722. _startMinutes = args.Length == 2 && float.TryParse(args[1], out outNum) ? outNum : cFile.NoRaidCommand.DefaultMin;
  723. StartPeriod();
  724. return;
  725. }
  726. case "stop":
  727. {
  728. StopPeriod();
  729. return;
  730. }
  731. }
  732. }
  733.  
  734. [ConsoleCommand("noraid.start")]
  735. private void ConsoleStartCommand(ConsoleSystem.Arg arg)
  736. {
  737. if (arg.Connection != null && !permission.UserHasPermission(arg.Connection.userid.ToString(), _perm))
  738. {
  739. arg.ReplyWith(Lang("Cmd_Permission", arg.Connection.userid.ToString()));
  740. return;
  741. }
  742. if (_startTimer != null)
  743. {
  744. arg.ReplyWith(Lang("Cmd_CantStart"));
  745. return;
  746. }
  747. float outNum;
  748. _startMinutes = arg.Args.Length >= 1 && float.TryParse(arg.Args[0], out outNum) ? outNum : cFile.NoRaidCommand.DefaultMin;
  749. arg.ReplyWith($"Started NoRaid period that lasts for {_startMinutes} minutes");
  750. StartPeriod();
  751. }
  752.  
  753. [ConsoleCommand("noraid.stop")]
  754. private void ConsoleStopCommand(ConsoleSystem.Arg arg)
  755. {
  756. if (arg.Connection != null && !permission.UserHasPermission(arg.Connection.userid.ToString(), _perm))
  757. {
  758. arg.ReplyWith(Lang("Cmd_Permission", arg.Connection.userid.ToString()));
  759. return;
  760. }
  761. StopPeriod();
  762. arg.ReplyWith("NoRaid period stopped");
  763. }
  764.  
  765. #endregion
  766. }
  767. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement