Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oqyh authored May 30, 2024
1 parent 64a78e4 commit dbe97d6
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 52 deletions.
51 changes: 42 additions & 9 deletions Auto-Rotate-Maps-GoldKingZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ namespace Auto_Rotate_Maps_GoldKingZ;
public class AutoRotateMapsGoldKingZ : BasePlugin
{
public override string ModuleName => "Auto Rotate Maps (Auto Rotate Maps Depend Players In Server)";
public override string ModuleVersion => "1.0.0";
public override string ModuleVersion => "1.0.1";
public override string ModuleAuthor => "Gold KingZ";
public override string ModuleDescription => "https://github.com/oqyh";

public override void Load(bool hotReload)
{
Globals.maplist = Path.Combine(ModuleDirectory, "config/RotationServerMapList.txt");

Configs.Load(ModuleDirectory);
Configs.Shared.CookiesModule = ModuleDirectory;

RegisterListener<Listeners.OnClientConnected>(OnClientConnected);
RegisterListener<Listeners.OnClientDisconnectPost>(OnClientDisconnectPost);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
Expand Down Expand Up @@ -142,10 +141,43 @@ private void RotationTimer_Callback2()
{
if(Configs.GetConfigData().RotateMode == 1)
{
Globals.GmapName = Helper.GetNextMap();
if (Configs.GetConfigData().EnableSchedule)
{
DateTime now = DateTime.Now;
string currentTime = now.ToString("HH:mm");
if (String.Compare(currentTime, Configs.GetConfigData().ScheduleFromTime) >= 0 &&
String.Compare(currentTime, Configs.GetConfigData().ScheduleToTime) < 0)
{
Globals.GmapName = Helper.GetNextMaps();
}else
{
Globals.GmapName = Helper.GetNextMap();
}
}else
{
Globals.GmapName = Helper.GetNextMap();
}

}else if(Configs.GetConfigData().RotateMode == 2)
{
Globals.GmapName = Helper.GetRandomMap();

if (Configs.GetConfigData().EnableSchedule)
{
DateTime now = DateTime.Now;
string currentTime = now.ToString("HH:mm");
if (String.Compare(currentTime, Configs.GetConfigData().ScheduleFromTime) >= 0 &&
String.Compare(currentTime, Configs.GetConfigData().ScheduleToTime) < 0)
{
Globals.GmapName = Helper.GetRandomMaps();
}else
{
Globals.GmapName = Helper.GetRandomMap();
}
}else
{
Globals.GmapName = Helper.GetRandomMap();
}
}

if(Configs.GetConfigData().TextLog_Enable && Configs.GetConfigData().RotateMode != 0)
Expand Down Expand Up @@ -224,28 +256,28 @@ private void RotationTimer_Callback2()

}

if (Globals.GmapName.StartsWith("ds:") )
if (Globals.GmapName.StartsWith(Configs.GetConfigData().Prefix_For_Ds_Workshop_Changelevel))
{
Server.NextFrame(() =>
{
AddTimer(2.00f, () =>
{
string dsworkshop = Globals.GmapName.TrimStart().Substring("ds:".Length).Trim();
string dsworkshop = Globals.GmapName.TrimStart().Substring(Configs.GetConfigData().Prefix_For_Ds_Workshop_Changelevel.Length).Trim();
Server.ExecuteCommand($"ds_workshop_changelevel {dsworkshop}");
}, TimerFlags.STOP_ON_MAPCHANGE);
});

}else if (Globals.GmapName.StartsWith("host:"))
}else if (Globals.GmapName.StartsWith(Configs.GetConfigData().Prefix_For_Host_Workshop_Map))
{
Server.NextFrame(() =>
{
AddTimer(2.00f, () =>
{
string hostworkshop = Globals.GmapName.TrimStart().Substring("host:".Length).Trim();
string hostworkshop = Globals.GmapName.TrimStart().Substring(Configs.GetConfigData().Prefix_For_Host_Workshop_Map.Length).Trim();
Server.ExecuteCommand($"host_workshop_map {hostworkshop}");
}, TimerFlags.STOP_ON_MAPCHANGE);
});
}else if (!(Globals.GmapName.StartsWith("ds:") || Globals.GmapName.StartsWith("host:")))
}else if (!(Globals.GmapName.StartsWith(Configs.GetConfigData().Prefix_For_Ds_Workshop_Changelevel) || Globals.GmapName.StartsWith(Configs.GetConfigData().Prefix_For_Host_Workshop_Map)))
{
Server.NextFrame(() =>
{
Expand All @@ -266,6 +298,7 @@ private void RotationTimer_Callback2()
Globals.RotationTimer2 = null;
}
}

private void OnMapEnd()
{
Helper.ClearVariables();
Expand Down
22 changes: 21 additions & 1 deletion Config/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public static class Shared {

private static readonly string ConfigDirectoryName = "config";
private static readonly string ConfigFileName = "config.json";
private static readonly string FilePath2 = "RotationServerMapList.txt";
private static readonly string FilePath = "RotationServerMapList.txt";
private static readonly string FilePath2 = "RotationServerMapListSchedule.txt";
private static string? _FilePath;
private static string? _FilePath2;
private static string? _configFilePath;
private static ConfigData? _configData;
Expand Down Expand Up @@ -50,6 +52,9 @@ public static ConfigData Load(string modulePath)
Directory.CreateDirectory(configFileDirectory);
}

_FilePath = Path.Combine(configFileDirectory, FilePath);
Helper.CreateDefaultWeaponsJson(_FilePath);

_FilePath2 = Path.Combine(configFileDirectory, FilePath2);
Helper.CreateDefaultWeaponsJson2(_FilePath2);

Expand Down Expand Up @@ -87,6 +92,9 @@ private static void SaveConfigData(ConfigData configData)

public class ConfigData
{
public string Load_MapList_Path { get; set; }
public string Prefix_For_Ds_Workshop_Changelevel { get; set; }
public string Prefix_For_Host_Workshop_Map { get; set; }
private int _RotateMode;
public int RotateMode
{
Expand All @@ -108,6 +116,11 @@ public int RotateMode
}
public float RotateXTimerInMins { get; set; }
public int RotateWhenXPlayersInServerORLess { get; set; }
public bool EnableSchedule { get; set; }
public string ScheduleFromTime { get; set; }
public string ScheduleToTime { get; set; }
public string Schedule_MapList_Path { get; set; }

public string empty { get; set; }
public bool TextLog_Enable { get; set; }
public string TextLog_MessageFormat { get; set; }
Expand Down Expand Up @@ -158,9 +171,16 @@ public string DiscordLog_SideColor

public ConfigData()
{
Load_MapList_Path = "csgo/addons/counterstrikesharp/plugins/Auto-Rotate-Maps-GoldKingZ/config/RotationServerMapList.txt";
Prefix_For_Ds_Workshop_Changelevel = "ds:";
Prefix_For_Host_Workshop_Map = "host:";
RotateMode = 1;
RotateXTimerInMins = 5.0f;
RotateWhenXPlayersInServerORLess = 0;
EnableSchedule = false;
ScheduleFromTime = "01:00";
ScheduleToTime = "06:00";
Schedule_MapList_Path = "csgo/addons/counterstrikesharp/plugins/Auto-Rotate-Maps-GoldKingZ/config/RotationServerMapListSchedule.txt";
empty = "-----------------------------------------------------------------------------------";
TextLog_Enable = false;
TextLog_MessageFormat = "[{DATE} - {TIME}] Server Has Less Players Changing Map To [{MAP}]";
Expand Down
4 changes: 4 additions & 0 deletions Config/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ public class Globals
{
public static List<string> availableMaps = new List<string>();
public static List<string> allMaps = new List<string>();
public static List<string> availableMapss = new List<string>();
public static List<string> allMapss = new List<string>();
public static string maplist = "";
public static string GmapName = "";
public static string[] _lines = null!;
public static string[] _liness = null!;
public static int _currentIndex = -1;
public static int _currentIndexs = -1;
public static bool onetime = false;
public static CounterStrikeSharp.API.Modules.Timers.Timer? Defaultmap;
public static CounterStrikeSharp.API.Modules.Timers.Timer? RotationTimer;
Expand Down
Loading

0 comments on commit dbe97d6

Please sign in to comment.