Skip to content

Commit

Permalink
Fix entity log formatting, prevent issues with invalid player handles…
Browse files Browse the repository at this point in the history
… in PlayerFormatObject
  • Loading branch information
Mooshua committed Feb 6, 2024
1 parent 869a66a commit 236784d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 2 additions & 4 deletions mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public HookResult OnButtonPressed(CEntityIOOutput output, string name, CEntityIn
CBaseEntity? ent = Utilities.GetEntityFromIndex<CBaseEntity>((int)caller.Index);


_logs.Append(
$"{_logs.Player(player)} pressed a button: {ent.Entity?.Name ?? "Unlabeled"} -> {output?.Connections?.TargetDesc ?? "None"}");
_logs.Append(_logs.Player(player) $"pressed a button: {ent.Entity?.Name ?? "Unlabeled"} -> {output?.Connections?.TargetDesc ?? "None"}");

Check failure on line 30 in mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, ',' expected

Check failure on line 30 in mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, ',' expected

Check failure on line 30 in mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, ',' expected

Check failure on line 30 in mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, ',' expected
return HookResult.Continue;
}

Expand All @@ -42,8 +41,7 @@ public HookResult OnBreakableBroken(CEntityIOOutput output, string name, CEntity
CBaseEntity? ent = Utilities.GetEntityFromIndex<CBaseEntity>((int)caller.Index);


_logs.Append(
$"{_logs.Player(player)} broke an entity: {ent.Entity?.Name ?? "Unlabeled"} -> {output?.Connections?.TargetDesc ?? "None"}");
_logs.Append(_logs.Player(player), $"broke an entity: {ent.Entity?.Name ?? "Unlabeled"} -> {output?.Connections?.TargetDesc ?? "None"}");
return HookResult.Continue;
}
}
5 changes: 4 additions & 1 deletion public/Jailbreak.Formatting/Core/FormatObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ public static FormatObject FromObject(object value)
{
return new StringFormatObject(value.ToString() ?? "null");
}
}

public override string ToString()
=> ToPlain();
}
12 changes: 6 additions & 6 deletions public/Jailbreak.Formatting/Objects/PlayerFormatObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ namespace Jailbreak.Formatting.Objects;

public class PlayerFormatObject : FormatObject
{
private readonly CCSPlayerController _player;
private readonly string _name;

public PlayerFormatObject(CCSPlayerController player)
{
_player = player;
_name = player.PlayerName;
}

public override string ToChat()
{
return $"{ChatColors.Yellow}{_player.PlayerName}";
return $"{ChatColors.Yellow}{_name}";
}

public override string ToPanorama()
{
return _player.PlayerName.Sanitize();
return _name.Sanitize();
}

public override string ToPlain()
{
return _player.PlayerName;
return _name;
}
}
}

0 comments on commit 236784d

Please sign in to comment.