Continue script abstraction

This commit is contained in:
hydrant
2020-03-01 13:15:50 +01:00
parent 37f499a446
commit d7a76caf2a
14 changed files with 531 additions and 8 deletions

View File

@@ -13,6 +13,8 @@ using ReallifeGamemode.Server.Core.RageMP;
using ReallifeGamemode.Server.Core.Events;
using System.Collections.Generic;
using ReallifeGamemode.Server.Common;
using System.Reflection;
using System.Linq;
using ReallifeGamemode.Server.Job;
/**
@@ -35,10 +37,18 @@ namespace ReallifeGamemode.Server
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
var methods = Assembly.GetExecutingAssembly()
.GetTypes()
.SelectMany(t => t.GetMethods())
.Where(m => m.GetCustomAttributes(typeof(CommandAttribute), false).Length > 0)
.ToArray();
var registeredCommands = methods.Select(c => c.GetCustomAttribute<CommandAttribute>().CommandString);
IAPI apiInstance = new RageAPI();
eventHandler = new EventHandler(apiInstance);
new Core.Main(apiInstance, eventHandler);
new Core.Main(apiInstance, eventHandler, registeredCommands.ToArray());
NAPI.Server.SetGlobalServerChat(false);