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

@@ -17,12 +17,13 @@ namespace ReallifeGamemode.Server.Core.Commands
private readonly ILogger logger = LogManager.GetLogger<CommandHandler>();
private readonly IAPI api;
private readonly string[] legacyCommands;
private Random random = new Random();
public CommandHandler(IAPI api)
public CommandHandler(IAPI api, string[] registeredCommands)
{
this.api = api;
legacyCommands = registeredCommands;
Main.EventHandler.RegisterClientEvent("Command", OnPlayerCommand);
}
@@ -32,6 +33,11 @@ namespace ReallifeGamemode.Server.Core.Commands
logger.LogInformation("Player '{Name}' executed command '{command}'", player.Name, command);
if(legacyCommands.Contains(command))
{
return;
}
if (!registeredCommands.ContainsKey(command))
{
player.SendMessage($"Der Befehl ~b~/{command}~s~ existiert nicht", ChatPrefix.Error);

View File

@@ -20,14 +20,18 @@ namespace ReallifeGamemode.Server.Core
private readonly ILogger logger = LogManager.GetLogger<Main>();
public Main(IAPI api, Events.EventHandler eventHandler)
public Main(IAPI api, Events.EventHandler eventHandler, string[] registeredCommands)
{
logger.LogInformation("Loading scripts...");
API = api;
EventHandler = eventHandler;
API.DisableDefaultCommandErrorMessages();
API.DisableDefaultSpawnBehavior();
API.SetGlobalChatEnabled(false);
LoadScript();
LoadCommands();
LoadCommands(registeredCommands);
}
private void LoadScript()
@@ -43,9 +47,9 @@ namespace ReallifeGamemode.Server.Core
}
}
private void LoadCommands()
private void LoadCommands(string[] registeredCommands)
{
CommandHandler commandHandler = new CommandHandler(API);
CommandHandler commandHandler = new CommandHandler(API, registeredCommands);
var allTypes = Assembly.GetExecutingAssembly().GetTypes();
var commandTypes = allTypes.Where(t => t.IsSubclassOf(typeof(Command)) && !t.IsAbstract);