-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
251 additions
and
30 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using Jailbreak.Formatting.Base; | ||
using Jailbreak.Formatting.Core; | ||
using Jailbreak.Formatting.Logistics; | ||
using Jailbreak.Formatting.Objects; | ||
using Jailbreak.Formatting.Views; | ||
|
||
namespace Jailbreak.English.Generic; | ||
|
||
public class GenericCommandNotifications : IGenericCommandNotifications, ILanguage<Formatting.Languages.English> | ||
{ | ||
public static FormatObject PREFIX = | ||
new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}JB{ChatColors.Darkred}]") | ||
{ | ||
// Hide in panorama and center text | ||
Plain = false, | ||
Panorama = false, | ||
Chat = true, | ||
}; | ||
|
||
public IView PlayerNotFound(string query) | ||
{ | ||
return new SimpleView(writer => | ||
writer | ||
.Line(PREFIX, $"Player '{query}' not found!")); | ||
} | ||
|
||
public IView PlayerFoundMultiple(string query) | ||
{ | ||
return new SimpleView(writer => | ||
writer | ||
.Line(PREFIX, $"Multiple players found for '{query}'!")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using CounterStrikeSharp.API.Modules.Commands.Targeting; | ||
using Jailbreak.Formatting.Extensions; | ||
using Jailbreak.Formatting.Views; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Jailbreak.Debug.Subcommands; | ||
|
||
public abstract class AbstractCommand | ||
{ | ||
protected IServiceProvider services; | ||
private IGenericCommandNotifications lang; | ||
|
||
protected AbstractCommand(IServiceProvider services) | ||
{ | ||
this.services = services; | ||
lang = services.GetRequiredService<IGenericCommandNotifications>(); | ||
} | ||
|
||
public abstract void OnCommand(CCSPlayerController? executor, WrappedInfo info); | ||
|
||
protected TargetResult? GetTarget(WrappedInfo command, int argIndex = 1, | ||
Func<CCSPlayerController, bool>? predicate = null) | ||
{ | ||
return GetTarget(command.info, argIndex + 1, predicate); | ||
} | ||
|
||
protected TargetResult? GetVulnerableTarget(WrappedInfo command, int argIndex = 1, | ||
Func<CCSPlayerController, bool>? predicate = null) | ||
{ | ||
return GetVulnerableTarget(command.info, argIndex + 1, predicate); | ||
} | ||
|
||
protected TargetResult? GetTarget(CommandInfo command, int argIndex = 1, | ||
Func<CCSPlayerController, bool>? predicate = null) | ||
{ | ||
var matches = command.GetArgTargetResult(argIndex); | ||
|
||
matches.Players = matches.Players.Where(player => | ||
player is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected }).ToList(); | ||
if (predicate != null) | ||
matches.Players = matches.Players.Where(predicate).ToList(); | ||
|
||
if (!matches.Any()) | ||
{ | ||
if (command.CallingPlayer != null) | ||
lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer); | ||
return null; | ||
} | ||
|
||
if (matches.Count() > 1 && command.GetArg(argIndex).StartsWith('@')) | ||
return matches; | ||
|
||
if (matches.Count() == 1 || !command.GetArg(argIndex).StartsWith('@')) | ||
return matches; | ||
|
||
if (command.CallingPlayer != null) | ||
lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer); | ||
return null; | ||
} | ||
|
||
internal TargetResult? GetVulnerableTarget(CommandInfo command, int argIndex = 1, | ||
Func<CCSPlayerController, bool>? predicate = null) | ||
{ | ||
return GetTarget(command, argIndex, | ||
(p) => command.CallingPlayer == null || | ||
command.CallingPlayer.CanTarget(p) && (predicate == null || predicate(p))); | ||
} | ||
|
||
internal TargetResult? GetSingleTarget(CommandInfo command, int argIndex = 1) | ||
{ | ||
var matches = command.GetArgTargetResult(argIndex); | ||
|
||
if (!matches.Any()) | ||
{ | ||
if (command.CallingPlayer != null) | ||
lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer); | ||
return null; | ||
} | ||
|
||
if (matches.Count() > 1) | ||
{ | ||
if (command.CallingPlayer != null) | ||
lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer); | ||
return null; | ||
} | ||
|
||
return matches; | ||
} | ||
|
||
internal string GetTargetLabel(CommandInfo info, int argIndex = 1) | ||
{ | ||
switch (info.GetArg(argIndex)) | ||
{ | ||
case "@all": | ||
return "all players"; | ||
case "@bots": | ||
return "all bots"; | ||
case "@humans": | ||
return "all humans"; | ||
case "@alive": | ||
return "alive players"; | ||
case "@dead": | ||
return "dead players"; | ||
case "@!me": | ||
return "all except self"; | ||
case "@me": | ||
return info.CallingPlayer == null ? "Console" : info.CallingPlayer.PlayerName; | ||
case "@ct": | ||
return "all CTs"; | ||
case "@t": | ||
return "all Ts"; | ||
case "@spec": | ||
return "all spectators"; | ||
default: | ||
var player = info.GetArgTargetResult(argIndex).FirstOrDefault(); | ||
if (player != null) | ||
return player.PlayerName; | ||
return "unknown"; | ||
} | ||
} | ||
|
||
|
||
internal string GetTargetLabels(CommandInfo info, int argIndex = 1) | ||
{ | ||
string label = GetTargetLabel(info, argIndex); | ||
if (label.ToLower().EndsWith("s")) | ||
return label + "'"; | ||
return label + "'s"; | ||
} | ||
} | ||
|
||
public static class CommandExtensions | ||
|
||
{ | ||
internal static bool CanTarget(this CCSPlayerController controller, CCSPlayerController target) | ||
{ | ||
if (!target.IsValid) return false; | ||
if (target.Connected != PlayerConnectedState.PlayerConnected) return false; | ||
if (target.IsBot || target.IsHLTV) return true; | ||
return AdminManager.CanPlayerTarget(controller, target); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using Jailbreak.Formatting.Views; | ||
using Jailbreak.Public.Mod.Rebel; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Jailbreak.Debug.Subcommands; | ||
|
||
// css_markrebel [player] <duration> | ||
public class MarkRebel : Executor | ||
public class MarkRebel : AbstractCommand | ||
{ | ||
|
||
public MarkRebel() | ||
public MarkRebel(IServiceProvider services) : base(services) | ||
{ | ||
|
||
} | ||
|
||
public void HandleExecution(CCSPlayerController? executor, WrappedInfo info) | ||
public override void OnCommand(CCSPlayerController? executor, WrappedInfo info) | ||
{ | ||
if (executor == null) | ||
if (info.ArgCount == 1) | ||
{ | ||
info.ReplyToCommand("Specify target?"); | ||
return; | ||
} | ||
|
||
if (info.ArgCount == 1) | ||
var target = GetVulnerableTarget(info); | ||
if (target == null) | ||
return; | ||
|
||
var duration = 120; | ||
if(info.ArgCount == 3) | ||
{ | ||
if (!int.TryParse(info.GetArg(2), out duration)) | ||
{ | ||
info.ReplyToCommand("Invalid duration"); | ||
return; | ||
} | ||
} | ||
|
||
foreach (var player in target.Players) | ||
{ | ||
// asdf | ||
services.GetRequiredService<IRebelService>().MarkRebel(player, duration); | ||
} | ||
info.ReplyToCommand($"Marked {target.Players.Count()} players as rebels for {duration} seconds"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Jailbreak.Formatting.Base; | ||
|
||
namespace Jailbreak.Formatting.Views; | ||
|
||
public interface IGenericCommandNotifications | ||
{ | ||
public IView PlayerNotFound(string query); | ||
public IView PlayerFoundMultiple(string query); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.