mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-09-27 20:17:04 +02:00
Merge branch 'main' of https://github.com/Cruze03/CS2-SimpleAdmin
This commit is contained in:
commit
a3dccbaa1e
19 changed files with 235 additions and 33 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
using System.Diagnostics;
|
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ using CounterStrikeSharp.API.Core.Attributes;
|
||||||
using CounterStrikeSharp.API.Core.Capabilities;
|
using CounterStrikeSharp.API.Core.Capabilities;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
using CS2_SimpleAdmin.Managers;
|
using CS2_SimpleAdmin.Managers;
|
||||||
using CS2_SimpleAdminApi;
|
using CS2_SimpleAdminApi;
|
||||||
|
|
@ -12,7 +11,7 @@ using MySqlConnector;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
[MinimumApiVersion(276)]
|
[MinimumApiVersion(279)]
|
||||||
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
||||||
{
|
{
|
||||||
internal static CS2_SimpleAdmin Instance { get; private set; } = new();
|
internal static CS2_SimpleAdmin Instance { get; private set; } = new();
|
||||||
|
|
@ -20,7 +19,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||||
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
||||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||||
public override string ModuleVersion => "1.6.3b";
|
public override string ModuleVersion => "1.6.5a";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
if (caller == null) return true;
|
if (caller == null) return true;
|
||||||
|
|
||||||
bool canPermBan = AdminManager.PlayerHasPermissions(caller, "@css/permban");
|
var canPermBan = AdminManager.PlayerHasPermissions(caller, "@css/permban");
|
||||||
|
|
||||||
if (duration <= 0 && canPermBan == false)
|
if (duration <= 0 && canPermBan == false)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
|
@ -497,13 +496,13 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
if (_localizer == null || caller == null) return;
|
if (_localizer == null || caller == null) return;
|
||||||
|
|
||||||
var disconnectedMenu = MenuApi?.NewMenu(_localizer["sa_menu_disconnected_title"]);
|
var disconnectedMenu = Helper.CreateMenu(_localizer["sa_menu_disconnected_title"]);
|
||||||
|
|
||||||
DisconnectedPlayers.ForEach(player =>
|
DisconnectedPlayers.ForEach(player =>
|
||||||
{
|
{
|
||||||
disconnectedMenu?.AddMenuOption(player.Name, (_, _) =>
|
disconnectedMenu?.AddMenuOption(player.Name, (_, _) =>
|
||||||
{
|
{
|
||||||
var disconnectedMenuAction = MenuApi?.NewMenu(_localizer["sa_menu_disconnected_action_title"]);
|
var disconnectedMenuAction = Helper.CreateMenu(_localizer["sa_menu_disconnected_action_title"]);
|
||||||
disconnectedMenuAction?.AddMenuOption(_localizer["sa_ban"], (_, _) =>
|
disconnectedMenuAction?.AddMenuOption(_localizer["sa_ban"], (_, _) =>
|
||||||
{
|
{
|
||||||
DurationMenu.OpenMenu(caller, _localizer["sa_ban"], player, (_, _, duration) =>
|
DurationMenu.OpenMenu(caller, _localizer["sa_ban"], player, (_, _, duration) =>
|
||||||
|
|
@ -567,7 +566,7 @@ public partial class CS2_SimpleAdmin
|
||||||
|
|
||||||
var userId = player.UserId.Value;
|
var userId = player.UserId.Value;
|
||||||
|
|
||||||
IMenu? warnsMenu = MenuApi?.NewMenu(_localizer["sa_admin_warns_menu_title", player.PlayerName]);
|
IMenu? warnsMenu = Helper.CreateMenu(_localizer["sa_admin_warns_menu_title", player.PlayerName]);
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CS2_SimpleAdmin.Managers;
|
using CS2_SimpleAdmin.Managers;
|
||||||
|
|
@ -50,6 +49,7 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
||||||
if (!caller.CanTarget(player)) return;
|
if (!caller.CanTarget(player)) return;
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Set default caller name if not provided
|
// Set default caller name if not provided
|
||||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||||
|
|
@ -126,6 +126,7 @@ public partial class CS2_SimpleAdmin
|
||||||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out var time);
|
int.TryParse(command.GetArg(2), out var time);
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Get player and admin info
|
// Get player and admin info
|
||||||
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
||||||
|
|
@ -264,6 +265,7 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
||||||
if (!caller.CanTarget(player)) return;
|
if (!caller.CanTarget(player)) return;
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Set default caller name if not provided
|
// Set default caller name if not provided
|
||||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||||
|
|
@ -344,6 +346,7 @@ public partial class CS2_SimpleAdmin
|
||||||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out var time);
|
int.TryParse(command.GetArg(2), out var time);
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Get player and admin info
|
// Get player and admin info
|
||||||
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
||||||
|
|
@ -486,6 +489,7 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
||||||
if (!caller.CanTarget(player)) return;
|
if (!caller.CanTarget(player)) return;
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Set default caller name if not provided
|
// Set default caller name if not provided
|
||||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||||
|
|
@ -506,6 +510,7 @@ public partial class CS2_SimpleAdmin
|
||||||
|
|
||||||
// Add penalty to the player's penalty manager
|
// Add penalty to the player's penalty manager
|
||||||
PlayerPenaltyManager.AddPenalty(player.Slot, PenaltyType.Silence, Time.ActualDateTime().AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player.Slot, PenaltyType.Silence, Time.ActualDateTime().AddMinutes(time), time);
|
||||||
|
player.VoiceFlags = VoiceFlags.Muted;
|
||||||
|
|
||||||
// Determine message keys and arguments based on silence time (permanent or timed)
|
// Determine message keys and arguments based on silence time (permanent or timed)
|
||||||
var (messageKey, activityMessageKey, playerArgs, adminActivityArgs) = time == 0
|
var (messageKey, activityMessageKey, playerArgs, adminActivityArgs) = time == 0
|
||||||
|
|
@ -566,6 +571,7 @@ public partial class CS2_SimpleAdmin
|
||||||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out var time);
|
int.TryParse(command.GetArg(2), out var time);
|
||||||
|
if (!CheckValidMute(caller, time)) return;
|
||||||
|
|
||||||
// Get player and admin info
|
// Get player and admin info
|
||||||
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
||||||
|
|
@ -672,4 +678,22 @@ public partial class CS2_SimpleAdmin
|
||||||
command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}.");
|
command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CheckValidMute(CCSPlayerController? caller, int duration)
|
||||||
|
{
|
||||||
|
if (caller == null) return true;
|
||||||
|
|
||||||
|
var canPermMute = AdminManager.PlayerHasPermissions(caller, "@css/permmute");
|
||||||
|
|
||||||
|
if (duration <= 0 && canPermMute == false)
|
||||||
|
{
|
||||||
|
caller.PrintToChat($"{_localizer!["sa_prefix"]} {_localizer["sa_ban_perm_restricted"]}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration <= Config.OtherSettings.MaxMuteDuration || canPermMute) return true;
|
||||||
|
|
||||||
|
caller.PrintToChat($"{_localizer!["sa_prefix"]} {_localizer["sa_ban_max_duration_exceeded", Config.OtherSettings.MaxMuteDuration]}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
|
@ -34,7 +33,7 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||||
{
|
{
|
||||||
IMenu? voteMenu = MenuApi?.NewMenu(_localizer["sa_admin_vote_menu_title", question]);
|
IMenu? voteMenu = Helper.CreateMenu(_localizer["sa_admin_vote_menu_title", question]);
|
||||||
if (voteMenu == null)
|
if (voteMenu == null)
|
||||||
return;
|
return;
|
||||||
//ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
|
//ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,18 +67,11 @@ public partial class CS2_SimpleAdmin
|
||||||
var weaponName = command.GetArg(2);
|
var weaponName = command.GetArg(2);
|
||||||
|
|
||||||
// check if item is typed
|
// check if item is typed
|
||||||
if (weaponName.Length < 5)
|
// if (weaponName.Length < 2)
|
||||||
{
|
// {
|
||||||
command.ReplyToCommand($"No weapon typed.");
|
// command.ReplyToCommand($"No weapon typed.");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// check if item is valid
|
|
||||||
if (!weaponName.Contains("weapon_") && !weaponName.Contains("item_"))
|
|
||||||
{
|
|
||||||
command.ReplyToCommand($"{weaponName} is not a valid item.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if weapon is knife
|
// check if weapon is knife
|
||||||
if (weaponName.Contains("_knife") || weaponName.Contains("bayonet"))
|
if (weaponName.Contains("_knife") || weaponName.Contains("bayonet"))
|
||||||
|
|
@ -105,9 +98,22 @@ public partial class CS2_SimpleAdmin
|
||||||
|
|
||||||
// Set default caller name if not provided
|
// Set default caller name if not provided
|
||||||
callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console";
|
callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console";
|
||||||
|
var weapons = WeaponHelper.GetWeaponsByPartialName(weaponName);
|
||||||
|
|
||||||
|
switch (weapons.Count)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return;
|
||||||
|
case > 1:
|
||||||
|
{
|
||||||
|
var weaponList = string.Join(", ", weapons.Select(w => w.EnumMemberValue));
|
||||||
|
command?.ReplyToCommand($"Found weapons with a similar name: {weaponList}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Give weapon to the player
|
// Give weapon to the player
|
||||||
player.GiveNamedItem(weaponName);
|
player.GiveNamedItem(weapons.First().EnumValue);
|
||||||
|
|
||||||
// Log the command
|
// Log the command
|
||||||
if (command == null)
|
if (command == null)
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,8 @@ public class CustomServerCommandData
|
||||||
|
|
||||||
public class MenuConfig
|
public class MenuConfig
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("MenuType")] public string MenuType { get; set; } = "selectable";
|
||||||
|
|
||||||
[JsonPropertyName("Durations")]
|
[JsonPropertyName("Durations")]
|
||||||
public DurationItem[] Durations { get; set; } =
|
public DurationItem[] Durations { get; set; } =
|
||||||
[
|
[
|
||||||
|
|
@ -216,6 +218,9 @@ public class OtherSettings
|
||||||
|
|
||||||
[JsonPropertyName("MaxBanDuration")]
|
[JsonPropertyName("MaxBanDuration")]
|
||||||
public int MaxBanDuration { get; set; } = 60 * 24 * 7;
|
public int MaxBanDuration { get; set; } = 60 * 24 * 7;
|
||||||
|
|
||||||
|
[JsonPropertyName("MaxMuteDuration")]
|
||||||
|
public int MaxMuteDuration { get; set; } = 60 * 24 * 7;
|
||||||
|
|
||||||
[JsonPropertyName("ExpireOldIpBans")]
|
[JsonPropertyName("ExpireOldIpBans")]
|
||||||
public int ExpireOldIpBans { get; set; } = 0;
|
public int ExpireOldIpBans { get; set; } = 0;
|
||||||
|
|
@ -235,7 +240,7 @@ public class OtherSettings
|
||||||
|
|
||||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 21;
|
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 23;
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseHost")]
|
[JsonPropertyName("DatabaseHost")]
|
||||||
public string DatabaseHost { get; set; } = "";
|
public string DatabaseHost { get; set; } = "";
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,12 @@ public partial class CS2_SimpleAdmin
|
||||||
|
|
||||||
var command = info.GetArg(0).ToLower();
|
var command = info.GetArg(0).ToLower();
|
||||||
|
|
||||||
|
if (command == "css_admins_reload")
|
||||||
|
{
|
||||||
|
AddTimer(1.0f, () => ReloadAdmins(null));
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!command.Contains("say"))
|
if (!command.Contains("say"))
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Globalization;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API;
|
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
|
|
@ -15,10 +14,13 @@ using Microsoft.Extensions.Logging;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
||||||
using CS2_SimpleAdmin.Managers;
|
using CS2_SimpleAdmin.Managers;
|
||||||
|
using MenuManager;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
|
|
@ -542,6 +544,33 @@ internal static class Helper
|
||||||
CS2_SimpleAdmin._localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})",
|
CS2_SimpleAdmin._localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})",
|
||||||
commandString]));
|
commandString]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMenu? CreateMenu(string title)
|
||||||
|
{
|
||||||
|
var menuType = CS2_SimpleAdmin.Instance.Config.MenuConfigs.MenuType.ToLower();
|
||||||
|
|
||||||
|
var menu = menuType switch
|
||||||
|
{
|
||||||
|
_ when menuType.Equals("selectable", StringComparison.CurrentCultureIgnoreCase) =>
|
||||||
|
CS2_SimpleAdmin.MenuApi?.NewMenu(title),
|
||||||
|
|
||||||
|
_ when menuType.Equals("dynamic", StringComparison.CurrentCultureIgnoreCase) =>
|
||||||
|
CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ButtonMenu),
|
||||||
|
|
||||||
|
_ when menuType.Equals("center", StringComparison.CurrentCultureIgnoreCase) =>
|
||||||
|
CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.CenterMenu),
|
||||||
|
|
||||||
|
_ when menuType.Equals("chat", StringComparison.CurrentCultureIgnoreCase) =>
|
||||||
|
CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ChatMenu),
|
||||||
|
|
||||||
|
_ when menuType.Equals("console", StringComparison.CurrentCultureIgnoreCase) =>
|
||||||
|
CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ConsoleMenu),
|
||||||
|
|
||||||
|
_ => CS2_SimpleAdmin.MenuApi?.NewMenu(title)
|
||||||
|
};
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PluginInfo
|
public static class PluginInfo
|
||||||
|
|
@ -652,4 +681,47 @@ public static class Time
|
||||||
return utcNow;
|
return utcNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class WeaponHelper
|
||||||
|
{
|
||||||
|
private static readonly Lazy<Dictionary<string, CsItem>> WeaponsEnumCache = new(BuildEnumMemberMap);
|
||||||
|
|
||||||
|
private static Dictionary<string, CsItem> BuildEnumMemberMap()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, CsItem>();
|
||||||
|
|
||||||
|
foreach (var field in typeof(CsItem).GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||||
|
{
|
||||||
|
var attribute = field.GetCustomAttribute<EnumMemberAttribute>();
|
||||||
|
if (attribute?.Value == null) continue;
|
||||||
|
if (field.GetValue(null) is not CsItem csItem)
|
||||||
|
continue;
|
||||||
|
var enumValue = field.GetValue(null);
|
||||||
|
|
||||||
|
dictionary.TryAdd(attribute.Value, csItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CsItem? GetEnumFromWeaponName(string weaponName)
|
||||||
|
{
|
||||||
|
if (WeaponsEnumCache.Value.TryGetValue(weaponName, out var csItem))
|
||||||
|
{
|
||||||
|
return csItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<(string EnumMemberValue, CsItem EnumValue)> GetWeaponsByPartialName(string input)
|
||||||
|
{
|
||||||
|
var matchingWeapons = WeaponsEnumCache.Value
|
||||||
|
.Where(kvp => kvp.Key.Contains(input))
|
||||||
|
.Select(kvp => (kvp.Key, kvp.Value))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return matchingWeapons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ public static class AdminMenu
|
||||||
{
|
{
|
||||||
public static IMenu? CreateMenu(string title)
|
public static IMenu? CreateMenu(string title)
|
||||||
{
|
{
|
||||||
return CS2_SimpleAdmin.MenuApi?.NewMenu(title);
|
return Helper.CreateMenu(title);
|
||||||
// return CS2_SimpleAdmin.Instance.Config.UseChatMenu ? new ChatMenu(title) : new CenterHtmlMenu(title, CS2_SimpleAdmin.Instance);
|
// return CS2_SimpleAdmin.Instance.Config.UseChatMenu ? new ChatMenu(title) : new CenterHtmlMenu(title, CS2_SimpleAdmin.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.6.3b
|
1.6.5a
|
||||||
BIN
Modules/CS2-SimpleAdmin_CleanModule/CS2-SimpleAdminApi.dll
Normal file
BIN
Modules/CS2-SimpleAdmin_CleanModule/CS2-SimpleAdminApi.dll
Normal file
Binary file not shown.
|
|
@ -0,0 +1,59 @@
|
||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
|
using CounterStrikeSharp.API.Core.Capabilities;
|
||||||
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
using CS2_SimpleAdminApi;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin_CleanModule;
|
||||||
|
|
||||||
|
public class CS2_SimpleAdmin_CleanModule: BasePlugin
|
||||||
|
{
|
||||||
|
public override string ModuleName => "[CS2-SimpleAdmin] Clean module";
|
||||||
|
public override string ModuleDescription => "Module allows you to remove all weapons lying on the ground";
|
||||||
|
public override string ModuleVersion => "v1.0.0";
|
||||||
|
public override string ModuleAuthor => "daffyy";
|
||||||
|
|
||||||
|
private static ICS2_SimpleAdminApi? _sharedApi;
|
||||||
|
private readonly PluginCapability<ICS2_SimpleAdminApi> _pluginCapability = new("simpleadmin:api");
|
||||||
|
|
||||||
|
public override void OnAllPluginsLoaded(bool hotReload)
|
||||||
|
{
|
||||||
|
_sharedApi = _pluginCapability.Get();
|
||||||
|
|
||||||
|
if (_sharedApi == null)
|
||||||
|
{
|
||||||
|
Logger.LogError("CS2-SimpleAdmin SharedApi not found");
|
||||||
|
Unload(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("css_clean")]
|
||||||
|
[ConsoleCommand("css_clear")]
|
||||||
|
[RequiresPermissions("@css/cheat")]
|
||||||
|
public void OnCleanCommand(CCSPlayerController? caller, CommandInfo commandInfo)
|
||||||
|
{
|
||||||
|
var weapons = Utilities.FindAllEntitiesByDesignerName<CCSWeaponBaseGun>("weapon_");
|
||||||
|
var defusers = Utilities.FindAllEntitiesByDesignerName<CSceneEntity>("item_cutters");
|
||||||
|
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (!weapon.IsValid || weapon.State != CSWeaponState_t.WEAPON_NOT_CARRIED)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
weapon.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var defuser in defusers)
|
||||||
|
{
|
||||||
|
if (!defuser.IsValid || defuser.OwnerEntity.Value != null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
defuser.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
_sharedApi?.LogCommand(caller, commandInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RootNamespace>CS2_SimpleAdmin_CleanModule</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.266" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="CS2-SimpleAdminApi">
|
||||||
|
<HintPath>CS2-SimpleAdminApi.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS2-SimpleAdmin_CleanModule", "CS2-SimpleAdmin_CleanModule.csproj", "{D940F3E9-0E3F-467A-B336-149E3A624FB6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D940F3E9-0E3F-467A-B336-149E3A624FB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D940F3E9-0E3F-467A-B336-149E3A624FB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D940F3E9-0E3F-467A-B336-149E3A624FB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D940F3E9-0E3F-467A-B336-149E3A624FB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue