Changes properties to use automatic property initializers
This commit is contained in:
parent
f0a48ad431
commit
06fa31a7bf
623 changed files with 13072 additions and 19304 deletions
|
|
@ -28,86 +28,78 @@ namespace Server.Commands
|
|||
|
||||
public class CommandEventArgs : EventArgs
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private string m_Command, m_ArgString;
|
||||
private string[] m_Arguments;
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public Mobile Mobile => m_Mobile;
|
||||
public string Command { get; }
|
||||
|
||||
public string Command => m_Command;
|
||||
public string ArgString { get; }
|
||||
|
||||
public string ArgString => m_ArgString;
|
||||
public string[] Arguments { get; }
|
||||
|
||||
public string[] Arguments => m_Arguments;
|
||||
|
||||
public int Length => m_Arguments.Length;
|
||||
public int Length => Arguments.Length;
|
||||
|
||||
public string GetString( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
if ( index < 0 || index >= Arguments.Length )
|
||||
return "";
|
||||
|
||||
return m_Arguments[index];
|
||||
return Arguments[index];
|
||||
}
|
||||
|
||||
public int GetInt32( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
if ( index < 0 || index >= Arguments.Length )
|
||||
return 0;
|
||||
|
||||
return Utility.ToInt32( m_Arguments[index] );
|
||||
return Utility.ToInt32( Arguments[index] );
|
||||
}
|
||||
|
||||
public bool GetBoolean( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
if ( index < 0 || index >= Arguments.Length )
|
||||
return false;
|
||||
|
||||
return Utility.ToBoolean( m_Arguments[index] );
|
||||
return Utility.ToBoolean( Arguments[index] );
|
||||
}
|
||||
|
||||
public double GetDouble( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
if ( index < 0 || index >= Arguments.Length )
|
||||
return 0.0;
|
||||
|
||||
return Utility.ToDouble( m_Arguments[index] );
|
||||
return Utility.ToDouble( Arguments[index] );
|
||||
}
|
||||
|
||||
public TimeSpan GetTimeSpan( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
if ( index < 0 || index >= Arguments.Length )
|
||||
return TimeSpan.Zero;
|
||||
|
||||
return Utility.ToTimeSpan( m_Arguments[index] );
|
||||
return Utility.ToTimeSpan( Arguments[index] );
|
||||
}
|
||||
|
||||
public CommandEventArgs( Mobile mobile, string command, string argString, string[] arguments )
|
||||
{
|
||||
m_Mobile = mobile;
|
||||
m_Command = command;
|
||||
m_ArgString = argString;
|
||||
m_Arguments = arguments;
|
||||
Mobile = mobile;
|
||||
Command = command;
|
||||
ArgString = argString;
|
||||
Arguments = arguments;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandEntry : IComparable
|
||||
{
|
||||
private string m_Command;
|
||||
private CommandEventHandler m_Handler;
|
||||
private AccessLevel m_AccessLevel;
|
||||
public string Command { get; }
|
||||
|
||||
public string Command => m_Command;
|
||||
public CommandEventHandler Handler { get; }
|
||||
|
||||
public CommandEventHandler Handler => m_Handler;
|
||||
|
||||
public AccessLevel AccessLevel => m_AccessLevel;
|
||||
public AccessLevel AccessLevel { get; }
|
||||
|
||||
public CommandEntry( string command, CommandEventHandler handler, AccessLevel accessLevel )
|
||||
{
|
||||
m_Command = command;
|
||||
m_Handler = handler;
|
||||
m_AccessLevel = accessLevel;
|
||||
Command = command;
|
||||
Handler = handler;
|
||||
AccessLevel = accessLevel;
|
||||
}
|
||||
|
||||
public int CompareTo( object obj )
|
||||
|
|
@ -120,19 +112,13 @@ namespace Server.Commands
|
|||
if ( !(obj is CommandEntry e) )
|
||||
throw new ArgumentException();
|
||||
|
||||
return m_Command.CompareTo( e.m_Command );
|
||||
return Command.CompareTo( e.Command );
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandSystem
|
||||
{
|
||||
private static string m_Prefix = "[";
|
||||
|
||||
public static string Prefix
|
||||
{
|
||||
get => m_Prefix;
|
||||
set => m_Prefix = value;
|
||||
}
|
||||
public static string Prefix { get; set; } = "[";
|
||||
|
||||
public static string[] Split( string value )
|
||||
{
|
||||
|
|
@ -187,25 +173,19 @@ namespace Server.Commands
|
|||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<string, CommandEntry> m_Entries;
|
||||
|
||||
public static Dictionary<string, CommandEntry> Entries => m_Entries;
|
||||
public static Dictionary<string, CommandEntry> Entries { get; }
|
||||
|
||||
static CommandSystem()
|
||||
{
|
||||
m_Entries = new Dictionary<string, CommandEntry>( StringComparer.OrdinalIgnoreCase );
|
||||
Entries = new Dictionary<string, CommandEntry>( StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
|
||||
public static void Register( string command, AccessLevel access, CommandEventHandler handler )
|
||||
{
|
||||
m_Entries[command] = new CommandEntry( command, handler, access );
|
||||
Entries[command] = new CommandEntry( command, handler, access );
|
||||
}
|
||||
|
||||
private static AccessLevel m_BadCommandIngoreLevel = AccessLevel.Player;
|
||||
|
||||
public static AccessLevel BadCommandIgnoreLevel{ get => m_BadCommandIngoreLevel;
|
||||
set => m_BadCommandIngoreLevel = value;
|
||||
}
|
||||
public static AccessLevel BadCommandIgnoreLevel { get; set; } = AccessLevel.Player;
|
||||
|
||||
public static bool Handle( Mobile from, string text )
|
||||
{
|
||||
|
|
@ -214,10 +194,10 @@ namespace Server.Commands
|
|||
|
||||
public static bool Handle( Mobile from, string text, MessageType type )
|
||||
{
|
||||
if ( text.StartsWith( m_Prefix ) || type == MessageType.Command )
|
||||
if ( text.StartsWith( Prefix ) || type == MessageType.Command )
|
||||
{
|
||||
if ( type != MessageType.Command )
|
||||
text = text.Substring( m_Prefix.Length );
|
||||
text = text.Substring( Prefix.Length );
|
||||
|
||||
int indexOf = text.IndexOf( ' ' );
|
||||
|
||||
|
|
@ -239,7 +219,7 @@ namespace Server.Commands
|
|||
args = new string[0];
|
||||
}
|
||||
|
||||
m_Entries.TryGetValue( command, out CommandEntry entry );
|
||||
Entries.TryGetValue( command, out CommandEntry entry );
|
||||
|
||||
if ( entry != null )
|
||||
{
|
||||
|
|
@ -254,7 +234,7 @@ namespace Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( from.AccessLevel <= m_BadCommandIngoreLevel )
|
||||
if ( from.AccessLevel <= BadCommandIgnoreLevel )
|
||||
return false;
|
||||
|
||||
from.SendMessage( "You do not have access to that command." );
|
||||
|
|
@ -262,7 +242,7 @@ namespace Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( from.AccessLevel <= m_BadCommandIngoreLevel )
|
||||
if ( from.AccessLevel <= BadCommandIgnoreLevel )
|
||||
return false;
|
||||
|
||||
from.SendMessage( "That is not a valid command." );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue