Advertisement
emesten

Untitled

Jun 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.90 KB | None | 0 0
  1. using Oxide.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6.  
  7. namespace Oxide.Plugins
  8. {
  9. [Info("Night Door", "Slydelix", "1.7.2", ResourceId = 2684)]
  10. class NightDoor : RustPlugin
  11. {
  12. private bool hideTime, BypassAdmin, BypassPerm, UseRealTime, AutoDoor, useMulti, intialized = false;
  13. private string startTime, endTime;
  14.  
  15. private const string usePerm = "nightdoor.use";
  16. private const string createIntervalPerm = "nightdoor.createinterval";
  17. private const string bypassPerm = "nightdoor.bypass";
  18.  
  19. #region config
  20.  
  21. protected override void LoadDefaultConfig()
  22. {
  23. Config["Allow admins to open time-limited door"] = BypassAdmin = GetConfig("Allow admins to open time-limited door", false);
  24. Config["Allow players with bypass permission to open time-limited door"] = BypassPerm = GetConfig("Allow players with bypass permission to open time-limited door", false);
  25. Config["Beginning time (HH:mm)"] = startTime = GetConfig("Beginning time (HH:mm)", "00:00");
  26. Config["Use multiple time intervals"] = useMulti = GetConfig("Use multiple time intervals", false);
  27. Config["End time (HH:mm)"] = endTime = GetConfig("End time (HH:mm)", "00:00");
  28. Config["Use system (real) time"] = UseRealTime = GetConfig("Use system (real) time", false);
  29. Config["Don't show time to player when unable to open door"] = hideTime = GetConfig("Don't show time to player when unable to open door", false);
  30. Config["Automatic door closing/opening"] = AutoDoor = GetConfig("Automatic door closing/opening", false);
  31. SaveConfig();
  32. }
  33.  
  34. #endregion
  35. #region lang
  36.  
  37. protected override void LoadDefaultMessages()
  38. {
  39. lang.RegisterMessages(new Dictionary<string, string>()
  40. {
  41. //Default messages
  42. {"ServerWiped", "Wipe du serveur détecté, remise à zéro du fichier de données"},
  43. {"WipeManual", "Remise a zéro manuelle du fichier de données de Night Door"},
  44. {"Warning_StartBiggerThanEnd", "La configuration ne semble pas correcte ! (l'heure de début se situe après l'heure de fin)"},
  45. {"Warning_DefaultConfig", "00:00 défini comme fin et comme début ! Changez ces valeurs par celles que vous désirez"},
  46. {"NoPermission", "Vous n'avez pas la permission pour utiliser cette commande"},
  47. //Player messages
  48. {"PlayerCannotOpen", "Cette {0} ne peut pas être ouverte."},
  49. {"PlayerCannotOpenTime", "Cette {0} ne peut être ouverte avant {1}"},
  50. {"PlayerCannotPlace", "Un verrou ne peut pas être placé sur cette {0}"},
  51. //Messages for /timeperiod
  52. {"TimeIntervalRemovedDoor", "La porte à {0} peut maintenant être ouverte car la période a été supprimée !"},
  53. {"TimeIntevalSyntax", "Erreur de syntaxe ! <color=silver>/timeperiod create <nom> <HH:mm>(heure de début) <HH:mm>(heure de fin)</color>"},
  54. {"TimeIntervalRemoveSyntax", "Erreur de syntaxe ! <color=silver>/timeperiod remove <nom></color>"},
  55. {"TimeIntervalCreated", "Nouvelle période créée sous le nom '{0}' ({1} - {2})"},
  56. {"TimeIntervalRemoved", "Période avec le nom '{0}' a été supprimée"},
  57. {"TimeIntervalNotSetUp", "Il n'y a aucune période enregistrée"},
  58. {"TimeIntervalList", "Liste de toutes les périodes: \n{0}"},
  59. {"TimeIntervalExists", "Une période avec ce nom existe déjà"},
  60. {"TimeIntervalDisabled", "Les périodes multiples ne sont pas activées." },
  61. {"TimeIntervalMissingTimePeriod", "Erreur de syntaxe ! /nd add <nom de la période que la porte doit utiliser>"},
  62. {"TimeIntervalNotFound", "Impossible de trouver une période avec ce nom '{0}'"},
  63. {"HowTo26Hour", "Pour créer une période incluant 2 jours différents, comme (22:00 - 02:00), ajouter 24 à la dernière valeur (22:00 - 26:00)" },
  64. {"HowToUseTimeIntervals", "Pour cr éer une periode saisir <color=silver>/timeperiod create <nom de la période> <HH:mm> (heure de début) <HH:mm> (heure de fin)</color>\nPour supprimer une période saisir <color=silver>/timeperiod remove <nom></color>\nPour obtenir une liste de toutes les périodes saisir <color=silver>/timeperiod list</color>"},
  65. //Messages for /nd
  66. {"NoEntity", "Vous ne regardez pas d'entité valide" },
  67. {"EntityNotDoor", "L'entité que vous regardez n'est pas ouvrable" },
  68. {"NoLockedEnts", "Aucune entité avec période trouvée"},
  69. {"ShowingEnts", "Affiche toutes les entités avec période"},
  70. { "SyntaxError", "Erreur de syntaxe ! Saisir /nd help pour plus d'information"},
  71. {"DoorNowLocked", "Cette {0} est maintenant sous la période (temps par défaut)"},
  72. {"DoorCustomLocked", "Cette {0} est maintenant sous la période ('{1}' ({2} - {3})"},
  73. {"NotTimeLocked", "Cette {0} n'est pas restreinte à une période"},
  74. {"AlreadyLocked", "Cette {0} est déjà restreint à une période"},
  75. {"DoorUnlocked", "Cette {0} n'est plus restreinte à une période"},
  76. {"InfoAboutDoor", "Cette {0} est maintenant sous période\nLa période est {1} ({2} - {3})"},
  77. {"ListOfCommands", "Liste des commandes :\n<color=silver>*Vous devez être en train de regarder une porte/trappe/porche pour que la plupart de ces commandes*</color>\n<color=silver>/nd add</color> - Rend l'entité ouvrable uniquement pendant la période par défaut (voir config)\n<color=silver>/nd add <periode></color> Rend l'entité ouvrable uniquement pendant la période spécifiée (/timeperiod)\n<color=silver>/nd remove</color> Rend l'entité à son état 'normal' (ouvrable a tout moment)\n<color=silver>/nd show</color> Affiche toutes les entités sous période\n<color=silver>/nd info</color> Affiche si la porte/trappe/porche est sous période et informe sur la période le cas échéant\nPériode actuelle : {0} - {1}"}
  78. }, this, "fr");
  79.  
  80. lang.RegisterMessages(new Dictionary<string, string>()
  81. {
  82. //Default messages
  83. {"ServerWiped", "Server wipe detected, wiping data file"},
  84. {"WipeManual", "Manually wiped Night Door data file"},
  85. {"Warning_StartBiggerThanEnd", "Config seems to be set up incorrectly! (Start time value is bigger than end time value)"},
  86. {"Warning_DefaultConfig", "Detected 00:00 as both end and start time! Change these to values you want"},
  87. {"NoPermission", "You don't have permission to use this command"},
  88. //Player messages
  89. {"PlayerCannotOpen", "This {0} cannot be opened."},
  90. {"PlayerCannotOpenTime", "This {0} cannot be opened until {1}"},
  91. {"PlayerCannotPlace", "A lock cannot be placed on this {0}"},
  92. //Messages for /timeperiod
  93. {"TimeIntervalRemovedDoor", "Door at {0} can now be opened at any time because the time period got removed!"},
  94. {"TimeIntevalSyntax", "Wrong syntax! <color=silver>/timeperiod create <name> <HH:mm>(starting time) <HH:mm>(ending time)</color>"},
  95. {"TimeIntervalRemoveSyntax", "Wrong syntax! <color=silver>/timeperiod remove <name></color>"},
  96. {"TimeIntervalCreated", "Created a new time period with name '{0}' ({1} - {2})"},
  97. {"TimeIntervalRemoved", "Removed a time period with name '{0}'"},
  98. {"TimeIntervalNotSetUp", "There are no time periods set up"},
  99. {"TimeIntervalList", "List of all time periods: \n{0}"},
  100. {"TimeIntervalExists", "A time period with that name already exists"},
  101. {"TimeIntervalDisabled", "Multiple time intervals are disabled." },
  102. {"TimeIntervalMissingTimePeriod", "Wrong syntax! /nd add <name of time period the door will use>"},
  103. {"TimeIntervalNotFound", "Couldn't find a time period with name '{0}'"},
  104. {"HowTo26Hour", "To create time periods that includes 2 days, like 22:00 - 02:00 add 24 to the last value (22:00 - 26:00)" },
  105. {"HowToUseTimeIntervals", "To create a time period type <color=silver>/timeperiod create <name of time period> <HH:mm> (starting time) <HH:mm> (ending time)</color>\nTo delete a time period type <color=silver>/timeperiod remove <name></color>\nFor list of all time periods type <color=silver>/timeperiod list</color>"},
  106. //Messages for /nd
  107. {"NoEntity", "You are not looking at an entity" },
  108. {"EntityNotDoor", "The entity you are looking at is not openable" },
  109. {"NoLockedEnts", "No time locked entites found"},
  110. {"ShowingEnts", "Showing all time locked entites"},
  111. { "SyntaxError", "Wrong syntax! Type /nd help for more info"},
  112. {"DoorNowLocked", "This {0} is now time locked (default time)"},
  113. {"DoorCustomLocked", "This {0} is now time locked (Time period '{1}' ({2} - {3})"},
  114. {"NotTimeLocked", "This {0} isn't time locked"},
  115. {"AlreadyLocked", "This {0} is already time locked"},
  116. {"DoorUnlocked", "This {0} is not time locked anymore"},
  117. {"InfoAboutDoor", "This {0} is time locked\nTime period is {1} ({2} - {3})"},
  118. {"ListOfCommands", "List of commands:\n<color=silver>*You have to look at the door/hatch/gate for most of the commands to work*</color>\n<color=silver>/nd add</color> - Makes the entity openable only during default time period(config time)\n<color=silver>/nd add <time period></color> Makes the entity openable only during specified time period (/timeperiod)\n<color=silver>/nd remove</color> Makes the entity 'normal' again (openable at any time)\n<color=silver>/nd show</color> shows all time locked entites\n<color=silver>/nd info</color> shows if the door/hatch/gate is time locked and the time period if it is\nCurrent time period: {0} - {1}"}
  119. }, this, "en");
  120. }
  121.  
  122. private T GetConfig<T>(string name, T defaultValue)
  123. {
  124. if (Config[name] == null) return defaultValue;
  125. return (T)Convert.ChangeType(Config[name], typeof(T));
  126. }
  127.  
  128. #endregion
  129. #region DataFile
  130.  
  131. private class StoredData
  132. {
  133. public Dictionary<uint, string> IDlist = new Dictionary<uint, string>();
  134. public HashSet<TimeInfo> TimeEntries = new HashSet<TimeInfo>();
  135.  
  136. public StoredData()
  137. {
  138. }
  139. }
  140.  
  141. private class TimeInfo
  142. {
  143. public string name;
  144. public string start;
  145. public string end;
  146.  
  147. public TimeInfo(string nameIn, string startInput, string endInput)
  148. {
  149. name = nameIn;
  150. start = startInput;
  151. end = endInput;
  152. }
  153. }
  154.  
  155. private StoredData storedData;
  156.  
  157. #endregion
  158. #region Hooks
  159.  
  160. private void OnNewSave(string filename)
  161. {
  162. PrintWarning(lang.GetMessage("ServerWiped", this));
  163. storedData.IDlist.Clear();
  164. SaveFile();
  165. }
  166.  
  167. private void OnServerInitialized()
  168. {
  169. timer.In(10f, () =>
  170. {
  171. intialized = true;
  172. });
  173. Repeat();
  174. DoDefaultT();
  175. }
  176.  
  177. private void Init()
  178. {
  179. LoadDefaultConfig();
  180. permission.RegisterPermission(usePerm, this);
  181. permission.RegisterPermission(createIntervalPerm, this);
  182. permission.RegisterPermission(bypassPerm, this);
  183. storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("NightDoor_NEW");
  184. if (GetDateTime(startTime) > GetDateTime(endTime)) PrintWarning(lang.GetMessage("Warning_StartBiggerThanEnd", this));
  185. if (startTime == "00:00" && endTime == "00:00") PrintWarning(lang.GetMessage("Warning_DefaultConfig", this));
  186. }
  187.  
  188. private void SaveFile() => Interface.Oxide.DataFileSystem.WriteObject("NightDoor_NEW", storedData);
  189.  
  190. private void Unload() => SaveFile();
  191.  
  192. private void OnServerSave() => CheckAllEntites();
  193.  
  194. private void OnEntityKill(BaseNetworkable entity) => CheckAllEntites();
  195.  
  196. private void OnDoorOpened(Door door, BasePlayer player)
  197. {
  198. BaseEntity doorEnt = door.GetEntity();
  199. if (doorEnt == null) return;
  200.  
  201. string name = GetNameFromEntity(doorEnt);
  202. uint entID = doorEnt.net.ID;
  203. if (storedData.IDlist.ContainsKey(door.net.ID))
  204. {
  205. float time = ConVar.Env.time;
  206. if (CanOpen(player, entID, time)) return;
  207. door.CloseRequest();
  208.  
  209. string entname = storedData.IDlist[entID];
  210.  
  211. foreach (var entry in storedData.TimeEntries)
  212. {
  213. if (entry.name == entname)
  214. {
  215. if (hideTime)
  216. {
  217. SendReply(player, lang.GetMessage("PlayerCannotOpen", this, player.UserIDString), name);
  218. return;
  219. }
  220.  
  221. SendReply(player, lang.GetMessage("PlayerCannotOpenTime", this, player.UserIDString), name, entry.start);
  222. return;
  223. }
  224. }
  225. return;
  226. }
  227. }
  228.  
  229. private void OnItemDeployed(Deployer deployer, BaseEntity entity)
  230. {
  231. if (entity == null || deployer == null) return;
  232.  
  233. BasePlayer player = deployer?.GetOwnerPlayer();
  234. string item = GetNameFromEntity(entity);
  235.  
  236. if (entity is Door)
  237. {
  238. BaseEntity codelockent = entity?.GetSlot(BaseEntity.Slot.Lock);
  239.  
  240. if (storedData.IDlist.ContainsKey(entity.net.ID))
  241. {
  242. Item codelock;
  243. if (codelockent?.PrefabName == "assets/prefabs/locks/keypad/lock.code.prefab") codelock = ItemManager.CreateByName("lock.code", 1);
  244. else codelock = ItemManager.CreateByName("lock.key", 1);
  245.  
  246. if (codelock != null)
  247. {
  248. player.GiveItem(codelock);
  249. SendReply(player, lang.GetMessage("PlayerCannotPlace", this, player.UserIDString), item);
  250. }
  251. codelockent?.KillMessage();
  252. return;
  253. }
  254. }
  255. }
  256.  
  257. private object CanPickupEntity(BaseCombatEntity entity, BasePlayer player)
  258. {
  259. if (entity == null) return null;
  260. if (storedData.IDlist.ContainsKey(entity.net.ID)) return true;
  261. return null;
  262. }
  263.  
  264. #endregion
  265. #region stuff
  266. private string GetNameFromEntity(BaseEntity entity)
  267. {
  268. Dictionary<string, string> EntList = new Dictionary<string, string> {
  269. {"door.hinged.toptier", "Armored Door" },
  270. {"gates.external.high.wood", "High External Wooden Gate" },
  271. {"gates.external.high.stone", "High External Stone Gate" },
  272. {"wall.frame.shopfront", "Shop Front" },
  273. {"wall.frame.garagedoor", "Garage Door" },
  274. {"shutter.wood.a", "Wood Shutters" },
  275. {"floor.ladder.hatch", "Ladder Hatch" },
  276. {"wall.frame.cell.gate", "Prison Cell Gate" },
  277. {"wall.frame.fence.gate", "Chainlink Fence Gate" },
  278. {"door.double.hinged.wood", "Wood Double Door" },
  279. {"door.double.hinged.toptier", "Armored Double Door" },
  280. {"door.double.hinged.metal", "Sheet Metal Double Door" },
  281. {"door.hinged.metal", "Sheet Metal Door" }
  282. };
  283.  
  284. string itemName = "entity";
  285.  
  286. if (EntList.ContainsKey(entity?.ShortPrefabName))
  287. itemName = EntList[entity?.ShortPrefabName];
  288.  
  289. return itemName;
  290. }
  291. private void Repeat()
  292. {
  293. timer.Every(5f, () => {
  294. CheckDoors();
  295. CheckAllEntites();
  296. });
  297. }
  298.  
  299. private void DoDefaultT()
  300. {
  301. timer.Once(1f, () => {
  302. foreach (var entry in storedData.TimeEntries)
  303. {
  304. if (entry.name == "default")
  305. {
  306. entry.start = startTime;
  307. entry.end = endTime;
  308. SaveFile();
  309. return;
  310. }
  311. }
  312.  
  313. var cfgTime = new TimeInfo("default", startTime, endTime);
  314. storedData.TimeEntries.Add(cfgTime);
  315. SaveFile();
  316. return;
  317. });
  318. }
  319.  
  320. private void CheckDoors()
  321. {
  322. if (!AutoDoor) return;
  323.  
  324. float time = ConVar.Env.time;
  325.  
  326. if (storedData.IDlist.Count == 0) return;
  327.  
  328. foreach (var entry in storedData.IDlist.ToList())
  329. {
  330. BaseEntity ent = BaseNetworkable.serverEntities.Find(entry.Key) as BaseEntity;
  331.  
  332. if (ent == null || ent.IsDestroyed) continue;
  333.  
  334. if (CanOpen(null, ent.net.ID, time))
  335. {
  336. ent.SetFlag(BaseEntity.Flags.Open, true);
  337. ent.SendNetworkUpdateImmediate();
  338. }
  339.  
  340. else
  341. {
  342. ent.SetFlag(BaseEntity.Flags.Open, false);
  343. ent.SendNetworkUpdateImmediate();
  344. }
  345. }
  346. }
  347.  
  348. private bool CanOpen(BasePlayer player, uint ID, float now)
  349. {
  350. if (player != null)
  351. {
  352. if (player.IsAdmin && BypassAdmin) return true;
  353. if (permission.UserHasPermission(player.UserIDString, bypassPerm) && BypassPerm) return true;
  354. }
  355.  
  356. if (UseRealTime)
  357. {
  358. foreach (var entry in storedData.IDlist)
  359. {
  360. if (entry.Key == ID)
  361. {
  362. foreach (var ent in storedData.TimeEntries)
  363. {
  364. if (ent.name == entry.Value)
  365. {
  366. string ending = ent.end;
  367. int valInt = int.Parse(ending.Split(':')[0]);
  368. if (valInt > 24)
  369. {
  370. DateTime start_changed = GetDateTime(ID, true);
  371. DateTime end_changed = GetDateTime(ID, false);
  372. start_changed = start_changed.AddDays(-1);
  373. end_changed = end_changed.AddDays(-1);
  374. if ((DateTime.Now >= start_changed) && (DateTime.Now <= end_changed)) return true;
  375. return false;
  376. }
  377.  
  378. else
  379. {
  380. DateTime start = GetDateTime(ID, true);
  381. DateTime end = GetDateTime(ID, false);
  382. if ((DateTime.Now >= start) && (DateTime.Now <= end)) return true;
  383. return false;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390.  
  391. //wtf is this even
  392. float a = GetFloat(ID, true);
  393. float b = GetFloat(ID, false);
  394. float c = b - 24f;
  395. if (c < 0) c = 99999f;
  396. if (now >= a && now <= b) return true;
  397. if (c != 99999f)
  398. {
  399. if (now >= 0f && now <= c) return true;
  400. }
  401.  
  402. return false;
  403. }
  404.  
  405. private void CheckAllEntites()
  406. {
  407. if (!intialized || storedData.IDlist.Count == 0) return;
  408.  
  409. foreach (var entry in storedData.IDlist.ToList())
  410. {
  411. BaseNetworkable ent = BaseNetworkable.serverEntities.Find(entry.Key) ?? null;
  412.  
  413. if (ent == null || ent.IsDestroyed)
  414. {
  415. storedData.IDlist.Remove(entry.Key);
  416. SaveFile();
  417. }
  418. }
  419. }
  420.  
  421. private float GetFloat(uint ID, bool start)
  422. {
  423. string input = "";
  424. foreach (var entry in storedData.TimeEntries)
  425. {
  426. if (entry.name == storedData.IDlist[ID])
  427. {
  428. if (start) input = entry.start;
  429. else input = entry.end;
  430. }
  431. }
  432.  
  433. string[] parts = input.Split(':');
  434. int hourInt = int.Parse(parts[0]);
  435. int minInt = int.Parse(parts[1]);
  436.  
  437. float min = (float)minInt / 60;
  438.  
  439. return (hourInt + min);
  440. }
  441.  
  442. private float GetFloat(string in2)
  443. {
  444. string[] parts = in2.Split(':');
  445. string h = "", m = "";
  446. int hourInt = int.Parse(parts[0]);
  447. int minInt = int.Parse(parts[1]);
  448.  
  449. float min = (float)minInt / 60;
  450. return (hourInt + min);
  451. }
  452.  
  453. private DateTime GetDateTime(uint ID, bool start)
  454. {
  455. DateTime final = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
  456. string input = "";
  457. foreach (var entry in storedData.TimeEntries)
  458. {
  459. if (entry.name == storedData.IDlist[ID])
  460. {
  461. if (start) input = entry.start;
  462. else input = entry.end;
  463. }
  464. }
  465.  
  466. string[] parts = input.Split(':');
  467. int mInt = int.Parse(parts[1]);
  468. int hInt = int.Parse(parts[0]);
  469.  
  470. if (hInt > 24 && start)
  471. {
  472. final = final.AddHours(hInt);
  473. final = final.AddMinutes(mInt);
  474. final = final.AddDays(-1);
  475. return final;
  476. }
  477.  
  478. final = final.AddHours(hInt);
  479. final = final.AddMinutes(mInt);
  480. return final;
  481. }
  482.  
  483. private DateTime GetDateTime(string input)
  484. {
  485. DateTime final = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
  486. string[] parts = input.Split(':');
  487. int mInt = int.Parse(parts[1]);
  488. int hInt = int.Parse(parts[0]);
  489. final = final.AddHours(hInt);
  490. final = final.AddMinutes(mInt);
  491. return final;
  492. }
  493.  
  494. private BaseEntity GetLookAtEntity(BasePlayer player, float maxDist = 250, int coll = -1)
  495. {
  496. if (player == null || player.IsDead()) return null;
  497. RaycastHit hit;
  498. var currentRot = Quaternion.Euler(player?.serverInput?.current?.aimAngles ?? Vector3.zero) * Vector3.forward;
  499. var ray = new Ray((player?.eyes?.position ?? Vector3.zero), currentRot);
  500. if (Physics.Raycast(ray, out hit, maxDist))
  501. {
  502. var ent = hit.GetEntity() ?? null;
  503. if (ent != null && !(ent?.IsDestroyed ?? true)) return ent;
  504. }
  505. return null;
  506. }
  507.  
  508. #endregion
  509. #region commands
  510.  
  511. [ConsoleCommand("wipedoordata")]
  512. private void nightdoorwipeccmd(ConsoleSystem.Arg arg)
  513. {
  514. if (arg.Connection != null) return;
  515. storedData.IDlist.Clear();
  516. storedData.TimeEntries.Clear();
  517. SaveFile();
  518. Puts(lang.GetMessage("WipeManual", this));
  519. }
  520.  
  521. [ChatCommand("timeperiod")]
  522. private void timeCmd(BasePlayer player, string command, string[] args)
  523. {
  524. if (!permission.UserHasPermission(player.UserIDString, createIntervalPerm))
  525. {
  526. SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  527. return;
  528. }
  529.  
  530. if (!useMulti)
  531. {
  532. SendReply(player, lang.GetMessage("TimeIntervalDisabled", this, player.UserIDString));
  533. return;
  534. }
  535.  
  536. if (args.Length < 1)
  537. {
  538. SendReply(player, lang.GetMessage("HowToUseTimeIntervals", this, player.UserIDString));
  539. return;
  540. }
  541.  
  542. switch (args[0].ToLower())
  543. {
  544. case "create":
  545. {
  546. if (args.Length < 4)
  547. {
  548. SendReply(player, lang.GetMessage("TimeIntevalSyntax", this, player.UserIDString));
  549. return;
  550. }
  551.  
  552. string Inputname = args[1];
  553. string time1 = args[2];
  554. string time2 = args[3];
  555.  
  556. foreach (var timeEntry in storedData.TimeEntries)
  557. {
  558. if (timeEntry.name.ToLower() == Inputname.ToLower())
  559. {
  560. SendReply(player, lang.GetMessage("TimeIntervalExists", this, player.UserIDString));
  561. return;
  562. }
  563. }
  564.  
  565. //Most complicated methods VVVVV
  566.  
  567. if (!time1.Contains(":") && !time2.Contains(":"))
  568. {
  569. SendReply(player, lang.GetMessage("TimeIntevalSyntax", this, player.UserIDString));
  570. return;
  571. }
  572.  
  573. string[] split1, split2;
  574. split2 = time2.Split(':');
  575. split1 = time1.Split(':');
  576. string[] allNumbers = { split1[0], split1[1], split2[0], split2[1] };
  577. foreach (string p in allNumbers)
  578. {
  579. foreach (var ew in p)
  580. {
  581. if (ew == '0' || ew == '1' || ew == '2' || ew == '3' || ew == '4' || ew == '5' || ew == '6' || ew == '7' || ew == '8' || ew == '9') continue;
  582.  
  583. else
  584. {
  585. SendReply(player, lang.GetMessage("TimeIntevalSyntax", this, player.UserIDString));
  586. return;
  587. }
  588. }
  589.  
  590. if (p.Length != 2)
  591. {
  592. SendReply(player, lang.GetMessage("TimeIntevalSyntax", this, player.UserIDString));
  593. return;
  594. }
  595. }
  596.  
  597. float a = GetFloat(time1);
  598. float b = GetFloat(time2);
  599.  
  600. if (a > b)
  601. {
  602. SendReply(player, lang.GetMessage("HowTo26Hour", this, player.UserIDString));
  603. return;
  604. }
  605.  
  606. TimeInfo entry = new TimeInfo(Inputname, time1, time2);
  607. storedData.TimeEntries.Add(entry);
  608. SendReply(player, lang.GetMessage("TimeIntervalCreated", this, player.UserIDString), Inputname, time1, time2);
  609. SaveFile();
  610. return;
  611. }
  612.  
  613. case "remove":
  614. {
  615. if (args.Length < 2)
  616. {
  617. SendReply(player, lang.GetMessage("TimeIntervalRemoveSyntax", this, player.UserIDString));
  618. return;
  619. }
  620.  
  621. string Inputname = args[1];
  622. List<TimeInfo> toRemove = new List<TimeInfo>();
  623. List<uint> idList = new List<uint>();
  624.  
  625. foreach (var entry in storedData.TimeEntries)
  626. {
  627. if (entry.name == Inputname && entry.name != "default")
  628. {
  629. toRemove.Add(entry);
  630. foreach (var ent in storedData.IDlist)
  631. {
  632. if (ent.Value == Inputname)
  633. {
  634. idList.Add(ent.Key);
  635. BaseNetworkable entity = BaseNetworkable.serverEntities.Find(ent.Key);
  636. SendReply(player, lang.GetMessage("TimeIntervalRemovedDoor", this, player.UserIDString), entity.transform.position.ToString());
  637. player.SendConsoleCommand("ddraw.sphere", 10f, Color.green, entity.transform.position, 1f);
  638. }
  639. }
  640.  
  641. SendReply(player, lang.GetMessage("TimeIntervalRemoved", this, player.UserIDString), entry.name);
  642. foreach (var ent2 in toRemove) storedData.TimeEntries.Remove(ent2);
  643. foreach (var ent3 in idList) storedData.IDlist.Remove(ent3);
  644. SaveFile();
  645. return;
  646. }
  647. }
  648. SendReply(player, lang.GetMessage("TimeIntervalNotFound", this, player.UserIDString), Inputname);
  649. return;
  650. }
  651.  
  652. case "list":
  653. {
  654. List<string> L = new List<string>();
  655. if (storedData.TimeEntries.Count < 1)
  656. {
  657. SendReply(player, lang.GetMessage("TimeIntervalNotSetUp", this, player.UserIDString));
  658. return;
  659. }
  660.  
  661. foreach (var entry in storedData.TimeEntries)
  662. L.Add(entry.name + " (" + entry.start + " - " + entry.end + ")");
  663.  
  664. string finished = string.Join("\n", L.ToArray());
  665. SendReply(player, lang.GetMessage("TimeIntervalList", this, player.UserIDString), finished);
  666. return;
  667. }
  668.  
  669. default:
  670. {
  671. SendReply(player, lang.GetMessage("TimeIntevalSyntax", this, player.UserIDString));
  672. return;
  673. }
  674. }
  675.  
  676. }
  677.  
  678. [ChatCommand("nd")]
  679. private void nightdoorcmd(BasePlayer player, string command, string[] args)
  680. {
  681. if (!permission.UserHasPermission(player.UserIDString, usePerm))
  682. {
  683. SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  684. return;
  685. }
  686.  
  687. if (args.Length < 1)
  688. {
  689. SendReply(player, lang.GetMessage("SyntaxError", this, player.UserIDString));
  690. return;
  691. }
  692.  
  693. BaseEntity ent = GetLookAtEntity(player, 10f);
  694.  
  695. string name = GetNameFromEntity(ent);
  696. Puts(name);
  697. switch (args[0].ToLower())
  698. {
  699. case "add":
  700. {
  701. if (ent == null)
  702. {
  703. SendReply(player, lang.GetMessage("NoEntity", this, player.UserIDString));
  704. return;
  705. }
  706.  
  707. if (!(ent is Door))
  708. {
  709. SendReply(player, lang.GetMessage("EntityNotDoor", this, player.UserIDString));
  710. return;
  711. }
  712.  
  713. if (storedData.IDlist.ContainsKey(ent.net.ID))
  714. {
  715. SendReply(player, lang.GetMessage("AlreadyLocked", this, player.UserIDString), name);
  716. return;
  717. }
  718.  
  719. if (args.Length < 2)
  720. {
  721. storedData.IDlist.Add(ent.net.ID, "default");
  722. SendReply(player, lang.GetMessage("DoorNowLocked", this, player.UserIDString), name);
  723. SaveFile();
  724. return;
  725. }
  726.  
  727. string tiName = args[1];
  728. if (string.IsNullOrEmpty(tiName))
  729. {
  730. SendReply(player, lang.GetMessage("TimeIntervalMissingTimePeriod", this, player.UserIDString));
  731. return;
  732. }
  733.  
  734. foreach (var entry in storedData.TimeEntries)
  735. {
  736. if (entry.name.ToLower() == tiName.ToLower())
  737. {
  738. storedData.IDlist.Add(ent.net.ID, entry.name);
  739. SendReply(player, lang.GetMessage("DoorCustomLocked", this, player.UserIDString), name, entry.name, entry.start, entry.end);
  740. SaveFile();
  741. return;
  742. }
  743. }
  744. SendReply(player, lang.GetMessage("TimeIntervalNotFound", this, player.UserIDString), tiName);
  745. return;
  746. }
  747.  
  748. case "remove":
  749. {
  750. if (ent == null)
  751. {
  752. SendReply(player, lang.GetMessage("NoEntity", this, player.UserIDString));
  753. return;
  754. }
  755.  
  756. if (!(ent is Door))
  757. {
  758. SendReply(player, lang.GetMessage("EntityNotDoor", this, player.UserIDString));
  759. return;
  760. }
  761.  
  762. if (!storedData.IDlist.ContainsKey(ent.net.ID))
  763. {
  764. SendReply(player, lang.GetMessage("NotTimeLocked", this, player.UserIDString), name);
  765. return;
  766. }
  767.  
  768. storedData.IDlist.Remove(ent.net.ID);
  769. SendReply(player, lang.GetMessage("DoorUnlocked", this, player.UserIDString), name);
  770. SaveFile();
  771. return;
  772. }
  773.  
  774. case "info":
  775. {
  776. if (ent == null)
  777. {
  778. SendReply(player, lang.GetMessage("NoEntity", this, player.UserIDString));
  779. return;
  780. }
  781.  
  782. if (!(ent is Door))
  783. {
  784. SendReply(player, lang.GetMessage("EntityNotDoor", this, player.UserIDString));
  785. return;
  786. }
  787.  
  788. if (!storedData.IDlist.ContainsKey(ent.net.ID))
  789. {
  790. SendReply(player, lang.GetMessage("NotTimeLocked", this, player.UserIDString), name);
  791. return;
  792. }
  793.  
  794. string type = storedData.IDlist[ent.net.ID];
  795. string start = "", end = "";
  796.  
  797. if (type == "default")
  798. {
  799. string p1, p2, p3, p4;
  800. p1 = (GetDateTime(startTime).Hour.ToString() == "0") ? "00" : GetDateTime(startTime).Hour.ToString();
  801. p2 = (GetDateTime(startTime).Minute.ToString() == "0") ? "00" : GetDateTime(startTime).Minute.ToString();
  802. p3 = (GetDateTime(endTime).Hour.ToString() == "0") ? "00" : GetDateTime(endTime).Hour.ToString();
  803. p4 = (GetDateTime(endTime).Minute.ToString() == "0") ? "00" : GetDateTime(endTime).Minute.ToString();
  804. start = p1 + ":" + p2;
  805. end = p3 + ":" + p4;
  806. SendReply(player, lang.GetMessage("InfoAboutDoor", this, player.UserIDString), name, type, start, end);
  807. return;
  808. }
  809.  
  810. foreach (var entry in storedData.TimeEntries)
  811. {
  812. if (entry.name == type)
  813. {
  814. start = entry.start;
  815. end = entry.end;
  816. }
  817. }
  818.  
  819. SendReply(player, lang.GetMessage("InfoAboutDoor", this, player.UserIDString), name, type, start, end);
  820. return;
  821. }
  822.  
  823. case "show":
  824. {
  825. if (storedData.IDlist.Count == 0)
  826. {
  827. SendReply(player, lang.GetMessage("NoLockedEnts", this, player.UserIDString));
  828. return;
  829. }
  830.  
  831. SendReply(player, lang.GetMessage("ShowingEnts", this, player.UserIDString));
  832. foreach (var entry in storedData.IDlist)
  833. {
  834. BaseNetworkable EntityN = BaseNetworkable.serverEntities.Find(entry.Key);
  835. if (EntityN == null)
  836. {
  837. CheckAllEntites();
  838. continue;
  839. }
  840. Vector3 pos = EntityN.transform.position;
  841. pos.y += 1f;
  842. player.SendConsoleCommand("ddraw.sphere", 10f, Color.green, pos, 1f);
  843. }
  844. return;
  845. }
  846.  
  847. case "help":
  848. {
  849. string start, end;
  850. string p1, p2, p3, p4;
  851. p1 = (GetDateTime(startTime).Hour.ToString() == "0") ? "00" : GetDateTime(startTime).Hour.ToString();
  852. p2 = (GetDateTime(startTime).Minute.ToString() == "0") ? "00" : GetDateTime(startTime).Minute.ToString();
  853. p3 = (GetDateTime(endTime).Hour.ToString() == "0") ? "00" : GetDateTime(endTime).Hour.ToString();
  854. p4 = (GetDateTime(endTime).Minute.ToString() == "0") ? "00" : GetDateTime(endTime).Minute.ToString();
  855. start = p1 + ":" + p2;
  856. end = p3 + ":" + p4;
  857.  
  858. SendReply(player, lang.GetMessage("ListOfCommands", this, player.UserIDString), start, end);
  859. return;
  860. }
  861.  
  862. default:
  863. {
  864. SendReply(player, lang.GetMessage("SyntaxError", this, player.UserIDString));
  865. return;
  866. }
  867. }
  868. }
  869. #endregion
  870. }
  871. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement