Skip to content

Commit 5f714fb

Browse files
Avoid redundantly caliing CommandManager.GetDescriptor
1 parent d370674 commit 5f714fb

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

fCraft/Commands/CommandManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static bool ParseCommand([NotNull] Player player, [NotNull] CommandReader
225225
{
226226
if (player == null) throw new ArgumentNullException("player");
227227
if (cmd == null) throw new ArgumentNullException("cmd");
228-
CommandDescriptor descriptor = GetDescriptor(cmd.Name, true);
228+
CommandDescriptor descriptor = cmd.Descriptor;
229229

230230
if (descriptor == null)
231231
{

fCraft/Player/Player.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -459,35 +459,34 @@ void ParseCommand( string rawMessage, bool fromConsole ) {
459459
rawMessage = rawMessage.Substring(0, rawMessage.Length - 1);
460460
}
461461
CommandReader cmd = new CommandReader(rawMessage);
462-
CommandDescriptor commandDescriptor = CommandManager.GetDescriptor(cmd.Name, true);
463462

464-
if (commandDescriptor == null) {
463+
if (cmd.Descriptor == null) {
465464
Message("Unknown command \"{0}\". See &H/Commands", cmd.Name);
466465
Logger.Log(LogType.UserCommand, "{0}[Not A CMD]: {1}", Name, rawMessage);
467-
} else if (IsPlayingCTF && commandDescriptor.Permissions != null &&
468-
(commandDescriptor.Permissions.Contains(Permission.Build) ||
469-
commandDescriptor.Permissions.Contains(Permission.Draw) ||
470-
commandDescriptor.Permissions.Contains(Permission.DrawAdvanced) ||
471-
commandDescriptor.Permissions.Contains(Permission.CopyAndPaste) ||
472-
commandDescriptor.Permissions.Contains(Permission.UndoOthersActions) ||
473-
commandDescriptor.Permissions.Contains(Permission.UndoAll) ||
474-
commandDescriptor.Permissions.Contains(Permission.Teleport) ||
475-
commandDescriptor.Permissions.Contains(Permission.Bring) ||
476-
commandDescriptor.Permissions.Contains(Permission.BringAll))) {
466+
} else if (IsPlayingCTF && cmd.Descriptor.Permissions != null &&
467+
(cmd.Descriptor.Permissions.Contains(Permission.Build) ||
468+
cmd.Descriptor.Permissions.Contains(Permission.Draw) ||
469+
cmd.Descriptor.Permissions.Contains(Permission.DrawAdvanced) ||
470+
cmd.Descriptor.Permissions.Contains(Permission.CopyAndPaste) ||
471+
cmd.Descriptor.Permissions.Contains(Permission.UndoOthersActions) ||
472+
cmd.Descriptor.Permissions.Contains(Permission.UndoAll) ||
473+
cmd.Descriptor.Permissions.Contains(Permission.Teleport) ||
474+
cmd.Descriptor.Permissions.Contains(Permission.Bring) ||
475+
cmd.Descriptor.Permissions.Contains(Permission.BringAll))) {
477476
Message("&WYou cannot use this command while playing CTF");
478-
} else if (Info.IsFrozen && !commandDescriptor.UsableByFrozenPlayers) {
477+
} else if (Info.IsFrozen && !cmd.Descriptor.UsableByFrozenPlayers) {
479478
Message("&WYou cannot use this command while frozen.");
480479
Logger.Log(LogType.UserCommand, "{0}[Frozen]: {1}", Name, rawMessage);
481480
} else {
482-
if (!commandDescriptor.DisableLogging && !(fromConsole && rawMessage.CaselessStarts("/place"))) {
481+
if (!cmd.Descriptor.DisableLogging && !(fromConsole && rawMessage.CaselessStarts("/place"))) {
483482
Logger.Log(LogType.UserCommand, "{0}: {1}", Name, rawMessage);
484483
}
485-
if (commandDescriptor.RepeatableSelection) {
484+
if (cmd.Descriptor.RepeatableSelection) {
486485
selectionRepeatCommand = cmd;
487486
}
488487
SendToSpectators(cmd.RawMessage);
489488
CommandManager.ParseCommand(this, cmd, fromConsole);
490-
if (!commandDescriptor.NotRepeatable) {
489+
if (!cmd.Descriptor.NotRepeatable) {
491490
LastCommand = cmd;
492491
}
493492
}

0 commit comments

Comments
 (0)