mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-25 12:52:18 +00:00
Added restart game and change map menus
This commit is contained in:
@@ -2370,9 +2370,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
[CommandHelper(minArgs: 1, usage: "<mapname>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
[CommandHelper(minArgs: 1, usage: "<mapname>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||||
public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
string _command = string.Empty;
|
|
||||||
string? map = command.GetCommandString.Split(" ")[1];
|
string? map = command.GetCommandString.Split(" ")[1];
|
||||||
|
ChangeMap(caller, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeMap(CCSPlayerController? caller, string map, CommandInfo? command = null)
|
||||||
|
{
|
||||||
|
string _command = string.Empty;
|
||||||
|
|
||||||
if (map.StartsWith("ws:"))
|
if (map.StartsWith("ws:"))
|
||||||
{
|
{
|
||||||
if (long.TryParse(map.Replace("ws:", ""), out long mapId))
|
if (long.TryParse(map.Replace("ws:", ""), out long mapId))
|
||||||
@@ -2393,7 +2398,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
{
|
{
|
||||||
if (!Server.IsMapValid(map))
|
if (!Server.IsMapValid(map))
|
||||||
{
|
{
|
||||||
command.ReplyToCommand($"Map {map} not found.");
|
string msg = $"Map {map} not found.";
|
||||||
|
if (command != null)
|
||||||
|
command.ReplyToCommand(msg);
|
||||||
|
else if (caller != null && caller.IsValid)
|
||||||
|
caller.PrintToChat(msg);
|
||||||
|
else
|
||||||
|
Server.PrintToConsole(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2433,8 +2444,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
[RequiresPermissions("@css/changemap")]
|
[RequiresPermissions("@css/changemap")]
|
||||||
public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
string _command = string.Empty;
|
|
||||||
string? map = command.GetArg(1);
|
string? map = command.GetArg(1);
|
||||||
|
ChangeWSMap(caller, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeWSMap(CCSPlayerController? caller, string map)
|
||||||
|
{
|
||||||
|
string _command = string.Empty;
|
||||||
|
|
||||||
if (long.TryParse(map, out long mapId))
|
if (long.TryParse(map, out long mapId))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
ChatMenuOptionData[] options = new[]
|
ChatMenuOptionData[] options = new[]
|
||||||
{
|
{
|
||||||
new ChatMenuOptionData("Manage Players", () => ManagePlayersMenu.OpenMenu(admin)),
|
new ChatMenuOptionData("Manage Players", () => ManagePlayersMenu.OpenMenu(admin)),
|
||||||
new ChatMenuOptionData("Manage Server", null),
|
new ChatMenuOptionData("Manage Server", () => ManageServerMenu.OpenMenu(admin)),
|
||||||
new ChatMenuOptionData("Fun actions", null),
|
new ChatMenuOptionData("Fun actions", null),
|
||||||
new ChatMenuOptionData("Manage Admins", null)
|
new ChatMenuOptionData("Manage Admins", null)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
|
|
||||||
// TODO: Localize options
|
// TODO: Localize options
|
||||||
// options added in order
|
// options added in order
|
||||||
//options.Add(new ChatMenuOptionData("Who Is", () => PlayersMenu.OpenMenu(admin, "Who is", WhoIs)));
|
|
||||||
|
|
||||||
if (hasSlay)
|
if (hasSlay)
|
||||||
{
|
{
|
||||||
|
|||||||
79
Menus/ManageServerMenu.cs
Normal file
79
Menus/ManageServerMenu.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin.Menus
|
||||||
|
{
|
||||||
|
public static class ManageServerMenu
|
||||||
|
{
|
||||||
|
public static void OpenMenu(CCSPlayerController admin)
|
||||||
|
{
|
||||||
|
if (admin == null || admin.IsValid == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (AdminManager.PlayerHasPermissions(admin, "@css/generic") == false)
|
||||||
|
{
|
||||||
|
// TODO: Localize
|
||||||
|
admin.PrintToChat("[Simple Admin] You do not have permissions to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CenterHtmlMenu menu = new CenterHtmlMenu("Manage Server");
|
||||||
|
List<ChatMenuOptionData> options = new();
|
||||||
|
|
||||||
|
// permissions
|
||||||
|
bool hasMap = AdminManager.PlayerHasPermissions(admin, "@css/changemap");
|
||||||
|
|
||||||
|
// TODO: Localize options
|
||||||
|
// options added in order
|
||||||
|
|
||||||
|
if (hasMap)
|
||||||
|
{
|
||||||
|
options.Add(new ChatMenuOptionData("Change Map", () => ChangeMapMenu(admin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
options.Add(new ChatMenuOptionData("Restart Game", () => CS2_SimpleAdmin.Instance.RestartGame(admin)));
|
||||||
|
|
||||||
|
foreach (ChatMenuOptionData menuOptionData in options)
|
||||||
|
{
|
||||||
|
string menuName = menuOptionData.name;
|
||||||
|
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuManager.OpenCenterHtmlMenu(CS2_SimpleAdmin.Instance, admin, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ChangeMapMenu(CCSPlayerController admin)
|
||||||
|
{
|
||||||
|
CenterHtmlMenu menu = new CenterHtmlMenu($"Change Map");
|
||||||
|
List<ChatMenuOptionData> options = new();
|
||||||
|
|
||||||
|
string[] maps = Server.GetMapList();
|
||||||
|
foreach (string map in maps)
|
||||||
|
{
|
||||||
|
options.Add(new ChatMenuOptionData(map, () => ExecuteChangeMap(admin, map, false)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> wsMaps = new(); // TODO: Get from config to add workshopmaps
|
||||||
|
foreach (string map in wsMaps)
|
||||||
|
{
|
||||||
|
options.Add(new ChatMenuOptionData($"{map} (WS)", () => ExecuteChangeMap(admin, map, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ChatMenuOptionData menuOptionData in options)
|
||||||
|
{
|
||||||
|
string menuName = menuOptionData.name;
|
||||||
|
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuManager.OpenCenterHtmlMenu(CS2_SimpleAdmin.Instance, admin, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ExecuteChangeMap(CCSPlayerController admin, string mapName, bool workshop)
|
||||||
|
{
|
||||||
|
if (workshop)
|
||||||
|
CS2_SimpleAdmin.Instance.ChangeWSMap(admin, mapName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user