using System; using Newtonsoft.Json; using Oxide.Core; using System.Collections.Generic; namespace Oxide.Plugins { [Info("C4Logger", "M&B-Studios", "1.0.0")] [Description("Logs C4 usage by players.")] public class C4Logger : RustPlugin { private const string PermissionUse = "c4logger.use"; #region Configuration private Configuration config; private class Configuration { [JsonProperty("Enable logging")] public bool LoggingEnabled { get; set; } = true; } protected override void LoadDefaultConfig() { config = new Configuration(); SaveConfig(); } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); if (config == null) LoadDefaultConfig(); SaveConfig(); } catch { PrintError("Configuration file is corrupt! Loading default config."); LoadDefaultConfig(); } } protected override void SaveConfig() => Config.WriteObject(config); #endregion private void Init() { permission.RegisterPermission(PermissionUse, this); LoadConfig(); } private void OnExplosiveThrown(BasePlayer player, BaseEntity entity) { if (!config.LoggingEnabled || entity == null || player == null || !(entity is TimedExplosive) || !permission.UserHasPermission(player.UserIDString, PermissionUse)) return; string c4UsageLog = $"[{DateTime.Now}] {player.displayName} ({player.UserIDString}) used C4 at position ({entity.transform.position.x}, {entity.transform.position.y}, {entity.transform.position.z})"; LogToFile("c4_usage", c4UsageLog, this, true); } } }