Use better code
This commit is contained in:
parent
608e7a99bc
commit
75c8a8ced4
32 changed files with 77 additions and 105 deletions
|
|
@ -767,7 +767,7 @@ namespace TShockAPI
|
|||
return;
|
||||
}
|
||||
}
|
||||
else if (action == EditAction.PlaceTile && (projectileCreatesTile.ContainsKey(lastKilledProj) && editData == projectileCreatesTile[lastKilledProj]))
|
||||
else if (action == EditAction.PlaceTile && projectileCreatesTile.TryGetValue(lastKilledProj, out int value) && editData == value)
|
||||
{
|
||||
args.Player.LastKilledProjectile = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,12 +147,11 @@ namespace TShockAPI.CLI
|
|||
/// <returns></returns>
|
||||
public T Get<T>(FlagSet flags)
|
||||
{
|
||||
if (!_results.ContainsKey(flags))
|
||||
if (!_results.TryGetValue(flags, out object result))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
object result = _results[flags];
|
||||
Type t = typeof(T);
|
||||
|
||||
if (t == typeof(string))
|
||||
|
|
|
|||
|
|
@ -43,10 +43,7 @@ namespace TShockAPI.CLI
|
|||
/// <param name="flags">Flags represented by this FlagSet</param>
|
||||
public FlagSet(params string[] flags)
|
||||
{
|
||||
if (flags == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(flags));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(flags);
|
||||
|
||||
_flags = flags.Select(f => f.ToLowerInvariant());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,8 +113,7 @@ namespace TShockAPI
|
|||
get { return commandDelegate; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException();
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
commandDelegate = value;
|
||||
}
|
||||
|
|
@ -134,10 +133,9 @@ namespace TShockAPI
|
|||
|
||||
public Command(CommandDelegate cmd, params string[] names)
|
||||
{
|
||||
if (cmd == null)
|
||||
throw new ArgumentNullException("cmd");
|
||||
ArgumentNullException.ThrowIfNull(cmd);
|
||||
if (names == null || names.Length < 1)
|
||||
throw new ArgumentException("names");
|
||||
throw new ArgumentException("is null or empty", nameof(names));
|
||||
|
||||
AllowServer = true;
|
||||
CommandDelegate = cmd;
|
||||
|
|
@ -691,11 +689,10 @@ namespace TShockAPI
|
|||
if (Hooks.PlayerHooks.OnPlayerCommand(player, cmdName, cmdText, args, ref cmds, cmdPrefix))
|
||||
return true;
|
||||
|
||||
if (cmds.Count() == 0)
|
||||
if (!cmds.Any())
|
||||
{
|
||||
if (player.AwaitingResponse.ContainsKey(cmdName))
|
||||
if (player.AwaitingResponse.TryGetValue(cmdName, out Action<object> call))
|
||||
{
|
||||
Action<CommandArgs> call = player.AwaitingResponse[cmdName];
|
||||
player.AwaitingResponse.Remove(cmdName);
|
||||
call(new CommandArgs(cmdText, player, args));
|
||||
return true;
|
||||
|
|
@ -2035,7 +2032,7 @@ namespace TShockAPI
|
|||
return;
|
||||
}
|
||||
|
||||
string replacementCommand = String.Join(" ", args.Parameters.Select(p => p.Contains(" ") ? $"\"{p}\"" : p));
|
||||
string replacementCommand = string.Join(" ", args.Parameters.Select(p => p.Contains(' ') ? $"\"{p}\"" : p));
|
||||
args.Player.tempGroup = new SuperAdminGroup();
|
||||
HandleCommand(args.Player, replacementCommand);
|
||||
args.Player.tempGroup = null;
|
||||
|
|
@ -2111,8 +2108,8 @@ namespace TShockAPI
|
|||
Dictionary<string, int> restUsersTokens = new Dictionary<string, int>();
|
||||
foreach (Rests.SecureRest.TokenData tokenData in TShock.RestApi.Tokens.Values)
|
||||
{
|
||||
if (restUsersTokens.ContainsKey(tokenData.Username))
|
||||
restUsersTokens[tokenData.Username]++;
|
||||
if (restUsersTokens.TryGetValue(tokenData.Username, out int value))
|
||||
restUsersTokens[tokenData.Username] = ++value;
|
||||
else
|
||||
restUsersTokens.Add(tokenData.Username, 1);
|
||||
}
|
||||
|
|
@ -2464,7 +2461,7 @@ namespace TShockAPI
|
|||
private static void Rain(CommandArgs args)
|
||||
{
|
||||
bool slime = false;
|
||||
if (args.Parameters.Count > 1 && args.Parameters[1].ToLowerInvariant() == "slime")
|
||||
if (args.Parameters.Count > 1 && args.Parameters[1].Equals("slime", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
slime = true;
|
||||
}
|
||||
|
|
@ -3149,7 +3146,7 @@ namespace TShockAPI
|
|||
matches = new List<NPC> { npc };
|
||||
break;
|
||||
}
|
||||
if (npc.FullName.ToLowerInvariant().StartsWith(npcStr.ToLowerInvariant()) ||
|
||||
if (npc.FullName.StartsWith(npcStr, StringComparison.InvariantCultureIgnoreCase) ||
|
||||
englishName?.StartsWith(npcStr, StringComparison.InvariantCultureIgnoreCase) == true)
|
||||
matches.Add(npc);
|
||||
}
|
||||
|
|
@ -3264,7 +3261,7 @@ namespace TShockAPI
|
|||
});
|
||||
#endregion
|
||||
}
|
||||
else if (args.Parameters[0].ToLower() == "add" && hasManageWarpPermission)
|
||||
else if (args.Parameters[0].Equals("add", StringComparison.OrdinalIgnoreCase) && hasManageWarpPermission)
|
||||
{
|
||||
#region Add warp
|
||||
if (args.Parameters.Count == 2)
|
||||
|
|
@ -3287,7 +3284,7 @@ namespace TShockAPI
|
|||
args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}warp add [name].", Specifier));
|
||||
#endregion
|
||||
}
|
||||
else if (args.Parameters[0].ToLower() == "del" && hasManageWarpPermission)
|
||||
else if (args.Parameters[0].Equals("del", StringComparison.OrdinalIgnoreCase) && hasManageWarpPermission)
|
||||
{
|
||||
#region Del warp
|
||||
if (args.Parameters.Count == 2)
|
||||
|
|
@ -3304,7 +3301,7 @@ namespace TShockAPI
|
|||
args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}warp del [name].", Specifier));
|
||||
#endregion
|
||||
}
|
||||
else if (args.Parameters[0].ToLower() == "hide" && hasManageWarpPermission)
|
||||
else if (args.Parameters[0].Equals("hide", StringComparison.OrdinalIgnoreCase) && hasManageWarpPermission)
|
||||
{
|
||||
#region Hide warp
|
||||
if (args.Parameters.Count == 3)
|
||||
|
|
@ -3330,7 +3327,7 @@ namespace TShockAPI
|
|||
args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}warp hide [name] <true/false>.", Specifier));
|
||||
#endregion
|
||||
}
|
||||
else if (args.Parameters[0].ToLower() == "send" && args.Player.HasPermission(Permissions.tpothers))
|
||||
else if (args.Parameters[0].Equals("send", StringComparison.OrdinalIgnoreCase) && args.Player.HasPermission(Permissions.tpothers))
|
||||
{
|
||||
#region Warp send
|
||||
if (args.Parameters.Count < 3)
|
||||
|
|
@ -4749,14 +4746,14 @@ namespace TShockAPI
|
|||
if (args.Parameters.Count == 3)
|
||||
{
|
||||
string regionName = args.Parameters[1];
|
||||
if (args.Parameters[2].ToLower() == "true")
|
||||
if (args.Parameters[2].Equals("true", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (TShock.Regions.SetRegionState(regionName, true))
|
||||
args.Player.SendInfoMessage(GetString("Marked region {0} as protected.", regionName));
|
||||
else
|
||||
args.Player.SendErrorMessage(GetString($"Could not find the region {regionName}."));
|
||||
}
|
||||
else if (args.Parameters[2].ToLower() == "false")
|
||||
else if (args.Parameters[2].Equals("false", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (TShock.Regions.SetRegionState(regionName, false))
|
||||
args.Player.SendInfoMessage(GetString("Marked region {0} as unprotected.", regionName));
|
||||
|
|
|
|||
|
|
@ -347,9 +347,9 @@ namespace TShockAPI.DB
|
|||
/// <returns></returns>
|
||||
public Ban GetBanById(int id)
|
||||
{
|
||||
if (Bans.ContainsKey(id))
|
||||
if (Bans.TryGetValue(id, out Ban value))
|
||||
{
|
||||
return Bans[id];
|
||||
return value;
|
||||
}
|
||||
|
||||
using var reader = database.QueryReader("SELECT * FROM PlayerBans WHERE TicketNumber=@0", id);
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class MysqlQueryBuilder : GenericQueryBuilder, IQueryBuilder
|
|||
return ret + (length is not null ? "({0})".SFormat((int)length) : "");
|
||||
}
|
||||
|
||||
throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
|
||||
throw new NotImplementedException(Enum.GetName(type));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class PostgresQueryBuilder : GenericQueryBuilder
|
|||
MySqlDbType.Int64 => "BIGINT",
|
||||
MySqlDbType.DateTime => "TIMESTAMP",
|
||||
|
||||
_ => throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type))
|
||||
_ => throw new NotImplementedException(Enum.GetName(type))
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -79,7 +79,7 @@ public class PostgresQueryBuilder : GenericQueryBuilder
|
|||
.Where(c => c.Unique).Select(c => c.Name)
|
||||
.ToArray(); // No re-enumeration
|
||||
|
||||
return $"CREATE TABLE {EscapeTableName(table.Name)} ({string.Join(", ", columns)} {(uniques.Any() ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "")})";
|
||||
return $"CREATE TABLE {EscapeTableName(table.Name)} ({string.Join(", ", columns)} {(uniques.Length != 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "")})";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class SqliteQueryBuilder : GenericQueryBuilder, IQueryBuilder
|
|||
var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name);
|
||||
return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name),
|
||||
string.Join(", ", columns),
|
||||
uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "");
|
||||
uniques.Any() ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -91,7 +91,7 @@ public class SqliteQueryBuilder : GenericQueryBuilder, IQueryBuilder
|
|||
return ret;
|
||||
}
|
||||
|
||||
throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
|
||||
throw new NotImplementedException(Enum.GetName(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace TShockAPI.DB
|
|||
string groups = reader.Get<string>("Groups");
|
||||
int z = reader.Get<int>("Z");
|
||||
|
||||
string[] splitids = mergedids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] splitids = mergedids.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
Region r = new Region(id, new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString(), z);
|
||||
r.SetAllowedGroups(groups);
|
||||
|
|
@ -779,8 +779,7 @@ namespace TShockAPI.DB
|
|||
|
||||
foreach (string id in idArr)
|
||||
{
|
||||
int i = 0;
|
||||
if (int.TryParse(id, out i) && i != 0)
|
||||
if (int.TryParse(id, out var i) && i != 0)
|
||||
{
|
||||
idList.Add(i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -515,7 +515,7 @@ namespace TShockAPI.DB
|
|||
if (password.Trim().Length < Math.Max(4, TShock.Config.Settings.MinimumPasswordLength))
|
||||
{
|
||||
int minLength = TShock.Config.Settings.MinimumPasswordLength;
|
||||
throw new ArgumentOutOfRangeException("password", GetString($"Password must be at least {minLength} characters."));
|
||||
throw new ArgumentOutOfRangeException(nameof(password), GetString($"Password must be at least {minLength} characters."));
|
||||
}
|
||||
try
|
||||
{
|
||||
|
|
@ -536,7 +536,7 @@ namespace TShockAPI.DB
|
|||
if (password.Trim().Length < Math.Max(4, TShock.Config.Settings.MinimumPasswordLength))
|
||||
{
|
||||
int minLength = TShock.Config.Settings.MinimumPasswordLength;
|
||||
throw new ArgumentOutOfRangeException("password", GetString($"Password must be at least {minLength} characters."));
|
||||
throw new ArgumentOutOfRangeException(nameof(password), GetString($"Password must be at least {minLength} characters."));
|
||||
}
|
||||
Password = BCryptNext::BCrypt.Net.BCrypt.HashPassword(password.Trim(), workFactor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ namespace TShockAPI
|
|||
{
|
||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException("source");
|
||||
if (action == null) throw new ArgumentNullException("action");
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
|
||||
foreach (T item in source)
|
||||
action(item);
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ namespace MaxMind
|
|||
throw new IOException("Cannot seek GeoIP database");
|
||||
|
||||
_geodata.Seek(6*offset, SeekOrigin.Begin);
|
||||
_geodata.Read(buffer, 0, 6);
|
||||
_geodata.ReadExactly(buffer, 0, 6);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ namespace TShockAPI
|
|||
/// <param name="permission">The permission to add.</param>
|
||||
public virtual void AddPermission(string permission)
|
||||
{
|
||||
if (permission.StartsWith("!"))
|
||||
if (permission.StartsWith('!'))
|
||||
{
|
||||
NegatePermission(permission.Substring(1));
|
||||
return;
|
||||
|
|
@ -306,7 +306,7 @@ namespace TShockAPI
|
|||
/// <param name="permission"></param>
|
||||
public virtual void RemovePermission(string permission)
|
||||
{
|
||||
if (permission.StartsWith("!"))
|
||||
if (permission.StartsWith('!'))
|
||||
{
|
||||
negatedpermissions.Remove(permission.Substring(1));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -48,14 +48,12 @@ namespace TShockAPI.Handlers.NetModules
|
|||
/// <returns></returns>
|
||||
public static bool HasPermission(CreativePowerTypes powerType, TSPlayer player)
|
||||
{
|
||||
if (!PowerToPermissionMap.ContainsKey(powerType))
|
||||
if (!PowerToPermissionMap.TryGetValue(powerType, out string permission))
|
||||
{
|
||||
TShock.Log.ConsoleDebug(GetString("CreativePowerHandler received permission check request for unknown creative power"));
|
||||
return false;
|
||||
}
|
||||
|
||||
string permission = PowerToPermissionMap[powerType];
|
||||
|
||||
//prevent being told about the spawnrate permission on join until relogic fixes
|
||||
if (!player.HasReceivedNPCPermissionError && powerType == CreativePowerTypes.SetSpawnRate)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ namespace TShockAPI.Handlers.NetModules
|
|||
{
|
||||
INetModuleHandler handler;
|
||||
|
||||
if (NetModulesToHandlersMap.ContainsKey(args.ModuleType))
|
||||
if (NetModulesToHandlersMap.TryGetValue(args.ModuleType, out Type type))
|
||||
{
|
||||
handler = (INetModuleHandler)Activator.CreateInstance(NetModulesToHandlersMap[args.ModuleType]);
|
||||
handler = (INetModuleHandler)Activator.CreateInstance(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.Initializers;
|
||||
using Terraria.Localization;
|
||||
using Terraria.UI.Chat;
|
||||
|
|
@ -54,22 +55,22 @@ namespace TShockAPI.Localization
|
|||
LanguageManager.Instance.SetLanguage(GameCulture.FromCultureName(GameCulture.CultureName.English));
|
||||
}
|
||||
|
||||
for (var i = -48; i < Terraria.ID.ItemID.Count; i++)
|
||||
for (var i = -48; i < ItemID.Count; i++)
|
||||
{
|
||||
ItemNames.Add(i, Lang.GetItemNameValue(i));
|
||||
}
|
||||
|
||||
for (var i = -17; i < Terraria.ID.NPCID.Count; i++)
|
||||
for (var i = -17; i < NPCID.Count; i++)
|
||||
{
|
||||
NpcNames.Add(i, Lang.GetNPCNameValue(i));
|
||||
}
|
||||
|
||||
for (var i = 0; i < Terraria.ID.BuffID.Count; i++)
|
||||
for (var i = 0; i < BuffID.Count; i++)
|
||||
{
|
||||
Buffs.Add(i, Lang.GetBuffName(i));
|
||||
}
|
||||
|
||||
foreach (var field in typeof(Main).Assembly.GetType("Terraria.ID.PrefixID")
|
||||
foreach (var field in typeof(PrefixID)
|
||||
.GetFields().Where(f => !f.Name.Equals("Count", StringComparison.Ordinal)))
|
||||
{
|
||||
var i = (int)field.GetValue(null);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ namespace TShockAPI.Modules
|
|||
}
|
||||
}
|
||||
|
||||
if (args.Count() == ctorParams.Length)
|
||||
if (args.Count == ctorParams.Length)
|
||||
constructor = ctor;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class ReduceConsoleSpam : Module
|
|||
{
|
||||
var mprogress = e.Value.Substring(0, master + 1/*%*/);
|
||||
var sprogress = e.Value.Substring(sub + FindSub.Length);
|
||||
if (mprogress.EndsWith("%") && sprogress.EndsWith("%"))
|
||||
if (mprogress.EndsWith('%') && sprogress.EndsWith('%'))
|
||||
{
|
||||
var text = e.Value.Substring(master + FindMaster.Length, sub - master - FindMaster.Length).Trim();
|
||||
|
||||
|
|
|
|||
|
|
@ -253,8 +253,7 @@ namespace TShockAPI
|
|||
/// <returns></returns>
|
||||
public static NetItem Parse(string str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
ArgumentNullException.ThrowIfNull(str);
|
||||
|
||||
string[] comp = str.Split(',');
|
||||
if (comp.Length != 4)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ namespace TShockAPI
|
|||
get { return this.headerFormat; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException();
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
this.headerFormat = value;
|
||||
}
|
||||
|
|
@ -58,8 +57,7 @@ namespace TShockAPI
|
|||
get { return this.footerFormat; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException();
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
|
||||
this.footerFormat = value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -542,7 +542,7 @@ namespace TShockAPI
|
|||
|
||||
sb.AppendLine($"## {name}");
|
||||
sb.AppendLine($"{desc}");
|
||||
sb.AppendLine(GetString("* **Commands**: `{0}`", strs.Count() > 0 ? string.Join(", ", strs) : GetString("No associated commands.")));
|
||||
sb.AppendLine(GetString("* **Commands**: `{0}`", strs.Any() ? string.Join(", ", strs) : GetString("No associated commands.")));
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ namespace TShockAPI
|
|||
player.sscDeathsPVP = this.deathsPVP;
|
||||
|
||||
if (extraSlot != null)
|
||||
player.TPlayer.extraAccessory = extraSlot.Value == 1 ? true : false;
|
||||
player.TPlayer.extraAccessory = extraSlot.Value == 1;
|
||||
if (this.skinVariant != null)
|
||||
player.TPlayer.skinVariant = this.skinVariant.Value;
|
||||
if (this.voiceVariant != null)
|
||||
|
|
@ -603,11 +603,7 @@ namespace TShockAPI
|
|||
var sacrificedItems = TShock.ResearchDatastore.GetSacrificedItems();
|
||||
for(int i = 0; i < ItemID.Count; i++)
|
||||
{
|
||||
var amount = 0;
|
||||
if (sacrificedItems.ContainsKey(i))
|
||||
{
|
||||
amount = sacrificedItems[i];
|
||||
}
|
||||
sacrificedItems.TryGetValue(i, out int amount);
|
||||
|
||||
var response = NetCreativeUnlocksPlayerReportModule.SerializeSacrificeRequest(player.Index,i, amount);
|
||||
NetManager.Instance.SendToClient(response, player.Index);
|
||||
|
|
|
|||
|
|
@ -378,10 +378,10 @@ namespace Rests
|
|||
uri = uri.TrimEnd('/');
|
||||
string upgrade = null;
|
||||
|
||||
if (redirects.ContainsKey(uri))
|
||||
if (redirects.TryGetValue(uri, out var value))
|
||||
{
|
||||
upgrade = redirects[uri].Item2;
|
||||
uri = redirects[uri].Item1;
|
||||
upgrade = value.Item2;
|
||||
uri = value.Item1;
|
||||
}
|
||||
|
||||
foreach (var com in commands)
|
||||
|
|
@ -398,7 +398,7 @@ namespace Rests
|
|||
for (int i = 0; i < com.UriVerbs.Length; i++)
|
||||
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
|
||||
}
|
||||
else if (com.UriTemplate.ToLower() != uri.ToLower())
|
||||
else if (string.Equals(com.UriTemplate, uri, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1216,7 +1216,7 @@ namespace TShockAPI
|
|||
sb.AppendLine("{0}".SFormat(descattr.Description));
|
||||
|
||||
var permission = method.GetCustomAttributes(false).Where(o => o is Permission);
|
||||
if (permission.Count() > 0)
|
||||
if (permission.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("* **Permissions**: `{0}`", String.Join(", ", permission.Select(p => ((Permission)p).Name))));
|
||||
}
|
||||
|
|
@ -1225,8 +1225,8 @@ namespace TShockAPI
|
|||
sb.AppendLine(GetString("No special permissions are required for this route."));
|
||||
}
|
||||
sb.AppendLine();
|
||||
var verbs = method.GetCustomAttributes(false).Where(o => o is Verb);
|
||||
if (verbs.Count() > 0)
|
||||
var verbs = method.GetCustomAttributes(false).Where(o => o is Verb).Cast<Verb>();
|
||||
if (verbs.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("**Verbs**:"));
|
||||
foreach (Verb verb in verbs)
|
||||
|
|
@ -1238,8 +1238,8 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
sb.AppendLine();
|
||||
var nouns = method.GetCustomAttributes(false).Where(o => o is Noun);
|
||||
if (nouns.Count() > 0)
|
||||
var nouns = method.GetCustomAttributes(false).Where(o => o is Noun).Cast<Noun>();
|
||||
if (nouns.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("**Nouns**:"));
|
||||
foreach (Noun noun in nouns)
|
||||
|
|
@ -1375,7 +1375,7 @@ namespace TShockAPI
|
|||
}
|
||||
foreach (EscapedParameter filter in parameters)
|
||||
{
|
||||
if (player.ContainsKey(filter.Name) && !player[filter.Name].Equals(filter.Value))
|
||||
if (player.TryGetValue(filter.Name, out object value) && !value.Equals(filter.Value))
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
|
|
|
|||
|
|
@ -63,8 +63,7 @@ namespace Rests
|
|||
{
|
||||
get
|
||||
{
|
||||
object ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
if (TryGetValue(key, out object ret))
|
||||
return ret;
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ namespace Rests
|
|||
{
|
||||
get
|
||||
{
|
||||
string ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
if (TryGetValue(key, out string ret))
|
||||
{
|
||||
return Uri.UnescapeDataString(ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,14 +67,10 @@ namespace Rests
|
|||
|
||||
private void AddTokenToBucket(string ip)
|
||||
{
|
||||
if (tokenBucket.ContainsKey(ip))
|
||||
if (!tokenBucket.TryAdd(ip, 1))
|
||||
{
|
||||
tokenBucket[ip] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenBucket.Add(ip, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private object DestroyToken(RestRequestArgs args)
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ namespace TShockAPI
|
|||
public static SaveManager Instance { get { return instance; } }
|
||||
|
||||
// Producer Consumer
|
||||
private EventWaitHandle _wh = new AutoResetEvent(false);
|
||||
private Object _saveLock = new Object();
|
||||
private AutoResetEvent _wh = new AutoResetEvent(false);
|
||||
private object _saveLock = new object();
|
||||
private Queue<SaveTask> _saveQueue = new Queue<SaveTask>();
|
||||
private Thread _saveThread;
|
||||
private int saveQueueCount { get { lock (_saveLock) return _saveQueue.Count; } }
|
||||
|
|
|
|||
|
|
@ -155,14 +155,13 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
string searchLower = search.ToLower();
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
if ((search == player.Name) && exactNameOnly)
|
||||
return new List<TSPlayer> { player };
|
||||
if (player.Name.ToLower().StartsWith(searchLower))
|
||||
if (player.Name.StartsWith(search, StringComparison.CurrentCultureIgnoreCase))
|
||||
found.Add(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -1895,7 +1894,7 @@ namespace TShockAPI
|
|||
/// <param name="blue">The amount of blue color to factor in. Max: 255</param>
|
||||
public virtual void SendMessage(string msg, byte red, byte green, byte blue)
|
||||
{
|
||||
if (msg.Contains("\n"))
|
||||
if (msg.Contains('\n'))
|
||||
{
|
||||
string[] msgs = msg.Split('\n');
|
||||
foreach (string message in msgs)
|
||||
|
|
@ -1925,7 +1924,7 @@ namespace TShockAPI
|
|||
/// <param name="ply">The player who receives the message.</param>
|
||||
public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply)
|
||||
{
|
||||
if (msg.Contains("\n"))
|
||||
if (msg.Contains('\n'))
|
||||
{
|
||||
string[] msgs = msg.Split('\n');
|
||||
foreach (string message in msgs)
|
||||
|
|
@ -2290,11 +2289,8 @@ namespace TShockAPI
|
|||
/// <param name="name">The string representing the command i.e "yes" == /yes</param>
|
||||
/// <param name="callback">The method that will be executed on confirmation ie user accepts</param>
|
||||
public void AddResponse(string name, Action<object> callback)
|
||||
{
|
||||
if (AwaitingResponse.ContainsKey(name))
|
||||
{
|
||||
AwaitingResponse.Remove(name);
|
||||
}
|
||||
|
||||
AwaitingResponse.Add(name, callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ namespace TShockAPI
|
|||
matches = Directory.GetFiles(x64, "*" + libraryName + "*", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
if (matches.Count() == 0)
|
||||
if (!matches.Any())
|
||||
{
|
||||
matches = Directory.GetFiles(Environment.CurrentDirectory, "*" + libraryName + "*");
|
||||
}
|
||||
|
|
@ -329,7 +329,7 @@ namespace TShockAPI
|
|||
File.Delete(Path.Combine(SavePath, "tshock.pid"));
|
||||
}
|
||||
File.WriteAllText(Path.Combine(SavePath, "tshock.pid"),
|
||||
Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));
|
||||
Environment.ProcessId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
CliParser.Reset();
|
||||
HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());
|
||||
|
|
@ -992,7 +992,7 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
// Disable the auth system if "setup.lock" is present or a user account already exists
|
||||
if (File.Exists(Path.Combine(SavePath, "setup.lock")) || (UserAccounts.GetUserAccounts().Count() > 0))
|
||||
if (File.Exists(Path.Combine(SavePath, "setup.lock")) || (UserAccounts.GetUserAccounts().Count > 0))
|
||||
{
|
||||
SetupToken = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ namespace TShockAPI
|
|||
|
||||
private void NotifyAdministrators(Dictionary<string, string> update)
|
||||
{
|
||||
var changes = update["changes"].Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var changes = update["changes"].Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||
NotifyAdministrator(TSPlayer.Server, changes);
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1065,7 +1065,7 @@ namespace TShockAPI
|
|||
output.Append("[[");
|
||||
output.Append(g.Name);
|
||||
output.Append("]]");
|
||||
output.Append("|");
|
||||
output.Append('|');
|
||||
}
|
||||
|
||||
output.AppendLine();
|
||||
|
|
@ -1091,7 +1091,7 @@ namespace TShockAPI
|
|||
}
|
||||
else
|
||||
{
|
||||
output.Append("|");
|
||||
output.Append('|');
|
||||
}
|
||||
}
|
||||
output.AppendLine();
|
||||
|
|
@ -1192,13 +1192,11 @@ namespace TShockAPI
|
|||
item.netDefaults(i);
|
||||
if (item.placeStyle >= 0)
|
||||
{
|
||||
if (GetDataHandlers.MaxPlaceStyles.ContainsKey(item.createTile))
|
||||
if (!GetDataHandlers.MaxPlaceStyles.TryAdd(item.createTile, item.placeStyle))
|
||||
{
|
||||
if (item.placeStyle > GetDataHandlers.MaxPlaceStyles[item.createTile])
|
||||
GetDataHandlers.MaxPlaceStyles[item.createTile] = item.placeStyle;
|
||||
}
|
||||
else
|
||||
GetDataHandlers.MaxPlaceStyles.Add(item.createTile, item.placeStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue