Files
wwdpublic/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs
SimpleStation14 6949685f79 Mirror: Fix Playglobalsound Autocompletion (#319)
## Mirror of PR #26167: [Fix playglobalsound
autocompletion](https://github.com/space-wizards/space-station-14/pull/26167)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `65960facf522627c939a35a65b025ec49ffa5c52`

PR opened by <img
src="https://avatars.githubusercontent.com/u/31366439?v=4"
width="16"/><a href="https://github.com/metalgearsloth">
metalgearsloth</a> at 2024-03-16 03:02:08 UTC

---

PR changed 1 files with 3 additions and 1 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> Requires https://github.com/space-wizards/RobustToolbox/pull/4968


</details>

Co-authored-by: SimpleStation14 <Unknown>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
Co-authored-by: DEATHB4DEFEAT <zachcaffee@outlook.com>
2024-07-11 18:06:30 -07:00

119 lines
4.0 KiB
C#

using System.Linq;
using Content.Server.Audio;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Fun)]
public sealed class PlayGlobalSoundCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceManager _res = default!;
public string Command => "playglobalsound";
public string Description => Loc.GetString("play-global-sound-command-description");
public string Help => Loc.GetString("play-global-sound-command-help");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Filter filter;
var audio = AudioParams.Default;
bool replay = true;
switch (args.Length)
{
// No arguments, show command help.
case 0:
shell.WriteLine(Loc.GetString("play-global-sound-command-help"));
return;
// No users, play sound for everyone.
case 1:
// Filter.Broadcast does resolves IPlayerManager, so use this instead.
filter = Filter.Empty().AddAllPlayers(_playerManager);
break;
// One or more users specified.
default:
var volumeOffset = 0;
// Try to specify a new volume to play it at.
if (int.TryParse(args[1], out var volume))
{
audio = audio.WithVolume(volume);
volumeOffset = 1;
}
else
{
shell.WriteError(Loc.GetString("play-global-sound-command-volume-parse", ("volume", args[1])));
return;
}
// No users specified so play for them all.
if (args.Length == 2)
{
filter = Filter.Empty().AddAllPlayers(_playerManager);
}
else
{
replay = false;
filter = Filter.Empty();
// Skip the first argument, which is the sound path.
for (var i = 1 + volumeOffset; i < args.Length; i++)
{
var username = args[i];
if (!_playerManager.TryGetSessionByUsername(username, out var session))
{
shell.WriteError(Loc.GetString("play-global-sound-command-player-not-found", ("username", username)));
continue;
}
filter.AddPlayer(session);
}
}
break;
}
audio = audio.AddVolume(-8);
_entManager.System<ServerGlobalSoundSystem>().PlayAdminGlobal(filter, args[0], audio, replay);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var hint = Loc.GetString("play-global-sound-command-arg-path");
var options = CompletionHelper.AudioFilePath(args[0], _protoManager, _res);
return CompletionResult.FromHintOptions(options, hint);
}
if (args.Length == 2)
return CompletionResult.FromHint(Loc.GetString("play-global-sound-command-arg-volume"));
if (args.Length > 2)
{
var options = _playerManager.Sessions.Select<ICommonSession, string>(c => c.Name);
return CompletionResult.FromHintOptions(
options,
Loc.GetString("play-global-sound-command-arg-usern", ("user", args.Length - 2)));
}
return CompletionResult.Empty;
}
}