Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix bugs when round ends and new one starts
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonWizard committed Jan 20, 2019
1 parent 5f7b6ac commit 4f5eb60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions DisconnectDrop/DisconnectDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
28 changes: 19 additions & 9 deletions DisconnectDrop/MiscEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, List<Item>> inventories = new Dictionary<string, List<Item>>(); // steamId: inventory
public Dictionary<string, Vector> locations = new Dictionary<string, Vector>(); // steamId: position
private float pTime;
public Dictionary<string, List<Item>> inventories; // steamId: inventory
public Dictionary<string, Vector> 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<string, List<Item>>();
this.locations = new Dictionary<string, Vector>();

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)
Expand All @@ -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();
}
Expand Down Expand Up @@ -76,11 +91,6 @@ private void RealDisconnectHandler()
}
}

public void OnRoundRestart(RoundRestartEvent ev)
{
this.inventories = new Dictionary<string, List<Item>>();
this.locations = new Dictionary<string, Vector>();
}

private int refreshRate = 2;
private DateTime refreshCheck = DateTime.Now.AddSeconds(-1);
Expand Down

0 comments on commit 4f5eb60

Please sign in to comment.