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

css_peace / first warden mute #69

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 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
7 changes: 3 additions & 4 deletions lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -10,7 +9,7 @@ namespace Jailbreak.English.Generic;

public class GenericCommandNotifications : IGenericCommandNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX =
public static readonly FormatObject GENERIC_PREFIX =
new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}JB{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Expand All @@ -21,11 +20,11 @@ public class GenericCommandNotifications : IGenericCommandNotifications, ILangua

public IView PlayerNotFound(string query)
{
return new SimpleView { PREFIX, $"Player '{query}' not found!" };
return new SimpleView { GENERIC_PREFIX, $"Player '{query}' not found!" };
}

public IView PlayerFoundMultiple(string query)
{
return new SimpleView { PREFIX, $"Multiple players found for '{query}'!" };
return new SimpleView { GENERIC_PREFIX, $"Multiple players found for '{query}'!" };
}
}
4 changes: 2 additions & 2 deletions lang/Jailbreak.English/Rebel/RebelNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Jailbreak.English.Rebel;

public class RebelNotifications : IRebelNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]")
public static readonly FormatObject REBEL_PREFIX = new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Plain = false,
Expand All @@ -19,5 +19,5 @@ public class RebelNotifications : IRebelNotifications, ILanguage<Formatting.Lang
};

public IView NO_LONGER_REBEL =>
new SimpleView() { PREFIX, "You are no longer a rebel." };
new SimpleView() { REBEL_PREFIX, "You are no longer a rebel." };
}
22 changes: 11 additions & 11 deletions lang/Jailbreak.English/Teams/RatioNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Jailbreak.English.Teams;

public class RatioNotifications : IRatioNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.LightRed}[{ChatColors.Red}JB{ChatColors.LightRed}]")
public static readonly FormatObject RATIO_PREFIX = new HiddenFormatObject($" {ChatColors.LightRed}[{ChatColors.Red}JB{ChatColors.LightRed}]")
{
// Hide in panorama and center text
Plain = false,
Expand All @@ -19,34 +19,34 @@ public class RatioNotifications : IRatioNotifications, ILanguage<Formatting.Lang
};

public IView NOT_ENOUGH_GUARDS =>
new SimpleView { PREFIX, "There's not enough guards in the queue!" };
new SimpleView { RATIO_PREFIX, "There's not enough guards in the queue!" };

public IView PLEASE_JOIN_GUARD_QUEUE =>
new SimpleView { PREFIX, "Type !guard to become a guard!" };
new SimpleView { RATIO_PREFIX, "Type !guard to become a guard!" };

public IView JOINED_GUARD_QUEUE =>
new SimpleView { PREFIX, "You've joined the guard queue!" };
new SimpleView { RATIO_PREFIX, "You've joined the guard queue!" };

public IView ALREADY_A_GUARD =>
new SimpleView { PREFIX, "You're already a guard!" };
new SimpleView { RATIO_PREFIX, "You're already a guard!" };

public IView YOU_WERE_AUTOBALANCED_PRISONER =>
new SimpleView
{
{ PREFIX, "You were autobalanced to the prisoner team!" }, SimpleView.NEWLINE,
{ PREFIX, "Please use !guard to join the guard team." }
{ RATIO_PREFIX, "You were autobalanced to the prisoner team!" }, SimpleView.NEWLINE,
{ RATIO_PREFIX, "Please use !guard to join the guard team." }
};

public IView ATTEMPT_TO_JOIN_FROM_TEAM_MENU =>
new SimpleView { PREFIX, "You were swapped back to the prisoner team!" };
new SimpleView { RATIO_PREFIX, "You were swapped back to the prisoner team!" };

public IView LEFT_GUARD =>
new SimpleView
{
{ PREFIX, "You are no longer a guard." }, SimpleView.NEWLINE,
{ PREFIX, "Please use !guard if you want to re-join the guard team." }
{ RATIO_PREFIX, "You are no longer a guard." }, SimpleView.NEWLINE,
{ RATIO_PREFIX, "Please use !guard if you want to re-join the guard team." }
};

public IView YOU_WERE_AUTOBALANCED_GUARD =>
new SimpleView { PREFIX, "You are now a guard!" };
new SimpleView { RATIO_PREFIX, "You are now a guard!" };
}
27 changes: 13 additions & 14 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -11,7 +10,7 @@ namespace Jailbreak.English.Warden;

public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.Lime}[{ChatColors.Green}WARDEN{ChatColors.Lime}]")
public static readonly FormatObject WARDEN_PREFIX = new HiddenFormatObject($" {ChatColors.Lime}[{ChatColors.Green}WARDEN{ChatColors.Lime}]")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should make make it readonly for all of them :P

{
// Hide in panorama and center text
Plain = false,
Expand All @@ -22,43 +21,43 @@ public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.La
public IView PICKING_SHORTLY =>
new SimpleView
{
{ PREFIX, "Picking a warden shortly" }, SimpleView.NEWLINE,
{ PREFIX, "To enter the warden queue, type !warden in chat." }
{ WARDEN_PREFIX, "Picking a warden shortly" }, SimpleView.NEWLINE,
{ WARDEN_PREFIX, "To enter the warden queue, type !warden in chat." }
};

public IView NO_WARDENS =>
new SimpleView { PREFIX, "No wardens in queue! The next player to run !warden will become a warden." };
new SimpleView { WARDEN_PREFIX, "No wardens in queue! The next player to run !warden will become a warden." };

public IView WARDEN_LEFT =>
new SimpleView { PREFIX, "The warden has left the game!" };
new SimpleView { WARDEN_PREFIX, "The warden has left the game!" };

public IView WARDEN_DIED =>
new SimpleView { PREFIX, "The warden has died!" };
new SimpleView { WARDEN_PREFIX, "The warden has died!" };

public IView BECOME_NEXT_WARDEN =>
new SimpleView { PREFIX, "Type !warden to become the next warden" };
new SimpleView { WARDEN_PREFIX, "Type !warden to become the next warden" };

public IView JOIN_RAFFLE =>
new SimpleView { PREFIX, "You've joined the warden raffle!" };
new SimpleView { WARDEN_PREFIX, "You've joined the warden raffle!" };

public IView LEAVE_RAFFLE =>
new SimpleView { PREFIX, "You've left the warden raffle!" };
new SimpleView { WARDEN_PREFIX, "You've left the warden raffle!" };

public IView PASS_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "has resigned from being warden!" };
return new SimpleView { WARDEN_PREFIX, player, "has resigned from being warden!" };
}

public IView NEW_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "is now the warden!" };
return new SimpleView { WARDEN_PREFIX, player, "is now the warden!" };
}

public IView CURRENT_WARDEN(CCSPlayerController? player)
{
if (player is not null)
return new SimpleView { PREFIX, "The current warden is", player };
return new SimpleView { WARDEN_PREFIX, "The current warden is", player };
else
return new SimpleView { PREFIX, "There is currently no warden!" };
return new SimpleView { WARDEN_PREFIX, "There is currently no warden!" };
}
}
46 changes: 46 additions & 0 deletions lang/Jailbreak.English/Warden/WardenPeaceNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views;
using static Jailbreak.English.Warden.WardenNotifications;
using static Jailbreak.English.Generic.GenericCommandNotifications;

namespace Jailbreak.English.Warden;

// todo add player name in notification and style it with colour
public class WardenPeaceNotifications : IWardenPeaceNotifications, ILanguage<Formatting.Languages.English>
{

public IView PLAYERS_MUTED_VIACMD =>
new SimpleView { WARDEN_PREFIX, "Prisoners and Guards are silenced for 10 seconds." };

public IView PLAYERS_UNMUTED_VIACMD =>
new SimpleView { WARDEN_PREFIX, "Prisoners and Guards can speak again."};

public IView PRISONERS_MUTED_STARTROUND =>
new SimpleView { GENERIC_PREFIX, "Prisoners are muted for 45 seconds."};

public IView PRISONERS_UNMUTED_STARTROUND =>
new SimpleView { GENERIC_PREFIX, "Prisoners can speak again." };

public IView PLAYERS_MUTED_FIRSTWARDEN =>
new SimpleView { GENERIC_PREFIX, "Prisoners and Guards are automatically silenced for 10 seconds."};

public IView PLAYERS_UNMUTED_FIRSTWARDEN =>
new SimpleView { GENERIC_PREFIX, "Prisoners and Guards can speak again." };

public IView PLAYERS_WARDEN_DIED =>
new SimpleView { GENERIC_PREFIX, "Warden is dead. Players can speak again." };

public IView PLAYERS_UNMUTED_ADMINCMD =>
new SimpleView { GENERIC_PREFIX, "An admin has removed the warden mute." };

public IView PLAYERS_UNMUTED_ROUNDEND =>
new SimpleView { GENERIC_PREFIX, "All players unmuted due to round end." };

public IView CSS_PEACE_COOLDOWN(float cooldownTime)
{
return new SimpleView { GENERIC_PREFIX, $"You\'re on cooldown for {Math.Ceiling(cooldownTime)} second{((Math.Ceiling(cooldownTime) == 1) ? "." : "s." )}" };
}


}
5 changes: 2 additions & 3 deletions mod/Jailbreak.Rebel/RebelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Logs;
using Jailbreak.Public.Mod.Rebel;

namespace Jailbreak.Rebel;

public class RebelManager : IPluginBehavior, IRebelService
{
private IRebelNotifications notifs;
//private IRebelNotifications notifs;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable? :)

private readonly IRichLogService _logs;
private readonly IRebelNotifications _notifs;
private readonly Dictionary<CCSPlayerController, long> _rebelTimes = new();
Expand Down Expand Up @@ -121,7 +120,7 @@ public bool MarkRebel(CCSPlayerController player, long time = 120)

public void UnmarkRebel(CCSPlayerController player)
{
notifs.NO_LONGER_REBEL.ToPlayerChat(player);
_notifs.NO_LONGER_REBEL.ToPlayerChat(player);
_logs.Append(_logs.Player(player), "is no longer a rebel.");

_rebelTimes.Remove(player);
Expand Down
1 change: 0 additions & 1 deletion mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
Expand Down
74 changes: 74 additions & 0 deletions mod/Jailbreak.Warden/Commands/WardenPeaceCommandsBehavior.cs
Copy link
Contributor

@MSWS MSWS Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a cooldown to the command?
Also, please add a message broadcasted to players that the warden issued peace.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.Warden;
using Jailbreak.Public.Mod.Plugin;
using Jailbreak.Warden.Global;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Extensions;
using static Jailbreak.Public.Mod.Warden.PeaceMuteOptions;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Utils;

namespace Jailbreak.Warden.Commands;

public class WardenPeaceCommandsBehavior : IPluginBehavior
{

private readonly IWardenPeaceService _peaceService;
private readonly IWardenPeaceNotifications _wardenPeaceNotifications;
private readonly IEventsService _eventsService;

private DateTime _lastUsedTime;

public WardenPeaceCommandsBehavior(IWardenPeaceService peaceService, IEventsService eventsService, IWardenPeaceNotifications wardenPeaceNotifications)
{
_peaceService = peaceService;
_eventsService = eventsService;
_wardenPeaceNotifications = wardenPeaceNotifications;

Func<bool> wardenDeathCallback = () =>
{
_peaceService.UnmutePrevMutedAlivePlayers(MuteReason.WARDEN_DIED, CsTeam.Terrorist, CsTeam.CounterTerrorist);
return true;
};

_eventsService.RegisterEventListener("warden_death_event", wardenDeathCallback);

}

[ConsoleCommand("css_peace", "Gives everybody some peace of mind by muting Prisoners/Guards for 10 seconds (warden is exempt from this).")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
public void Command_Peace(CCSPlayerController? invoker, CommandInfo command)
{

if (invoker == null) return;

// we only want the warden OR ADMIN to be able to run this!
if (!_peaceService.IsWarden(invoker) || !AdminManager.PlayerHasPermissions(invoker, "@css/generic")) return;

// we still need if css_peace command mute is active in a team because it may have ended because of various things but the cooldown wouldn't have expired yet.
if (_peaceService.IsMuteActiveInTeam(CsTeam.CounterTerrorist) && (DateTime.Now - _lastUsedTime).Seconds < WardenPeaceBehaviour._commandMuteTime)
{
_wardenPeaceNotifications.CSS_PEACE_COOLDOWN(WardenPeaceBehaviour._commandMuteTime - (DateTime.Now - _lastUsedTime).Seconds).ToAllChat();
return;
}

PeaceMuteOptions options = new PeaceMuteOptions(MuteReason.CSS_PEACE, WardenPeaceBehaviour._commandMuteTime, CsTeam.Terrorist, CsTeam.CounterTerrorist);
_peaceService.PeaceMute(options);
_lastUsedTime = DateTime.Now;

}

[ConsoleCommand("css_unpeace", "Lets the admins remove the warden mute.")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
[RequiresPermissionsOr("@css/ban", "@css/kick", "@css/generic")]
public void Command_UnPeace(CCSPlayerController? invoker, CommandInfo command)
{
if (invoker == null) return;
// this does nothing to teams that don't have any mutes, see the documentation for UnmutePrevMutedPlayers
_peaceService.UnmutePrevMutedAlivePlayers(MuteReason.ADMIN_REMOVED_PEACEMUTE, CsTeam.Terrorist, CsTeam.CounterTerrorist, CsTeam.Spectator, CsTeam.None);
}

}
Loading