Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow moderators to set the time left #94

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
<data name="NextRank" xml:space="preserve">
<value>You moved up to {Name} rank, congratulations!</value>
</data>
<data name="NoPermissions" xml:space="preserve">
<value>You do not have permissions to use this command</value>
</data>
<data name="PasswordCannotBeEmpty" xml:space="preserve">
<value>Password cannot be empty</value>
</data>
Expand Down
18 changes: 18 additions & 0 deletions src/Application/Maps/Systems/MapRotationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,22 @@ public void OnGameModeInit()
{
mapRotationService.StartRotation();
}

[PlayerCommand("settimeleft")]
public void SetTimeLeft(Player player, int minutes)
{
if (player.HasLowerRoleThan(RoleId.Moderator))
return;

var interval = new Minutes(minutes);
TimeLeft timeLeft = mapRotationService.TimeLeft;
Result result = timeLeft.SetInterval(interval);
if(result.IsFailed)
{
player.SendClientMessage(Color.Red, result.Message);
return;
}

mapTextDrawRenderer.UpdateTimeLeft(timeLeft);
}
}
16 changes: 16 additions & 0 deletions src/Application/Players/Extensions/PlayerRoleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CTF.Application.Players.Extensions;

public static class PlayerRoleExtensions
{
public static bool HasLowerRoleThan(this Player player, RoleId id)
{
PlayerInfo playerInfo = player.GetInfo();
if (playerInfo.HasLowerRoleThan(id))
{
player.SendClientMessage(Color.Red, Messages.NoPermissions);
return true;
}

return false;
}
}
Loading