Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
fix: cleanup logger and add config
Browse files Browse the repository at this point in the history
  • Loading branch information
dollannn committed Apr 6, 2024
1 parent e835a26 commit 8031d9c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
50 changes: 33 additions & 17 deletions CS2Multi1v1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,53 @@

namespace CS2Multi1v1;

public class CS2Multi1v1 : BasePlugin
public class CS2Multi1v1 : BasePlugin, IPluginConfig<CS2Multi1v1Config>
{

public static CS2Multi1v1 Instance { get; private set; } = new();
public override string ModuleName => "CS2Multi1v1";
public override string ModuleVersion => "beta_1.0.0";
public override string ModuleAuthor => "rockCityMath, dollan";
public override string ModuleDescription => "Supports multiple automatic 1v1 arenas with rank climbing.";

private bool _aimMapLoaded;
private bool _aimMapLoaded = false;

internal static ILogger? _logger;
private Queue<ArenaPlayer> _waitingArenaPlayers = new Queue<ArenaPlayer>();
private List<Arena> _rankedArenas = new List<Arena>();

private ILogger<CS2Multi1v1> _logger;
private Queue<ArenaPlayer> _waitingArenaPlayers;
private List<Arena> _rankedArenas;
public CS2Multi1v1Config Config { get; set; } = new();

public CS2Multi1v1(ILogger<CS2Multi1v1> logger)
public void OnConfigParsed(CS2Multi1v1Config config)
{
_aimMapLoaded = false;
_logger = logger;
_waitingArenaPlayers = new Queue<ArenaPlayer>();
_rankedArenas = new List<Arena>();
Config = config;
}

// public CS2Multi1v1()
// {
// _aimMapLoaded = false;
// _waitingArenaPlayers = new Queue<ArenaPlayer>();
// _rankedArenas = new List<Arena>();
// }

public override void Load(bool hotReload)
{
Instance = this;
_logger = Logger;

_logger.LogInformation("Loaded CS2Multi1v1!");



if (hotReload)
{
_logger.LogInformation("Detected hot reload...");
// requeue/calc spawns??
}
}

private void RegisterEvents()
{
RegisterEventHandler<EventGameNewmap>(OnGameNewmap);
RegisterEventHandler<EventGameStart>(OnGameStart);
RegisterEventHandler<EventMapTransition>(OnMapTransition);
Expand All @@ -47,12 +69,6 @@ public override void Load(bool hotReload)
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);

if (hotReload)
{
_logger.LogInformation("Detected hot reload...");
// requeue/calc spawns??
}
}

// ----------------------------- SERVER RELATED GAME EVENT HOOKS -------------------------------------//
Expand Down Expand Up @@ -321,7 +337,7 @@ public void OnAsize(CCSPlayerController? player, CommandInfo commandInfo)
int count = 0;
foreach (Tuple<SpawnPoint, SpawnPoint> arenaSpawns in arenasSpawns)
{
Arena arena = new Arena(_logger, arenaSpawns);
Arena arena = new Arena(_logger!, arenaSpawns);
_rankedArenas.Add(arena);
count++;
}
Expand Down
9 changes: 9 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;

namespace CS2Multi1v1;

public class CS2Multi1v1Config : BasePluginConfig
{
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 0;
}
4 changes: 2 additions & 2 deletions Models/Arena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class Arena
private Tuple<SpawnPoint, SpawnPoint> _spawns;
private int _rank;
private RoundType _roundType;
private ILogger<CS2Multi1v1> _logger;
private ILogger _logger;

public ArenaPlayer? _player1;
private int _player1Kills;
Expand All @@ -20,7 +20,7 @@ internal class Arena
public ArenaPlayer? _player2; // these should be private, use util methods for interation
private int _player2Kills;

public Arena(ILogger<CS2Multi1v1> logger, Tuple<SpawnPoint, SpawnPoint> spawns)
public Arena(ILogger logger, Tuple<SpawnPoint, SpawnPoint> spawns)
{
_spawns = spawns;
_rank = 0;
Expand Down

0 comments on commit 8031d9c

Please sign in to comment.