mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 10:43:23 +00:00
Introduces a new documentation site for CS2-SimpleAdmin using Docusaurus, including developer API references, tutorials, user guides, and module documentation. Removes the CleanModule example and updates FunCommands and ExampleModule. Also updates main plugin and API files to support new documentation and module structure.
8.2 KiB
8.2 KiB
sidebar_position
| sidebar_position |
|---|
| 1 |
Developer Introduction
Welcome to the CS2-SimpleAdmin developer documentation!
Overview
This section contains technical documentation for developers who want to:
- Create modules using the CS2-SimpleAdmin API
- Contribute to the core plugin
- Integrate with CS2-SimpleAdmin from other plugins
- Understand the plugin architecture
API Documentation
The CS2-SimpleAdmin API provides a rich set of features for module developers:
Core Features
- Commands - Register and manage commands
- Menus - Create admin menus with player selection
- Penalties - Issue bans, mutes, gags, warnings
- Events - Subscribe to plugin events
- Utilities - Helper functions and player management
Quick Links
For Module Developers
- Module Development Guide - Start creating modules
- Best Practices - Write better code
- Examples - Code examples and patterns
For Core Contributors
- Architecture - Plugin structure and design
- GitHub Repository - Source code
Getting Started
Prerequisites
- C# knowledge (intermediate level)
- .NET 8.0 SDK
- CounterStrikeSharp understanding
- CS2 dedicated server for testing
Development Environment
Recommended:
- Visual Studio 2022 (Community or higher)
- VS Code with C# extension
- Git for version control
CS2-SimpleAdminApi Interface
The main API interface provides all functionality:
using CounterStrikeSharp.API.Core.Capabilities;
using CS2_SimpleAdminApi;
// Get the API
private ICS2_SimpleAdminApi? _api;
private readonly PluginCapability<ICS2_SimpleAdminApi> _pluginCapability =
new("simpleadmin:api");
public override void OnAllPluginsLoaded(bool hotReload)
{
_api = _pluginCapability.Get();
if (_api == null)
{
Logger.LogError("CS2-SimpleAdmin API not found!");
return;
}
// Use the API
_api.RegisterCommand("css_mycommand", "Description", OnMyCommand);
}
API Categories
Command Management
Register custom commands that integrate with CS2-SimpleAdmin:
_api.RegisterCommand("css_mycommand", "Description", callback);
_api.UnRegisterCommand("css_mycommand");
_api.GetTarget(command); // Parse player targets
Menu System
Create interactive menus with automatic back button handling:
// Register category
_api.RegisterMenuCategory("mycategory", "My Category", "@css/generic");
// Register menu
_api.RegisterMenu("mycategory", "mymenu", "My Menu", CreateMenu, "@css/generic");
// Create menu with players
_api.CreateMenuWithPlayers(context, admin, filter, onSelect);
Penalty System
Issue and manage player penalties:
// Ban player
_api.IssuePenalty(player, admin, PenaltyType.Ban, "Reason", 1440);
// Offline ban
_api.IssuePenalty(steamId, admin, PenaltyType.Ban, "Reason", 0);
// Check penalties
var status = _api.GetPlayerMuteStatus(player);
Event System
React to plugin events:
_api.OnSimpleAdminReady += () => { /* Plugin ready */ };
_api.OnPlayerPenaltied += (player, admin, type, reason, duration, id, serverId) =>
{
// Player received penalty
};
Utility Functions
Helper functions for common tasks:
// Get player info
var playerInfo = _api.GetPlayerInfo(player);
// Get valid players
var players = _api.GetValidPlayers();
// Check admin status
if (_api.IsAdminSilent(admin)) { /* ... */ }
// Show admin activity
_api.ShowAdminActivity("message_key", callerName, false, args);
Code Examples
Simple Command
[CommandHelper(1, "<#userid or name>")]
[RequiresPermissions("@css/generic")]
private void OnMyCommand(CCSPlayerController? caller, CommandInfo command)
{
var targets = _api!.GetTarget(command);
if (targets == null) return;
foreach (var target in targets.Players.Where(p => p.IsValid && caller!.CanTarget(p)))
{
// Do something with target
}
_api.LogCommand(caller, command);
}
Simple Menu
private object CreateMyMenu(CCSPlayerController admin, MenuContext context)
{
return _api!.CreateMenuWithPlayers(
context,
admin,
player => player.IsValid && admin.CanTarget(player),
(admin, target) => DoAction(admin, target)
);
}
Best Practices
Error Handling
if (_api == null)
{
Logger.LogError("API not available!");
return;
}
if (!player.IsValid || !player.PawnIsAlive)
{
return;
}
Resource Cleanup
public override void Unload(bool hotReload)
{
if (_api == null) return;
// Unregister commands
_api.UnRegisterCommand("css_mycommand");
// Unregister menus
_api.UnregisterMenu("mycategory", "mymenu");
// Unsubscribe events
_api.OnSimpleAdminReady -= OnReady;
}
Translations
// Use per-player language support
_api.ShowAdminActivityLocalized(
Localizer,
"translation_key",
caller?.PlayerName,
false,
args
);
Reference Implementation
The Fun Commands Module serves as a complete reference implementation demonstrating all API features:
- Command registration from config
- Menu creation with context
- Per-player translations
- Proper cleanup
- Code organization
Architecture Overview
CS2-SimpleAdmin follows a layered architecture:
Layers:
- CounterStrikeSharp Integration - Game event handling
- Manager Layer - Business logic (Bans, Mutes, Permissions)
- Database Layer - MySQL/SQLite with migrations
- Menu System - MenuManager with factory pattern
- Command System - Dynamic registration
- Public API - ICS2_SimpleAdminApi interface
Contributing
Ways to Contribute
- Report Bugs - GitHub Issues
- Suggest Features - GitHub Discussions
- Submit Pull Requests - Code contributions
- Create Modules - Extend functionality
- Improve Documentation - Help others learn
Development Workflow
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
Resources
Documentation
- API Reference - Complete API documentation
- Module Development - Create modules
- Architecture - Plugin design
External Resources
- CounterStrikeSharp Docs - CSS framework
- CS2 Docs - Game documentation
Community
- GitHub - Source code
- Issues - Bug reports
- Discussions - Questions and ideas
Support
Getting Help
- Check Documentation - Most questions answered here
- Search Issues - Someone may have had same problem
- Ask in Discussions - Community help
- Create Issue - For bugs or feature requests
Reporting Bugs
Include:
- CS2-SimpleAdmin version
- CounterStrikeSharp version
- Error messages
- Steps to reproduce
- Expected vs actual behavior
Next Steps
For New Developers
- Read API Overview - Understand available features
- Study Examples - Learn from code
- Create First Module - Get hands-on
For Advanced Developers
- Read Architecture - Deep dive into structure
- Review Source Code - Understand implementation
- Contribute - Help improve the plugin