diff --git a/DisconnectDrop/DisconnectDrop.cs b/DisconnectDrop/DisconnectDrop.cs index 0e64360..98c563f 100644 --- a/DisconnectDrop/DisconnectDrop.cs +++ b/DisconnectDrop/DisconnectDrop.cs @@ -11,7 +11,7 @@ namespace DisconnectDrop name = "DisconnectDrop", description = "Drops player items on disconnection.", id = "xyz.wizardlywonders.DisconnectDrop", - version = "1.6.0", + version = "1.6.1", SmodMajor = 3, SmodMinor = 2, SmodRevision = 2 @@ -32,6 +32,7 @@ public override void Register() { // Register config settings this.AddConfig(new ConfigSetting("ddrop_enable", true, SettingType.BOOL, true, "Whether DisconnectDrop should be enabled on server start.")); + this.AddConfig(new ConfigSetting("ddrop_debug", false, SettingType.BOOL, true, "Enables debugging output for DisconnectDrop.")); this.AddConfig(new ConfigSetting("ddrop_inventory_refreshrate", 2, SettingType.NUMERIC, true, "How often player inventories are cached (in seconds).")); // Register events diff --git a/DisconnectDrop/MiscEventHandler.cs b/DisconnectDrop/MiscEventHandler.cs index c7dc866..e7bf1c4 100644 --- a/DisconnectDrop/MiscEventHandler.cs +++ b/DisconnectDrop/MiscEventHandler.cs @@ -14,22 +14,29 @@ class MiscEventHandler : IEventHandlerPlayerJoin, IEventHandlerDisconnect, IEven { private readonly DisconnectDrop plugin; + private bool debugging; + private float pTime = 0; private bool roundOver = true; public Dictionary> inventories = new Dictionary>(); // steamId: inventory public Dictionary locations = new Dictionary(); // steamId: position - public MiscEventHandler(DisconnectDrop plugin) => this.plugin = plugin; + public MiscEventHandler(DisconnectDrop plugin) + { + this.plugin = plugin; + this.debugging = this.plugin.GetConfigBool("ddrop_debug"); + } public void OnWaitingForPlayers(WaitingForPlayersEvent ev) { if (!this.plugin.GetConfigBool("ddrop_enable")) this.plugin.pluginManager.DisablePlugin(plugin); + // refresh these on round restart this.inventories = new Dictionary>(); this.locations = new Dictionary(); - this.pTime = 0; + this.debugging = this.plugin.GetConfigBool("ddrop_debug"); } // this is crucial so inventories aren't mass-dropped on server restart @@ -53,6 +60,7 @@ public void OnDisconnect(DisconnectEvent ev) { if (this.roundOver) return; + this.Debug("Dropping player inventory."); Thread myThread = new Thread(new ThreadStart(RealDisconnectHandler)); myThread.Start(); } @@ -143,5 +151,12 @@ public void OnFixedUpdate(FixedUpdateEvent ev) } } } + + private void Debug(string str) + { + if (!this.debugging) return; + + this.plugin.Info("DEBUG: " + str); + } } }