Ejemplo n.º 1
0
        public bool IsAuthenticated()
        {
            if (Server.ServerSettings.OnlineMode)
            {
                try
                {
                    var uri = new Uri(
                        string.Format(
                            "http://session.minecraft.net/game/checkserver.jsp?user={0}&serverId={1}",
                            Username,
                            PacketCryptography.JavaHexDigest(Encoding.UTF8.GetBytes("")
                                                             .Concat(Wrapper.SharedKey)
                                                             .Concat(PacketCryptography.PublicKeyToAsn1(Globals.ServerKey))
                                                             .ToArray())
                            ));

                    var authenticated = new WebClient().DownloadString(uri);
                    if (authenticated.Contains("NO"))
                    {
                        ConsoleFunctions.WriteInfoLine("Response: " + authenticated);
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    ConsoleFunctions.WriteWarningLine("Caught Exception in PlayerEntity.cs IsAuth function... {0}, {1}", true, e.StackTrace, e.Message);
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static Dictionary <Type, List <MethodListener> > GetListeners(object obj, RegisteredListener listener)
        {
            var result = new Dictionary <Type, List <MethodListener> >();

            foreach (var method in obj.GetType().GetMethods(
                         BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic))
            {
                foreach (var attribute1 in method.GetCustomAttributes(typeof(EListener)))
                {
                    var attribute = (EListener)attribute1;
                    if (Events.ContainsKey(attribute.EventType))
                    {
                        if (result.TryGetValue(attribute.EventType, out var val))
                        {
                            val.Add(new MethodListener(attribute.Priority, method, listener));
                        }
                        else
                        {
                            result.Add(attribute.EventType,
                                       new List <MethodListener>()
                            {
                                new MethodListener(attribute.Priority, method, listener)
                            });
                        }
                    }
                    else
                    {
                        ConsoleFunctions.WriteWarningLine($"{attribute.EventType.FullName} is not registered!");
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static void AddPlugin(string filePath)
        {
            // todo: improve this when I learn more abt .NET reflection.
            var assembly   = Assembly.LoadFrom(filePath);
            var attributes = assembly.GetCustomAttributes(typeof(PluginAttributes), false).Cast <PluginAttributes>();

            foreach (var attribute in attributes)
            {
                try
                {
                    var module = assembly.GetModule(attribute.ModuleName);
                    if (module == null)
                    {
                        ConsoleFunctions.WriteWarningLine(
                            $"No module found in \"{filePath}\" at \"{attribute.ModuleName}\".");
                        break;
                    }

                    var pluginType = assembly.GetType(attribute.PluginPath);
                    if (pluginType == null)
                    {
                        ConsoleFunctions.WriteWarningLine(
                            $"No module found in \"{filePath}\" at \"{attribute.ModuleName}\".");
                        break;
                    }

                    dynamic obj = Activator.CreateInstance(pluginType);

                    if (obj == null)
                    {
                        ConsoleFunctions.WriteWarningLine($"{pluginType} is null when creating instance!");
                        break;
                    }

                    var plugin = obj as SharperPlugin;

                    if (plugin == null)
                    {
                        ConsoleFunctions.WriteWarningLine($"{obj} is not SharperPlugin instance!");
                        break;
                    }

                    plugin.Name        = attribute.Name;
                    plugin.Description = attribute.Description;
                    plugin.Author      = attribute.Author;
                    plugin.Version     = attribute.Version;

                    AddPlugin(plugin);
                }
                catch (Exception ex)
                {
                    ConsoleFunctions.WriteWarningLine(
                        $"Failed to load plugin {attribute.Name} {attribute.Version} at " +
                        $"\"{attribute.PluginPath}\" at \"{attribute.ModuleName}\". {ex}");
                }
            }
        }
Ejemplo n.º 4
0
        internal void LoadPlugins()
        {
            if (Config.GetProperty("PluginDisabled", false))
            {
                return;
            }
            var pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            pluginDirectory = Config.GetProperty("PluginDirectory", pluginDirectory);
            if (pluginDirectory != null)
            {
                pluginDirectory = Path.GetFullPath(pluginDirectory);

                foreach (var pluginPath in Directory.GetFiles(pluginDirectory, "*.dll", SearchOption.AllDirectories))
                {
                    var newAssembly = Assembly.LoadFile(pluginPath);
                    var types       = newAssembly.GetExportedTypes();
                    foreach (var type in types)
                    {
                        try
                        {
                            if (!type.IsDefined(typeof(PluginAttribute), true) && !typeof(IPlugin).IsAssignableFrom(type))
                            {
                                continue;
                            }
                            if (type.IsDefined(typeof(PluginAttribute), true))
                            {
                                var pluginAttribute = Attribute.GetCustomAttribute(type, typeof(PluginAttribute), true) as PluginAttribute;
                                if (pluginAttribute != null)
                                {
                                    if (!Config.GetProperty(pluginAttribute.PluginName + ".Enabled", true))
                                    {
                                        continue;
                                    }
                                }
                            }
                            var ctor = type.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                var plugin = ctor.Invoke(null);
                                _plugins.Add(plugin);
                                LoadCommands(type);
                                LoadOnPlayerJoin(type);
                            }
                        }
                        catch (Exception ex)
                        {
                            ConsoleFunctions.WriteWarningLine("Failed loading plugin type " + type + " as a plugin.");
                            ConsoleFunctions.WriteDebugLine("Plugin loader caught exception: " + ex);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void HandlePacket(object Client, byte[] Data)
        {
            ClientWrapper cWrapper = (ClientWrapper)Client;

            int[] _INT       = Globals.v2Int32(Data, 0);
            int   PacketSize = _INT[0];
            int   NextData   = _INT[1];

            ConsoleFunctions.WriteDebugLine("Packetsize: " + PacketSize.ToString() + " Next data: " + NextData.ToString());
            int PacketID = Globals.v2Int32(Data, NextData)[0];

            switch (PacketID)
            {
            case 0x00:
                new Handshake().Handle(cWrapper, Data);
                break;

            case 0x01:
                if (PacketSize == 9)
                {
                    new Ping().Handle(cWrapper, Data);
                }
                else
                {
                    new SharpMC.Networking.PacketHandler.Packets.Ingoing.ChatMessage().Handle(cWrapper, Data);
                }
                break;

            case 0x04:
                new PlayerPosition().Handle(cWrapper, Data);
                break;

            case 0x06:
                new PlayerPositionAndLook().Handle(cWrapper, Data);
                break;

            case 0x03:
                new SharpMC.Networking.PacketHandler.Packets.Ingoing.PlayerOnGround().Handle(cWrapper, Data);
                break;

            case 0x05:
                new SharpMC.Networking.PacketHandler.Packets.Ingoing.PlayerLook().Handle(cWrapper, Data);
                break;

            default:
                ConsoleFunctions.WriteWarningLine("Unknown packet received! ('" + PacketID + "')");
                break;
            }
        }
Ejemplo n.º 6
0
        public virtual IEnumerable <string> ParseTab(ICommandSender sender, string message, string prefix)
        {
            if (string.IsNullOrEmpty(message))
            {
                var strings = new List <string>();
                foreach (var keyValuePair in CommandMap)
                {
                    strings.AddRange(keyValuePair.Key);
                }
                return(strings);
            }
            var origMessage = message;

            try
            {
                message = message.Trim();
                while (message.Contains("  "))
                {
                    message = message.Replace("  ", " ");
                }
                var split   = message.Split(' ');
                var command = GetCommand(split[0]);
                if (command == default(Command))
                {
                    return(new List <string>());
                }

                string[] args;
                if (split.Length > 1)
                {
                    args = new string[split.Length - 1];
                    Array.Copy(split, 1, args, 0, split.Length - 1);
                }
                else
                {
                    args = new string[0];
                }

                return(command.TabComplete(sender, split[0], args, origMessage).ToList());
            }
            catch (Exception ex)
            {
                ConsoleFunctions.WriteWarningLine(ex.ToString());
                sender.SendChat("An error occured when tab-completing the command.", TextColor.Red);
            }
            return(new List <string>());
        }
Ejemplo n.º 7
0
        public void HandleCommand(string message, Player player)
        {
            try
            {
                var commandText = message.Split(' ')[0];
                message     = message.Replace(commandText, "").Trim();
                commandText = commandText.Replace("/", "").Replace(".", "");

                var arguments = message.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var handlerEntry in _pluginCommands)
                {
                    var commandAttribute = handlerEntry.Value;
                    if (!commandText.Equals(commandAttribute.Command, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    var method = handlerEntry.Key;
                    if (method == null)
                    {
                        return;
                    }

                    var authorizationAttributes = method.GetCustomAttributes <PermissionAttribute>(true);
                    foreach (var authorizationAttribute in authorizationAttributes)
                    {
                        if (!PermissionManager.HasPermission(player, authorizationAttribute.Permission))
                        {
                            player.SendChat("\u00A7cYou are not permitted to use this command!");
                            return;
                        }
                    }

                    if (ExecuteCommand(method, player, arguments, commandAttribute))
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleFunctions.WriteWarningLine(ex.ToString());
            }
            player.SendChat("\u00A7cUnknown command.");
        }
Ejemplo n.º 8
0
        internal void HandlePlayerJoin(Player player)
        {
            try
            {
                foreach (var handler in _pluginPlayerJoinEvents)
                {
                    var atrib = handler.Value;

                    var method = handler.Key;
                    if (method == null)
                    {
                        continue;
                    }
                    if (method.IsStatic)
                    {
                        method.Invoke(null, new object[] { player });
                    }
                    else
                    {
                        var pluginInstance = _plugins.FirstOrDefault(plugin => plugin.GetType() == method.DeclaringType);
                        if (pluginInstance == null)
                        {
                            continue;
                        }

                        if (method.ReturnType == typeof(void))
                        {
                            var parameters = method.GetParameters();
                            if (parameters.Length == 1)
                            {
                                method.Invoke(pluginInstance, new object[] { player });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //For now we will just ignore this, not to big of a deal.
                //Will have to think a bit more about this later on.
                ConsoleFunctions.WriteWarningLine("Plugin error: " + ex);
            }
        }
Ejemplo n.º 9
0
        internal void EnablePlugins(LevelManager levelman)
        {
            foreach (var plugin in _plugins)
            {
                var enablingPlugin = plugin as IPlugin;
                if (enablingPlugin == null)
                {
                    continue;
                }

                try
                {
                    enablingPlugin.OnEnable(new PluginContext(this));
                }
                catch (Exception ex)
                {
                    ConsoleFunctions.WriteWarningLine("On enable plugin: " + ex);
                }
            }
        }
Ejemplo n.º 10
0
        internal void DisablePlugins()
        {
            foreach (var plugin in _plugins)
            {
                var enablingPlugin = plugin as IPlugin;
                if (enablingPlugin == null)
                {
                    continue;
                }

                try
                {
                    enablingPlugin.OnDisable();
                }
                catch (Exception ex)
                {
                    ConsoleFunctions.WriteWarningLine("On disable plugin: " + ex);
                }
            }
        }
Ejemplo n.º 11
0
        private bool ReadCompressed(ClientWrapper client, NetworkStream clientStream, int dlength)
        {
            var buffie = new byte[dlength];
            int receivedData;

            receivedData = clientStream.Read(buffie, 0, buffie.Length);
            buffie       = ZlibStream.UncompressBuffer(buffie);

            if (receivedData > 0)
            {
                var buf = new DataBuffer(client);

                if (client.Decrypter != null)
                {
                    var date = new byte[4096];
                    client.Decrypter.TransformBlock(buffie, 0, buffie.Length, date, 0);
                    buf.BufferedData = date;
                }
                else
                {
                    buf.BufferedData = buffie;
                }

                buf.BufferedData = buffie;

                buf.Size = dlength;
                var packid = buf.ReadVarInt();

                if (!new PackageFactory(client, buf).Handle(packid))
                {
                    ConsoleFunctions.WriteWarningLine("Unknown packet received! \"0x" + packid.ToString("X2") + "\"");
                }

                buf.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public void PacketError(ClientWrapper client, Exception exception)
        {
            if (PacketErrors.ContainsKey(client.ClientIdentifier))
            {
                int errors = PacketErrors[client.ClientIdentifier];
                PacketErrors[client.ClientIdentifier] = errors + 1;

                if (ServerSettings.DisplayPacketErrors)
                {
                    ConsoleFunctions.WriteWarningLine("Packet error for player: \"" + client.Player.Username + "\" Packet errors: " +
                                                      PacketErrors[client.ClientIdentifier] + "\nError:\n" + exception.Message);
                }

                if (PacketErrors[client.ClientIdentifier] >= 3)
                {
                    //RemoveClient(client);
                    if (ServerSettings.ReportExceptionsToClient)
                    {
                        new Disconnect(client)
                        {
                            Reason = new McChatMessage("You were kicked from the server!\n" + exception.Message)
                        }.Write();
                    }
                    else
                    {
                        new Disconnect(client)
                        {
                            Reason = new McChatMessage("You were kicked from the server!")
                        }.Write();
                    }
                    client.Kicked = true;
                }
            }
            else
            {
                //Something really wrong
            }
        }
Ejemplo n.º 13
0
        public void PacketError(ClientWrapper client, Exception exception)
        {
            if (!PacketErrors.ContainsKey(client.ClientIdentifier))
            {
                return;
            }
            var errors = PacketErrors[client.ClientIdentifier];

            PacketErrors[client.ClientIdentifier] = errors + 1;

            if (Server.ServerSettings.DisplayPacketErrors)
            {
                ConsoleFunctions.WriteWarningLine("Packet error for player: \"" + client.Player.Username + "\" Packet errors: " +
                                                  PacketErrors[client.ClientIdentifier] + "\nError:\n" + exception.Message);
            }

            if (PacketErrors[client.ClientIdentifier] < 3)
            {
                return;
            }
            if (Server.ServerSettings.ReportExceptionsToClient)
            {
                new Disconnect(client)
                {
                    Reason = new ChatText("You were kicked from the server!\n" + exception.Message)
                }.Write();
            }
            else
            {
                new Disconnect(client)
                {
                    Reason = new ChatText("You were kicked from the server!")
                }.Write();
            }
            Globals.DisconnectClient(client);
        }
Ejemplo n.º 14
0
        public override void Read()
        {
            if (Buffer != null)
            {
                var length       = Buffer.ReadVarInt();
                var sharedsecret = Buffer.Read(length);

                length = Buffer.ReadVarInt();
                var verifytoken = Buffer.Read(length);

                Client.SharedKey = PacketCryptography.Decrypt(sharedsecret);

                var recv = PacketCryptography.GenerateAES((byte[])Client.SharedKey.Clone());
                var send = PacketCryptography.GenerateAES((byte[])Client.SharedKey.Clone());

                var packetToken = PacketCryptography.Decrypt(verifytoken);

                if (!packetToken.SequenceEqual(PacketCryptography.VerifyToken))
                {
                    //Wrong token! :(
                    ConsoleFunctions.WriteWarningLine("Wrong token!");
                    return;
                }

                Client.Decrypter = recv.CreateDecryptor();
                Client.Encrypter = send.CreateEncryptor();

                Client.EncryptionEnabled = true;
                Client.Player            = new Player(Globals.LevelManager.MainLevel)
                {
                    Uuid     = getUUID(Client.Username),
                    Username = Client.Username,
                    Wrapper  = Client,
                    Gamemode = Globals.LevelManager.MainLevel.DefaultGamemode
                };

                if (Client.Player.IsAuthenticated())
                {
                    new LoginSucces(Client)
                    {
                        Username = Client.Username, UUID = Client.Player.Uuid
                    }.Write();
                    Client.PacketMode = PacketMode.Play;

                    new SetCompression(Client).Write();

                    new JoinGame(Client)
                    {
                        Player = Client.Player
                    }.Write();
                    new SpawnPosition(Client).Write();
                    Client.StartKeepAliveTimer();
                    Client.Player.SendChunksFromPosition();
                }
                else
                {
                    new LoginSucces(Client)
                    {
                        Username = Client.Username, UUID = Client.Player.Uuid
                    }.Write();
                    new Disconnect(Client)
                    {
                        Reason = "Authentication failed! Try restarting your client."
                    }.Write();
                }
            }
        }
Ejemplo n.º 15
0
        private void HandleClientCommNew(object client)
        {
            var tcpClient    = (TcpClient)client;
            var clientStream = tcpClient.GetStream();
            var Client       = new ClientWrapper(tcpClient);

            while (true)
            {
                try
                {
                    var buffie = new byte[4096];
                    int receivedData;
                    receivedData = clientStream.Read(buffie, 0, buffie.Length);

                    if (receivedData > 0)
                    {
                        var buf = new MSGBuffer(Client);

                        if (Client.Decrypter != null)
                        {
                            var date = new byte[4096];
                            Client.Decrypter.TransformBlock(buffie, 0, buffie.Length, date, 0);
                            buf.BufferedData = date;
                        }
                        else
                        {
                            buf.BufferedData = buffie;
                        }

                        buf.BufferedData = buffie;

                        var length = buf.ReadVarInt();
                        buf.Size = length;
                        var packid = buf.ReadVarInt();

                        if (!new PackageFactory(Client, buf).Handle(packid))
                        {
                            ConsoleFunctions.WriteWarningLine("Unknown packet received! \"0x" + packid.ToString("X2") + "\"");
                        }
                        buf.Dispose();
                    }
                    else
                    {
                        //Stop the while loop. Client disconnected!
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Client.ThreadPool.KillAllThreads();
                    //Exception, disconnect!
                    ConsoleFunctions.WriteDebugLine("Error: \n" + ex);
                    new Disconnect(Client)
                    {
                        Reason = "§4SharpMC\n§fServer threw an exception!\n\nFor the nerdy people: \n" + ex.Message
                    }.Write();
                    break;
                }
            }
            //Close the connection with the client. :)
            Client.ThreadPool.KillAllThreads();
            Client.StopKeepAliveTimer();

            if (Client.Player != null)
            {
                Client.Player.Level.RemovePlayer(Client.Player);
                Client.Player.Level.BroadcastPlayerRemoval(Client);
            }
            Client.TcpClient.Close();
            Thread.CurrentThread.Abort();
        }
Ejemplo n.º 16
0
        private bool ExecuteCommand(MethodInfo method, Player player, string[] args, CommandAttribute commandAttribute)
        {
            var parameters = method.GetParameters();

            var addLenght = 0;

            if (parameters.Length > 0 && parameters[0].ParameterType == typeof(Player))
            {
                addLenght = 1;
            }

            if (parameters.Length != args.Length + addLenght)
            {
                player.SendChat("Invalid parameters specified!");
                player.SendChat(commandAttribute.Usage);
                return(true);
            }


            var objectArgs = new object[parameters.Length];

            for (var k = 0; k < parameters.Length; k++)
            {
                var parameter = parameters[k];
                var i         = k - addLenght;
                if (k == 0 && addLenght == 1)
                {
                    if (parameter.ParameterType == typeof(Player))
                    {
                        objectArgs[k] = player;
                        continue;
                    }
                    ConsoleFunctions.WriteWarningLine("Command method " + method.Name + " missing Player as first argument.");
                    return(false);
                }

                if (parameter.ParameterType == typeof(string))
                {
                    objectArgs[k] = args[i];
                    continue;
                }
                if (parameter.ParameterType == typeof(byte))
                {
                    byte value;
                    if (!byte.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }
                if (parameter.ParameterType == typeof(short))
                {
                    short value;
                    if (!short.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }
                if (parameter.ParameterType == typeof(int))
                {
                    int value;
                    if (!int.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }
                if (parameter.ParameterType == typeof(bool))
                {
                    bool value;
                    if (!bool.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }
                if (parameter.ParameterType == typeof(float))
                {
                    float value;
                    if (!float.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }
                if (parameter.ParameterType == typeof(double))
                {
                    double value;
                    if (!double.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                return(false);
            }

            var pluginInstance = _plugins.FirstOrDefault(plugin => plugin.GetType() == method.DeclaringType);

            if (pluginInstance == null)
            {
                return(false);
            }

            if (method.IsStatic)
            {
                method.Invoke(null, objectArgs);
            }
            else
            {
                if (method.DeclaringType == null)
                {
                    return(false);
                }

                method.Invoke(pluginInstance, objectArgs);
            }

            return(true);
        }
Ejemplo n.º 17
0
        public virtual void ParseCommand(ICommandSender sender, string message, string prefix)
        {
            var origMessage = message;

            try
            {
                message = message.Trim();
                while (message.Contains("  "))
                {
                    message = message.Replace("  ", " ");
                }
                var split   = message.Split(' ');
                var label   = split.Length == 1 ? message : message.Substring(0, message.IndexOf(' '));
                var command = GetCommand(label);

                {
                    var e = new CommandEvent(sender, command, origMessage, label, prefix, this, EventType.Pre);
                    EventManager.CallEvent(e);
                    if (e.Cancelled)
                    {
                        return;
                    }
                    if (e.Message != origMessage)
                    {
                        origMessage = e.Message;

                        message = origMessage.Trim();
                        while (message.Contains("  "))
                        {
                            message = message.Replace("  ", " ");
                        }

                        split = message.Split(' ');
                    }

                    command = e.Command;
                    sender  = e.Sender;
                    label   = e.Label;
                    prefix  = e.Prefix;
                }

                if (command == default(Command))
                {
                    UnknownCommand(sender, label);
                    return;
                }

                string[] args;
                if (split.Length > 1)
                {
                    args = new string[split.Length - 1];
                    Array.Copy(split, 1, args, 0, split.Length - 1);
                }
                else
                {
                    args = new string[0];
                }

                command.Execute(sender, label, args, origMessage);

                {
                    var e = new CommandEvent(sender, command, origMessage, label, prefix, this, EventType.Post);
                    EventManager.CallEvent(e);
                }
            }
            catch (Exception ex)
            {
                ConsoleFunctions.WriteWarningLine(ex.ToString());
                sender.SendChat("An error occured when executing this command.", TextColor.Red);
            }
        }
Ejemplo n.º 18
0
        private bool ExecuteCommand(MethodInfo method, Player player, string[] args, CommandAttribute commandAttribute)
        {
            var parameters = method.GetParameters();

            var addLenght          = 0;
            int requiredParameters = 0;

            if (parameters.Length > 0 && parameters[0].ParameterType == typeof(Player))
            {
                addLenght          = 1;
                requiredParameters = -1;
            }

            bool hasRequiredParameters = true;
            bool hasStringArray        = false;

            foreach (var param in parameters)
            {
                if (!param.IsOptional)
                {
                    requiredParameters++;
                }
                if (param.ParameterType == typeof(string[]))
                {
                    hasStringArray = true;
                }
            }

            if (args.Length < requiredParameters && !hasStringArray)
            {
                hasRequiredParameters = false;
            }

            if (!hasRequiredParameters || args.Length > (parameters.Length - addLenght) && !hasStringArray)
            {
                player.SendChat("Invalid command usage!", ChatColor.Red);
                player.SendChat(commandAttribute.Usage, ChatColor.Red);
                return(true);
            }

            var objectArgs = new object[parameters.Length];

            bool          stringarrayfound    = false;
            int           stringarrayposition = 0;
            List <string> stringarrayvalues   = new List <string>();

            int length = args.Length + addLenght;

            for (var k = 0; k < length; k++)
            {
                var parameter = parameters[k];
                var i         = k - addLenght;
                if (k == 0 && addLenght == 1)
                {
                    if (parameter.ParameterType == typeof(Player))
                    {
                        objectArgs[k] = player;
                        continue;
                    }
                    ConsoleFunctions.WriteWarningLine("Command method " + method.Name + " missing Player as first argument.");
                    return(false);
                }

                if (parameter.ParameterType == typeof(string[]))
                {
                    stringarrayfound    = true;
                    stringarrayposition = k;
                    stringarrayvalues.Add(args[i]);

                    objectArgs[stringarrayposition] = stringarrayvalues.ToArray();
                    break;
                }

                if (parameter.ParameterType == typeof(string))
                {
                    objectArgs[k] = args[i];
                    continue;
                }

                if (parameter.ParameterType == typeof(byte))
                {
                    byte value;
                    if (!byte.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(short))
                {
                    short value;
                    if (!short.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(int))
                {
                    int value;
                    if (!int.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(bool))
                {
                    bool value;
                    if (!bool.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(float))
                {
                    float value;
                    if (!float.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(double))
                {
                    double value;
                    if (!double.TryParse(args[i], out value))
                    {
                        return(false);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                if (parameter.ParameterType == typeof(Player))
                {
                    Player value = Globals.LevelManager.GetAllPlayers().FirstOrDefault(p => p.Username.ToLower().Equals(args[i].ToLower()));
                    if (value == null)
                    {
                        player.SendChat(String.Format("Player \"{0}\" is not found!", args[i]), ChatColor.Red);
                        return(true);
                    }
                    objectArgs[k] = value;
                    continue;
                }

                return(false);
            }

            if (stringarrayfound)
            {
                for (int k = stringarrayposition + 1; k <= args.Length; k++)
                {
                    var i = k - addLenght;
                    stringarrayvalues.Add(args[i]);
                    objectArgs[stringarrayposition] = stringarrayvalues.ToArray();
                }
            }

            var pluginInstance = _plugins.FirstOrDefault(plugin => plugin.GetType() == method.DeclaringType);

            if (pluginInstance == null)
            {
                ConsoleFunctions.WriteDebugLine("Plugin instance is null!");
                return(false);
            }

            if (method.IsStatic)
            {
                method.Invoke(null, objectArgs);
            }
            else
            {
                if (method.DeclaringType == null)
                {
                    return(false);
                }

                method.Invoke(pluginInstance, objectArgs);
            }

            return(true);
        }