1.6.4a
- New give command - Added `@css/permmute` flag to allow perm penalties - Fixed mute when player silenced - Added CleanModule - allow to clean weapons on ground
This commit is contained in:
parent
d30ac80a36
commit
5a9367ae89
17 changed files with 193 additions and 27 deletions
|
|
@ -1,4 +1,3 @@
|
|||
using System.Diagnostics;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using CounterStrikeSharp.API.Core.Attributes;
|
|||
using CounterStrikeSharp.API.Core.Capabilities;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||
using CS2_SimpleAdmin.Managers;
|
||||
using CS2_SimpleAdminApi;
|
||||
|
|
@ -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 ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||
public override string ModuleVersion => "1.6.3b";
|
||||
public override string ModuleVersion => "1.6.4a";
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ public partial class CS2_SimpleAdmin
|
|||
{
|
||||
if (caller == null) return true;
|
||||
|
||||
bool canPermBan = AdminManager.PlayerHasPermissions(caller, "@css/permban");
|
||||
var canPermBan = AdminManager.PlayerHasPermissions(caller, "@css/permban");
|
||||
|
||||
if (duration <= 0 && canPermBan == false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CS2_SimpleAdmin.Managers;
|
||||
|
|
@ -50,6 +49,7 @@ public partial class CS2_SimpleAdmin
|
|||
{
|
||||
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
||||
if (!caller.CanTarget(player)) return;
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Set default caller name if not provided
|
||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||
|
|
@ -126,6 +126,7 @@ public partial class CS2_SimpleAdmin
|
|||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||
|
||||
int.TryParse(command.GetArg(2), out var time);
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Get player and admin info
|
||||
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 (!caller.CanTarget(player)) return;
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Set default caller name if not provided
|
||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||
|
|
@ -343,6 +345,7 @@ public partial class CS2_SimpleAdmin
|
|||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||
|
||||
int.TryParse(command.GetArg(2), out var time);
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Get player and admin info
|
||||
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
||||
|
|
@ -483,6 +486,7 @@ public partial class CS2_SimpleAdmin
|
|||
{
|
||||
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
|
||||
if (!caller.CanTarget(player)) return;
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Set default caller name if not provided
|
||||
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
|
||||
|
|
@ -499,6 +503,7 @@ public partial class CS2_SimpleAdmin
|
|||
|
||||
// Add penalty to the player's penalty manager
|
||||
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)
|
||||
var (messageKey, activityMessageKey, playerArgs, adminActivityArgs) = time == 0
|
||||
|
|
@ -559,6 +564,7 @@ public partial class CS2_SimpleAdmin
|
|||
: (_localizer?["sa_unknown"] ?? "Unknown");
|
||||
|
||||
int.TryParse(command.GetArg(2), out var time);
|
||||
if (!CheckValidMute(caller, time)) return;
|
||||
|
||||
// Get player and admin info
|
||||
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
|
||||
|
|
@ -663,4 +669,22 @@ public partial class CS2_SimpleAdmin
|
|||
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.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,18 +67,11 @@ public partial class CS2_SimpleAdmin
|
|||
var weaponName = command.GetArg(2);
|
||||
|
||||
// check if item is typed
|
||||
if (weaponName.Length < 5)
|
||||
{
|
||||
command.ReplyToCommand($"No weapon typed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// check if item is valid
|
||||
if (!weaponName.Contains("weapon_") && !weaponName.Contains("item_"))
|
||||
{
|
||||
command.ReplyToCommand($"{weaponName} is not a valid item.");
|
||||
return;
|
||||
}
|
||||
// if (weaponName.Length < 2)
|
||||
// {
|
||||
// command.ReplyToCommand($"No weapon typed.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// check if weapon is knife
|
||||
if (weaponName.Contains("_knife") || weaponName.Contains("bayonet"))
|
||||
|
|
@ -105,9 +98,22 @@ public partial class CS2_SimpleAdmin
|
|||
|
||||
// Set default caller name if not provided
|
||||
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
|
||||
player.GiveNamedItem(weaponName);
|
||||
player.GiveNamedItem(weapons.First().EnumValue);
|
||||
|
||||
// Log the command
|
||||
if (command == null)
|
||||
|
|
|
|||
|
|
@ -201,6 +201,9 @@ public class OtherSettings
|
|||
|
||||
[JsonPropertyName("MaxBanDuration")]
|
||||
public int MaxBanDuration { get; set; } = 60 * 24 * 7;
|
||||
|
||||
[JsonPropertyName("MaxMuteDuration")]
|
||||
public int MaxMuteDuration { get; set; } = 60 * 24 * 7;
|
||||
|
||||
[JsonPropertyName("ExpireOldIpBans")]
|
||||
public int ExpireOldIpBans { get; set; } = 0;
|
||||
|
|
@ -220,7 +223,7 @@ public class OtherSettings
|
|||
|
||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||
{
|
||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 21;
|
||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 22;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Globalization;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
|
|
@ -15,9 +14,11 @@ using Microsoft.Extensions.Logging;
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
||||
using CS2_SimpleAdmin.Managers;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
|
@ -625,4 +626,47 @@ public static class Time
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1.6.3b
|
||||
1.6.4a
|
||||
Loading…
Add table
Add a link
Reference in a new issue