fork download
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4.  
  5. namespace Oxide.Plugins
  6. {
  7. [Info("WipeKits", "Ryan", "1.1.1")]
  8. [Description("Puts a configurable cooldown on each kit depending on their kitname.")]
  9. internal class WipeKits : RustPlugin
  10. {
  11. #region Declaration
  12.  
  13. private static ConfigFile _cFile;
  14. private DateTime _cachedWipeTime;
  15. private const string Perm = "wipekits.bypass";
  16.  
  17. #endregion
  18.  
  19. #region Config
  20.  
  21. private class ConfigFile
  22. {
  23. [JsonProperty(PropertyName = "Kit Names & Cooldowns - Cooldowns (minutes)")]
  24. public Dictionary<string, float> Kits;
  25.  
  26. [JsonProperty(PropertyName = "Use GUI Kits (true/false)")]
  27. public bool UseGui { get; set; }
  28.  
  29. public static ConfigFile DefaultConfig()
  30. {
  31. return new ConfigFile
  32. {
  33. Kits = new Dictionary<string, float>()
  34. {
  35. ["kitname1"] = 5,
  36. ["kitname2"] = 5
  37. },
  38. UseGui = false
  39. };
  40. }
  41. }
  42.  
  43. protected override void LoadDefaultConfig()
  44. {
  45. PrintWarning("Loading default configuration file...");
  46. _cFile = ConfigFile.DefaultConfig();
  47. }
  48.  
  49. protected override void LoadConfig()
  50. {
  51. base.LoadConfig();
  52. try
  53. {
  54. _cFile = Config.ReadObject<ConfigFile>();
  55. if (_cFile == null)
  56. Regenerate();
  57. }
  58. catch { Regenerate(); }
  59. }
  60.  
  61. protected override void SaveConfig() => Config.WriteObject(_cFile);
  62.  
  63. private void Regenerate()
  64. {
  65. PrintWarning($"Configuration file at 'oxide/config/{Name}.json' seems to be corrupt, regenerating...");
  66. LoadDefaultConfig();
  67. }
  68.  
  69. #endregion Config
  70.  
  71. #region Lang
  72.  
  73. private void LoadDefaultMessages()
  74. {
  75. lang.RegisterMessages(new Dictionary<string, string>
  76. {
  77. // Time formatting
  78. ["DayFormat"] = "<color=orange>{0}</color> day and <color=orange>{1}</color> hours",
  79. ["DaysFormat"] = "<color=orange>{0}</color> days and <color=orange>{1}</color> hours",
  80. ["HourFormat"] = "<color=orange>{0}</color> hour and <color=orange>{1}</color> minutes",
  81. ["HoursFormat"] = "<color=orange>{0}</color> hours and <color=orange>{1}</color> minutes",
  82. ["MinFormat"] = "<color=orange>{0}</color> minute and <color=orange>{1}</color> seconds",
  83. ["MinsFormat"] = "<color=orange>{0}</color> minutes and <color=orange>{1}</color> seconds",
  84. ["SecsFormat"] = "<color=orange>{0}</color> seconds",
  85. // Can't use command
  86. ["CantUse"] = "The server's just wiped! Try again in {0}",
  87. }, this);
  88. }
  89.  
  90. #endregion Lang
  91.  
  92. #region Methods
  93.  
  94. private string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
  95.  
  96. private string GetFormattedTime(double time)
  97. {
  98. TimeSpan timeSpan = TimeSpan.FromSeconds(time);
  99. if (timeSpan.TotalSeconds < 1) return null;
  100.  
  101. if (Math.Floor(timeSpan.TotalDays) >= 1)
  102. return string.Format(timeSpan.Days > 1 ? Lang("DaysFormat", null, timeSpan.Days, timeSpan.Hours) : Lang("DayFormat", null, timeSpan.Days, timeSpan.Hours));
  103. if (Math.Floor(timeSpan.TotalMinutes) >= 60)
  104. return string.Format(timeSpan.Hours > 1 ? Lang("HoursFormat", null, timeSpan.Hours, timeSpan.Minutes) : Lang("HourFormat", null, timeSpan.Hours, timeSpan.Minutes));
  105. if (Math.Floor(timeSpan.TotalSeconds) >= 60)
  106. return string.Format(timeSpan.Minutes > 1 ? Lang("MinsFormat", null, timeSpan.Minutes, timeSpan.Seconds) : Lang("MinFormat", null, timeSpan.Minutes, timeSpan.Seconds));
  107. return Lang("SecsFormat", null, timeSpan.Seconds);
  108. }
  109.  
  110. private TimeSpan GetNextKitTime(float cooldown)
  111. {
  112. var timeSince = TimeSpan.FromSeconds((DateTime.UtcNow.ToLocalTime() - _cachedWipeTime).TotalSeconds);
  113. if (timeSince.TotalSeconds > cooldown * 60)
  114. return TimeSpan.Zero;
  115. var timeUntil = cooldown * 60 - Math.Round(timeSince.TotalSeconds);
  116. return TimeSpan.FromSeconds(timeUntil);
  117. }
  118.  
  119. #endregion
  120.  
  121. #region Hooks
  122.  
  123. private void OnServerInitialized() => _cachedWipeTime = SaveRestore.SaveCreatedTime.ToLocalTime();
  124.  
  125. private object OnPlayerCommand(ConsoleSystem.Arg arg)
  126. {
  127. var player = (BasePlayer) arg.Connection.player;
  128. if (arg.cmd.FullName.ToLower().Equals("chat.say") && arg.GetString(0).ToLower().StartsWith("/kit"))
  129. {
  130. var chatArgs = arg.GetString(0).ToLower().Split(' ');
  131. if (chatArgs.Length > 1 && _cFile.Kits.ContainsKey(chatArgs[1]))
  132. {
  133. var kitCooldown = _cFile.Kits[chatArgs[1]];
  134. if (GetNextKitTime(kitCooldown) != TimeSpan.Zero)
  135. {
  136. PrintToChat(player, Lang("CantUse", player.UserIDString, GetFormattedTime(GetNextKitTime(kitCooldown).TotalSeconds)));
  137. return true;
  138. }
  139. }
  140. }
  141. if (_cFile.UseGui && arg.cmd.FullName.ToLower().StartsWith("kit.gui") && _cFile.Kits.ContainsKey(arg.GetString(0).ToLower()))
  142. {
  143. var kitCooldown = _cFile.Kits[arg.GetString(0).ToLower()];
  144. if (GetNextKitTime(kitCooldown) != TimeSpan.Zero)
  145. {
  146. player.SendConsoleCommand("kit.close");
  147. PrintToChat(player, Lang("CantUse", player.UserIDString, GetFormattedTime(GetNextKitTime(kitCooldown).TotalSeconds)));
  148. return true;
  149. }
  150. }
  151. return null;
  152. }
  153.  
  154. #endregion
  155. }
  156. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `Newtonsoft' could not be found. Are you missing an assembly reference?
prog.cs(9,31): error CS0246: The type or namespace name `RustPlugin' could not be found. Are you missing an assembly reference?
prog.cs(43,33): error CS0115: `Oxide.Plugins.WipeKits.LoadDefaultConfig()' is marked as an override but no suitable method found to override
prog.cs(49,33): error CS0115: `Oxide.Plugins.WipeKits.LoadConfig()' is marked as an override but no suitable method found to override
prog.cs(61,33): error CS0115: `Oxide.Plugins.WipeKits.SaveConfig()' is marked as an override but no suitable method found to override
prog.cs(125,40): error CS0246: The type or namespace name `ConsoleSystem' could not be found. Are you missing an assembly reference?
Compilation failed: 6 error(s), 0 warnings
stdout
Standard output is empty