Prevent errors from OnPlayerLeave() returning NULL

I suffered from some errors when I started the script. I soon found out, that the client detects some players leaving and I was wondering why, because there was not even a leaving message. I soon found out that the errors came from OnPlayerLeave() which returned a UUID but the name parameter was NULL. I don't know whether this is a bug in the client, but this should fix it for the script.
This commit is contained in:
Daenges 2021-06-02 22:58:00 +02:00 committed by ORelio
parent 6b29c97a05
commit 061b71befc

View file

@ -316,20 +316,36 @@ class DiscordWebhook : ChatBot
}
public override void OnPlayerJoin(Guid uuid, string name)
{
if (uuid.ToString() != string.Empty && name != string.Empty &&
uuid.ToString() != null && name != null)
{
if (settings.GetNamesToUuidMojangCache().ContainsKey(name))
{
settings.GetNamesToUuidMojangCache().Remove(name);
}
}
else
{
LogDebugToConsole(string.Format("Invalid player joined the game! UUID: {0}, Playername: {1}", uuid.ToString(), name));
}
}
public override void OnPlayerLeave(Guid uuid, string name)
{
if (uuid.ToString() != string.Empty && name != string.Empty &&
uuid.ToString() != null && name != null)
{
if (!settings.GetNamesToUuidMojangCache().ContainsKey(name))
{
settings.GetNamesToUuidMojangCache().Add(name, uuid.ToString());
}
}
else
{
LogDebugToConsole(string.Format("Invalid player left the game! UUID: {0}, Playername: {1}", uuid.ToString(), name));
}
}
public override bool OnDisconnect(DisconnectReason reason, string message)
{
@ -768,4 +784,3 @@ class DiscordWebhook : ChatBot
else { return GetHelp(); }
}
}