Skip to content

Commit d2e0c53

Browse files
fix: trying to access data that doesn't exist
1 parent fe76f6c commit d2e0c53

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/AutoCode.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ void OnEntitySpawned(CodeLock codeLock)
8787
return;
8888
}
8989

90+
// No data for player.
91+
if (!Data.Inst.playerCodes.ContainsKey(player.userID))
92+
{
93+
return;
94+
}
95+
9096
Data.Structure.PlayerSettings settings = Data.Inst.playerCodes[player.userID];
9197

9298
// Disabled for the player or they haven't set a code?
@@ -117,7 +123,8 @@ object CanUseLockedEntity(BasePlayer player, CodeLock codeLock)
117123
codeLock.hasCode &&
118124
codeLock.HasFlag(BaseEntity.Flags.Locked) &&
119125
Permissions.Oxide.UserHasPermission(player.UserIDString, Permissions.Use) &&
120-
Permissions.Oxide.UserHasPermission(player.UserIDString, Permissions.Try)
126+
Permissions.Oxide.UserHasPermission(player.UserIDString, Permissions.Try) &&
127+
Data.Inst.playerCodes.ContainsKey(player.userID)
121128
)
122129
{
123130
Data.Structure.PlayerSettings settings = Data.Inst.playerCodes[player.userID];
@@ -267,6 +274,12 @@ public void SetCode(BasePlayer player, string code)
267274
*/
268275
public void ToggleEnabled(BasePlayer player)
269276
{
277+
// Can't toggle until player has done their first enabled.
278+
if (!Data.Inst.playerCodes.ContainsKey(player.userID))
279+
{
280+
return;
281+
}
282+
270283
Data.Inst.playerCodes[player.userID].enabled = !Data.Inst.playerCodes[player.userID].enabled;
271284
player.ChatMessage(lang.GetMessage(Data.Inst.playerCodes[player.userID].enabled ? "Enabled" : "Disabled", this, player.UserIDString));
272285
}

0 commit comments

Comments
 (0)