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

Commit

Permalink
Updated to SMod 3.7.0-A (Ish)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rnen committed May 15, 2020
1 parent 3257766 commit 9bb5283
Show file tree
Hide file tree
Showing 33 changed files with 322 additions and 265 deletions.
2 changes: 1 addition & 1 deletion AdminToolbox/AdminToolbox/API/ATWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace AdminToolbox.API
/// </summary>
public static class ATWeb
{
private static AdminToolbox Plugin => AdminToolbox.plugin;
private static AdminToolbox Plugin => AdminToolbox.singleton;

private static void Debug(string str) => Plugin.Debug("[ATWeb]: " + str);

Expand Down
20 changes: 10 additions & 10 deletions AdminToolbox/AdminToolbox/API/ExtentionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public static class ExtentionMethods
{
private static Server Server => PluginManager.Manager.Server;

private static AdminToolbox Plugin => AdminToolbox.plugin;
private static AdminToolbox Plugin => AdminToolbox.singleton;

internal static bool GetIsJailed(this Player player)
=> AdminToolbox.ATPlayerDict.ContainsKey(player.SteamId) && AdminToolbox.ATPlayerDict[player.SteamId].isJailed;
=> AdminToolbox.ATPlayerDict.ContainsKey(player.UserId) && AdminToolbox.ATPlayerDict[player.UserId].isJailed;

public static bool IsInsideJail(this Player player)
{
Expand All @@ -30,12 +30,12 @@ public static bool IsInsideJail(this Player player)
return x > 7 || y > 5 || z > 7 ? false : true;
}

internal static string[] SteamIDsToArray(this List<Player> players)
internal static string[] UserIdsToArray(this List<Player> players)
{
string[] newArray = new string[players.Count];
for (int i = 0; i < players.Count; i++)
{
newArray[i] = players[i].SteamId;
newArray[i] = players[i].UserId;
}
return newArray;
}
Expand All @@ -49,8 +49,8 @@ internal static Player[] JailedPlayers(this Player[] players)

return players.Length > 0 && Server.Round.Duration > 0
? players
.Where(p => p.TeamRole.Role != Role.UNASSIGNED
&& p.TeamRole.Role != Role.SPECTATOR
.Where(p => p.TeamRole.Role != Smod2.API.RoleType.UNASSIGNED
&& p.TeamRole.Role != Smod2.API.RoleType.SPECTATOR
&& !p.OverwatchMode
&& p.GetIsJailed()).ToArray()
: (new Player[0]);
Expand All @@ -70,7 +70,7 @@ private static bool ContainsPlayer(this string[] array, Player player)
{
if (string.IsNullOrEmpty(str))
continue;
if (str == player.SteamId)
if (str == player.UserId)
return true;
else if (player.GetUserGroup().Name != null && str == player.GetUserGroup().Name.Trim().ToUpper())
return true;
Expand All @@ -87,7 +87,7 @@ private static bool ContainsPlayer(this string[] array, Player player)
}
}

internal static bool IsPlayer(this ICommandSender sender) => sender is Player p && !string.IsNullOrEmpty(p.SteamId);
internal static bool IsPlayer(this ICommandSender sender) => sender is Player p && !string.IsNullOrEmpty(p.UserId);

internal static bool IsPermitted(this ICommandSender sender, string[] commandKey) => sender.IsPermitted(commandKey, false, out string[] reply);

Expand Down Expand Up @@ -129,7 +129,7 @@ internal static bool IsPermitted(this ICommandSender sender, string[] commandKey
}

internal static bool ContainsPlayer(this Dictionary<string, PlayerSettings> dict, Player player)
=> AdminToolbox.ATPlayerDict?.ContainsKey(player?.SteamId) ?? false;
=> AdminToolbox.ATPlayerDict?.ContainsKey(player?.UserId) ?? false;

internal static void ResetPlayerBools(this Dictionary<string, PlayerSettings>.KeyCollection dict)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ internal static bool TryGetVector(this Dictionary<string, WarpPoint> dict, strin
/// </summary>
internal static void Cleanup(this Dictionary<string, PlayerSettings> dict)
{
string[] currentPlayers = PluginManager.Manager.Server.GetPlayers().SteamIDsToArray();
string[] currentPlayers = PluginManager.Manager.Server.GetPlayers().UserIdsToArray();
Dictionary<string, PlayerSettings> newDict = new Dictionary<string, PlayerSettings>(dict);
if (newDict.Count > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion AdminToolbox/AdminToolbox/API/GetPlayerFromString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Player GetPlayer(string args)
else if (long.TryParse(args, out long sID))
{
foreach (Player pl in Server.GetPlayers())
if (pl.SteamId == sID.ToString())
if (pl.UserId == sID.ToString())
return pl;
}
else
Expand Down
24 changes: 12 additions & 12 deletions AdminToolbox/AdminToolbox/API/JailHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class JailHandler

private static Server Server => PluginManager.Manager.Server;

private static void Debug(string message) => AdminToolbox.plugin.Debug("[JailHandler]: " + message);
private static void Debug(string message) => AdminToolbox.singleton.Debug("[JailHandler]: " + message);

/// <summary>
/// Checks the players marked as "Jailed" to see if they are at where they're supposed to be
Expand All @@ -29,9 +29,9 @@ internal static void CheckJailedPlayers()
Player[] jailedPlayers = Server.GetPlayers().ToArray().JailedPlayers();
if (jailedPlayers.Length > 0)
foreach (Player pl in jailedPlayers)
if (AdminToolbox.ATPlayerDict.ContainsKey(pl.SteamId))
if (AdminToolbox.ATPlayerDict.ContainsKey(pl.UserId))
if (!pl.IsInsideJail()) SendToJail(pl);
else if (AdminToolbox.ATPlayerDict[pl.SteamId].JailedToTime <= DateTime.Now) ReturnFromJail(pl);
else if (AdminToolbox.ATPlayerDict[pl.UserId].JailedToTime <= DateTime.Now) ReturnFromJail(pl);
}

/// <summary>
Expand All @@ -43,11 +43,11 @@ internal static void CheckJailedPlayers()
/// </summary>
/// <param name="player">the <see cref="Player"/> to send into jail</param>
/// <param name="jailedToTime">the time to jail the player. Null sets the time to remaining time, or if thats null, one year</param>
public static bool SendToJail(Player player, DateTime? jailedToTime)
public static bool SendToJail(Smod2.API.Player player, DateTime? jailedToTime)
{
if (player == null || player.TeamRole.Role == Role.SPECTATOR || player.OverwatchMode) return false;
if (player == null || player.TeamRole.Role == Smod2.API.RoleType.SPECTATOR || player.OverwatchMode) return false;
Debug($"Attempting to jail {player.Name}");
if (AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings psetting))
if (AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings psetting))
{
if (!jailedToTime.HasValue || jailedToTime < DateTime.Now)
Debug($"Jail time for \"{player.Name}\" not specified, jailing for a year.");
Expand All @@ -65,7 +65,7 @@ public static bool SendToJail(Player player, DateTime? jailedToTime)
}
//Changes role to Tutorial, teleports to jail, removes inv.
Debug($"Variables stored, sending \"{player.Name}\" to jail");
player.ChangeRole(Role.TUTORIAL, true, false);
player.ChangeRole(Smod2.API.RoleType.TUTORIAL, true, false);
player.Teleport(JailPos, true);
foreach (SMItem item in player.GetInventory())
item.Remove();
Expand All @@ -86,13 +86,13 @@ public static bool SendToJail(Player player, DateTime? jailedToTime)
/// <param name="player">the player to return</param>
public static bool ReturnFromJail(Player player)
{
if (player == null || string.IsNullOrEmpty(player.SteamId.Trim()))
if (player == null || string.IsNullOrEmpty(player.UserId.Trim()))
{
Debug("Return: Player or SteamID null/empty");
Debug("Return: Player or UserId null/empty");
return false;
}
Debug($"Attempting to unjail \"{player.Name}\"");
if (AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings psetting))
if (AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings psetting))
{
psetting.isJailed = false;
psetting.JailedToTime = DateTime.Now;
Expand All @@ -109,12 +109,12 @@ public static bool ReturnFromJail(Player player)
player.SetAmmo(AmmoType.DROPPED_5, psetting.prevAmmo5);
player.SetAmmo(AmmoType.DROPPED_7, psetting.prevAmmo7);
player.SetAmmo(AmmoType.DROPPED_9, psetting.prevAmmo9);
AdminToolbox.ATPlayerDict[player.SteamId].playerPrevInv = null;
AdminToolbox.ATPlayerDict[player.UserId].playerPrevInv = null;
return true;
}
else
{
AdminToolbox.plugin.Info("Could not return player from jail! Player not in PlayerDict!");
AdminToolbox.singleton.Info("Could not return player from jail! Player not in PlayerDict!");
return false;
}
}
Expand Down
15 changes: 8 additions & 7 deletions AdminToolbox/AdminToolbox/API/PlayerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AdminToolbox.API
public class PlayerInfo
{
public string LastNickname { get; internal set; } = "Unknown";
public string SteamID { get; internal set; } = "00000000000000000";
public string UserId { get; internal set; } = "00000000000000000";
public bool DNT { get; internal set; } = false;

public string FirstJoin { get; set; } = "";
Expand All @@ -34,7 +34,7 @@ public class PlayerStats
public PlayerStats() { }
}
/// <summary>
/// <see cref ="PlayerSettings"/> is <see cref ="AdminToolbox"/>'s settings <see cref="Class"/>
/// <see cref ="PlayerSettings"/> is <see cref ="AdminToolbox"/>'s settings
/// <para>Used in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// </summary>
public class PlayerSettings
Expand All @@ -54,22 +54,23 @@ public bool
public PlayerStats PlayerStats = new PlayerStats();
public PlayerInfo PlayerInfo = new PlayerInfo();

internal int
previousHealth = 100,
internal float
previousHealth = 100;
internal int
prevAmmo5 = 0,
prevAmmo7 = 0,
prevAmmo9 = 0;
public Vector DeathPos = Vector.Zero;
internal Vector originalPos = Vector.Zero;
internal Role previousRole = Role.CLASSD;
internal Smod2.API.RoleType previousRole = Smod2.API.RoleType.CLASSD;
internal List<SMItem> playerPrevInv = new List<SMItem>();

internal ItemType InfiniteItem = ItemType.NULL;
internal Smod2.API.ItemType InfiniteItem = Smod2.API.ItemType.NULL;

public DateTime JailedToTime { get; internal set; } = DateTime.Now;
public DateTime JoinTime { get; internal set; } = DateTime.Now;


public PlayerSettings(string steamID) => this.PlayerInfo.SteamID = steamID;
public PlayerSettings(string UserId) => this.PlayerInfo.UserId = UserId;
}
}
22 changes: 11 additions & 11 deletions AdminToolbox/AdminToolbox/API/SetPlayerVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace AdminToolbox.API
public static class SetPlayerVariables
{
/// <summary>
/// For setting <see cref="API.PlayerSettings"/> bools by <paramref name="steamID"/>
/// <para>Returns false if <paramref name="steamID"/> is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// For setting <see cref="API.PlayerSettings"/> bools by <paramref name="UserId"/>
/// <para>Returns false if <paramref name="UserId"/> is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// </summary>
public static bool SetPlayerBools(string steamID, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null)
public static bool SetPlayerBools(string UserId, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null)
{
if (AdminToolbox.ATPlayerDict.TryGetValue(steamID, out PlayerSettings setting))
if (AdminToolbox.ATPlayerDict.TryGetValue(UserId, out PlayerSettings setting))
{
setting.overwatchMode = spectatorOnly ?? setting.overwatchMode;
setting.godMode = godMode ?? setting.godMode;
Expand All @@ -31,29 +31,29 @@ public static bool SetPlayerBools(string steamID, bool? spectatorOnly = null, bo
}
/// <summary>
/// For setting <see cref="API.PlayerSettings"/> bools on a <see cref="Player"/>
/// <para>Returns false if <paramref name="player"/>'s steamID is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// <para>Returns false if <paramref name="player"/>'s UserId is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// </summary>
public static bool SetPlayerBools(Player player, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null)
=> SetPlayerBools(player.SteamId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed);
=> SetPlayerBools(player.UserId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed);
/// <summary>
/// For setting <see cref="API.PlayerSettings"/> bools on a list of <see cref="Player"/>s
/// <para>Returns false if one or more of <paramref name="players"/> steamid's is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// <para>Returns false if one or more of <paramref name="players"/> UserId's is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// </summary>
public static bool SetPlayerBools(List<Player> players, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null)
{
int failiures = 0;
foreach (Player player in players)
if (!SetPlayerBools(player.SteamId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed))
if (!SetPlayerBools(player.UserId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed))
failiures++;
return !(failiures > 0);
}
/// <summary>
/// For setting <see cref="PlayerStats"/>
/// <para>Returns false if <paramref name="steamID"/> is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// <para>Returns false if <paramref name="UserId"/> is not in <see cref="AdminToolbox.ATPlayerDict"/></para>
/// </summary>
public static bool SetPlayerStats(string steamID, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null, int? BanCount = null)
public static bool SetPlayerStats(string UserId, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null, int? BanCount = null)
{
if (AdminToolbox.ATPlayerDict.TryGetValue(steamID, out PlayerSettings settings))
if (AdminToolbox.ATPlayerDict.TryGetValue(UserId, out PlayerSettings settings))
{
PlayerStats stats = settings.PlayerStats;
stats.Kills = Kills ?? stats.Kills;
Expand Down
20 changes: 10 additions & 10 deletions AdminToolbox/AdminToolbox/API/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public static class Utility
/// <returns>Returns <see cref="bool"/> based on success</returns>
/// <para>Invalid <see cref="int"/> parameters returns <see cref="Smod2.API.Role.UNASSIGNED"/></para>
/// </summary>
public static bool TryParseRole(int roleID, out Role role)
public static bool TryParseRole(int roleID, out Smod2.API.RoleType role)
{
role = Role.UNASSIGNED;
role = Smod2.API.RoleType.UNASSIGNED;
int[] validRoles = Enum.GetValues(typeof(Role)).Cast<int>().ToArray();
if (!validRoles.Contains(roleID))
return false;
else
{
role = (Role)roleID;
role = (Smod2.API.RoleType)roleID;
return true;
}
}
Expand All @@ -30,15 +30,15 @@ public static bool TryParseRole(int roleID, out Role role)
/// <returns>Returns <see cref="bool"/> based on success</returns>
/// <para>Invalid <see cref="int"/> parameters returns <see cref="Smod2.API.ItemType.NULL"/></para>
/// </summary>
public static bool TryParseItem(int itemID, out ItemType itemType)
public static bool TryParseItem(int itemID, out Smod2.API.ItemType itemType)
{
itemType = ItemType.NULL;
int[] validItems = Enum.GetValues(typeof(ItemType)).Cast<int>().ToArray();
itemType = Smod2.API.ItemType.NULL;
int[] validItems = Enum.GetValues(typeof(Smod2.API.ItemType)).Cast<int>().ToArray();
if (!validItems.Contains(itemID))
return false;
else
{
itemType = (ItemType)itemID;
itemType = (Smod2.API.ItemType)itemID;
return true;
}
}
Expand All @@ -48,14 +48,14 @@ public static bool TryParseItem(int itemID, out ItemType itemType)
/// <returns>Returns <see cref="bool"/> based on success</returns>
/// <para>Tries to cast to <see cref="int"/> first, then compares names</para>
/// </summary>
public static bool TryParseItem(string item, out ItemType itemType)
public static bool TryParseItem(string item, out Smod2.API.ItemType itemType)
{
if (int.TryParse(item, out int x))
return TryParseItem(x, out itemType);

itemType = ItemType.NULL;
itemType = Smod2.API.ItemType.NULL;

foreach (ItemType i in Enum.GetValues(typeof(ItemType)))
foreach (Smod2.API.ItemType i in Enum.GetValues(typeof(Smod2.API.ItemType)))
{
if (i.ToString().ToUpper().Contains(item.ToUpper()))
{
Expand Down
Loading

0 comments on commit 9bb5283

Please sign in to comment.