Skip to content

Commit

Permalink
Merge pull request #6 from pandathebeasty/feature/replace_color_place…
Browse files Browse the repository at this point in the history
…holders

Update command listener and replace color placeholders from "[]" to "{}"
  • Loading branch information
Quake1011 authored Jun 27, 2024
2 parents 08fb17d + a1c59b1 commit 5414b39
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
14 changes: 7 additions & 7 deletions build/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"medic.AliveMsg": "{0} [default]You need be alive to use this command.",
"medic.NoAccess": "{0} [default]You don't have access to use this command.",
"medic.LimitReached": "{0} [default]Limit has been reached. Total: [red]|{1}|[default].",
"medic.NoMoney": "{0} [default]Not enough money to use medic. You need [red]|{1}$|[default].",
"medic.MinHealth": "{0} [default]You need [red]{1}HP [default]or less to use medic.",
"medic.FullHP": "{0} [default]You have [red]full HP [default]already.",
"medic.HealMsg": "{0} [default]Player [red]{1} [default]used medic([red]+{2}HP[default])."
"medic.AliveMsg": "{0} {default}You need be alive to use this command.",
"medic.NoAccess": "{0} {default}You don't have access to use this command.",
"medic.LimitReached": "{0} {default}Limit has been reached. Total: {red}|{1}|{default}.",
"medic.NoMoney": "{0} {default}Not enough money to use medic. You need {red}|{1}$|{default}.",
"medic.MinHealth": "{0} {default}You need {red}{1}HP {default}or less to use medic.",
"medic.FullHP": "{0} {default}You have {red}full HP {default}already.",
"medic.HealMsg": "{0} {default}Player {red}{1} {default}used medic({red}+{2}HP{default})."
}
Binary file modified build/medic.dll
Binary file not shown.
Binary file modified build/medic.pdb
Binary file not shown.
82 changes: 52 additions & 30 deletions src/Medic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace medic;
public class ConfigGen : BasePluginConfig
{
[JsonPropertyName("PluginTag")]
public string PluginTag { get; init; } = " [red][Medic]";
public string PluginTag { get; init; } = " {red}[Medic]";
[JsonPropertyName("MinHealth")]
public int MinHealth { get; init; } = 40;
[JsonPropertyName("HealHealth")]
Expand All @@ -34,14 +34,14 @@ public class ConfigGen : BasePluginConfig
[JsonPropertyName("HealFailureSound")]
public string HealFailureSound { get; init; } = "buttons/blip2";
[JsonPropertyName("ConfigVersion")]
public override int Version { get; set; } = 2;
public override int Version { get; set; } = 3;
}

[MinimumApiVersion(225)]
public class Medic : BasePlugin, IPluginConfig<ConfigGen>
{
public override string ModuleName => "Medic";
public override string ModuleVersion => "0.1";
public override string ModuleVersion => "0.1.1";
public override string ModuleAuthor => "Quake1011, GSM-RO & panda.";
public ConfigGen Config { get; set; } = null!;
private static readonly string AssemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? "";
Expand Down Expand Up @@ -69,31 +69,37 @@ public class Medic : BasePlugin, IPluginConfig<ConfigGen>
}
private static readonly Dictionary<string, char> ColorMap = new Dictionary<string, char>
{
{ "[default]", ChatColors.Default },
{ "[white]", ChatColors.White },
{ "[darkred]", ChatColors.DarkRed },
{ "[green]", ChatColors.Green },
{ "[lightyellow]", ChatColors.LightYellow },
{ "[lightblue]", ChatColors.LightBlue },
{ "[olive]", ChatColors.Olive },
{ "[lime]", ChatColors.Lime },
{ "[red]", ChatColors.Red },
{ "[lightpurple]", ChatColors.LightPurple },
{ "[purple]", ChatColors.Purple },
{ "[grey]", ChatColors.Grey },
{ "[yellow]", ChatColors.Yellow },
{ "[gold]", ChatColors.Gold },
{ "[silver]", ChatColors.Silver },
{ "[blue]", ChatColors.Blue },
{ "[darkblue]", ChatColors.DarkBlue },
{ "[bluegrey]", ChatColors.BlueGrey },
{ "[magenta]", ChatColors.Magenta },
{ "[lightred]", ChatColors.LightRed },
{ "[orange]", ChatColors.Orange }
{ "{default}", ChatColors.Default },
{ "{white}", ChatColors.White },
{ "{darkred}", ChatColors.DarkRed },
{ "{green}", ChatColors.Green },
{ "{lightyellow}", ChatColors.LightYellow },
{ "{lightblue}", ChatColors.LightBlue },
{ "{olive}", ChatColors.Olive },
{ "{lime}", ChatColors.Lime },
{ "{red}", ChatColors.Red },
{ "{lightpurple}", ChatColors.LightPurple },
{ "{purple}", ChatColors.Purple },
{ "{grey}", ChatColors.Grey },
{ "{yellow}", ChatColors.Yellow },
{ "{gold}", ChatColors.Gold },
{ "{silver}", ChatColors.Silver },
{ "{blue}", ChatColors.Blue },
{ "{darkblue}", ChatColors.DarkBlue },
{ "{bluegrey}", ChatColors.BlueGrey },
{ "{magenta}", ChatColors.Magenta },
{ "{lightred}", ChatColors.LightRed },
{ "{orange}", ChatColors.Orange }
};

private string ReplaceColorPlaceholders(string message)
{

if (!string.IsNullOrEmpty(message) && message[0] != ' ')
{
message = " " + message;
}

foreach (var colorPlaceholder in ColorMap)
{
message = message.Replace(colorPlaceholder.Key, colorPlaceholder.Value.ToString());
Expand All @@ -113,6 +119,8 @@ public override void Load(bool hotReload)
{
RegisterEventHandler<EventRoundStart>(OnRoundStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);

RegisterCommands();

RegisterListener<Listeners.OnMapStart>(_ =>
{
Expand Down Expand Up @@ -144,12 +152,26 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)

return HookResult.Continue;
}

private void RegisterCommands()
{
AddCommand($"css_medic", "Heal player", (player, info) =>
{
OnCommandMedic(player, info);
});

AddCommand($"css_medkit", "Heal player", (player, info) =>
{
OnCommandMedic(player, info);
});

[ConsoleCommand("css_medkit", "Heal player")]
[ConsoleCommand("css_medic", "Heal player")]
[ConsoleCommand("css_doctor", "Heal player")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnCommand(CCSPlayerController? player, CommandInfo info)
AddCommand($"css_doctor", "Heal player", (player, info) =>
{
OnCommandMedic(player, info);
});
}

private void OnCommandMedic(CCSPlayerController? player, CommandInfo info)
{
if (player == null)
return;
Expand Down
14 changes: 7 additions & 7 deletions src/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"medic.AliveMsg": "{0} [default]You need be alive to use this command.",
"medic.NoAccess": "{0} [default]You don't have access to use this command.",
"medic.LimitReached": "{0} [default]Limit has been reached. Total: [red]|{1}|[default].",
"medic.NoMoney": "{0} [default]Not enough money to use medic. You need [red]|{1}$|[default].",
"medic.MinHealth": "{0} [default]You need [red]{1}HP [default]or less to use medic.",
"medic.FullHP": "{0} [default]You have [red]full HP [default]already.",
"medic.HealMsg": "{0} [default]Player [red]{1} [default]used medic([red]+{2}HP[default])."
"medic.AliveMsg": "{0} {default}You need be alive to use this command.",
"medic.NoAccess": "{0} {default}You don't have access to use this command.",
"medic.LimitReached": "{0} {default}Limit has been reached. Total: {red}|{1}|{default}.",
"medic.NoMoney": "{0} {default}Not enough money to use medic. You need {red}|{1}$|{default}.",
"medic.MinHealth": "{0} {default}You need {red}{1}HP {default}or less to use medic.",
"medic.FullHP": "{0} {default}You have {red}full HP {default}already.",
"medic.HealMsg": "{0} {default}Player {red}{1} {default}used medic({red}+{2}HP{default})."
}

0 comments on commit 5414b39

Please # to comment.