From 4f5eb60dd639bff6cbc88e6cbbc7afce6b8c186c Mon Sep 17 00:00:00 2001 From: Spooky Date: Sun, 20 Jan 2019 13:23:29 -0700 Subject: [PATCH] Fix bugs when round ends and new one starts --- DisconnectDrop/DisconnectDrop.cs | 6 +++--- DisconnectDrop/MiscEventHandler.cs | 28 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/DisconnectDrop/DisconnectDrop.cs b/DisconnectDrop/DisconnectDrop.cs index 2ef6983..0e64360 100644 --- a/DisconnectDrop/DisconnectDrop.cs +++ b/DisconnectDrop/DisconnectDrop.cs @@ -11,10 +11,10 @@ namespace DisconnectDrop name = "DisconnectDrop", description = "Drops player items on disconnection.", id = "xyz.wizardlywonders.DisconnectDrop", - version = "1.5", + version = "1.6.0", SmodMajor = 3, - SmodMinor = 1, - SmodRevision = 22 + SmodMinor = 2, + SmodRevision = 2 )] class DisconnectDrop : Plugin { diff --git a/DisconnectDrop/MiscEventHandler.cs b/DisconnectDrop/MiscEventHandler.cs index 24d032d..27b5aaf 100644 --- a/DisconnectDrop/MiscEventHandler.cs +++ b/DisconnectDrop/MiscEventHandler.cs @@ -10,19 +10,32 @@ namespace DisconnectDrop { - class MiscEventHandler : IEventHandlerPlayerJoin, IEventHandlerDisconnect, IEventHandlerRoundRestart, IEventHandlerFixedUpdate, IEventHandlerWaitingForPlayers + class MiscEventHandler : IEventHandlerPlayerJoin, IEventHandlerDisconnect, IEventHandlerFixedUpdate, IEventHandlerWaitingForPlayers, IEventHandlerRoundEnd { private readonly DisconnectDrop plugin; - private float pTime = 0; - public Dictionary> inventories = new Dictionary>(); // steamId: inventory - public Dictionary locations = new Dictionary(); // steamId: position + private float pTime; + public Dictionary> inventories; // steamId: inventory + public Dictionary locations; // steamId: position + bool roundOver; public MiscEventHandler(DisconnectDrop plugin) => this.plugin = plugin; public void OnWaitingForPlayers(WaitingForPlayersEvent ev) { if (!this.plugin.GetConfigBool("ddrop_enable")) this.plugin.pluginManager.DisablePlugin(plugin); + + this.inventories = new Dictionary>(); + this.locations = new Dictionary(); + + this.pTime = 0; + this.roundOver = false; + } + + // this is crucial so inventories aren't mass-dropped on server restart + public void OnRoundEnd(RoundEndEvent ev) + { + this.roundOver = true; } public void OnPlayerJoin(PlayerJoinEvent ev) @@ -33,6 +46,8 @@ public void OnPlayerJoin(PlayerJoinEvent ev) public void OnDisconnect(DisconnectEvent ev) { + if (this.roundOver) return; + Thread myThread = new Thread(new ThreadStart(RealDisconnectHandler)); myThread.Start(); } @@ -76,11 +91,6 @@ private void RealDisconnectHandler() } } - public void OnRoundRestart(RoundRestartEvent ev) - { - this.inventories = new Dictionary>(); - this.locations = new Dictionary(); - } private int refreshRate = 2; private DateTime refreshCheck = DateTime.Now.AddSeconds(-1);