public override void GenericEvent(GenericEvent e) { // Unless you specifically want to override some of the plugins default // functionality, you should always call the base method. base.GenericEvent(e); // Your plugin won't get a majority of the possible events since there isn't // actually a method for Potato to push these events through (on purpose) // Shortest history: It was replaced with the command preview/execute/executed // so plugins could intercept the actual command that would fire the event. // Now we just use it for internal plugin events. // See Potato.Net.GameEventType enum for descriptions of each possible event. if (e.GenericEventType == GenericEventType.PluginsEnabled) { // Consider this event here to be the start of your plugin. It's live, will // get commands and events from now on. Console.WriteLine("Program.GenericEvent.PluginsPluginEnabled: k, go!"); // Log a custom event with Potato whenever this plugin is enabled. You // can log these whenever you want something recorded/transported over the push event this.Bubble(CommandBuilder.EventsLog(new GenericEvent() { Name = "This is a custom event that will be logged when the plugin is enabled." })); } }
public override void GenericEvent(GenericEvent e) { base.GenericEvent(e); if (e.GenericEventType == GenericEventType.PluginsEnabled) { // Plugin is enabled and Potato will now accept our commands/actions. // 2. Register a text command (tell it what command to call when it is matched) // If you wanted to follow the execution of this eventually you will find yourself in Potato.Core.Connections.TextCommands.TextCommandController.RegisterTextCommand this.Bubble(new Command() { CommandType = CommandType.TextCommandsRegister, Scope = new CommandScopeModel() { ConnectionGuid = this.ConnectionGuid }, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = this.PluginGuid, Parser = TextCommandParserType.Fuzzy, PluginCommand = "FuzzyCommand", // This will be the command name that comes through Description = "FuzzyCommandDescription", // When using the fuzzy parser you just need to supply keywords to pickup in a text command Commands = new List<String>() { "Test", "Blah", "Fuzzy" } } } } } } }); // Register a route command, which is a very specific format of text command this.Bubble(new Command() { CommandType = CommandType.TextCommandsRegister, Scope = new CommandScopeModel() { ConnectionGuid = this.ConnectionGuid }, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = this.PluginGuid, Parser = TextCommandParserType.Route, PluginCommand = "RouteCommand", // This will be the command name that comes through Description = "RouteCommandDescription", // When using the route parser the structure must be identical // to one of the command "routes" supplied below. Commands = new List<String>() { "route", "route :player", "route :player :text", "route :map", "route :map :text", "route :number", } } } } } } }); } }
public override void GenericEvent(GenericEvent e) { Console.WriteLine("Test Plugin ({0}) Event: {1}", this.PluginGuid, e.Name); if (e.GenericEventType == GenericEventType.TextCommandRegistered) { this.Commands.Add(e.Now.TextCommands.First()); } else if (e.GenericEventType == GenericEventType.TextCommandUnregistered) { this.Commands.Remove(e.Now.TextCommands.First()); } else if (e.GenericEventType == GenericEventType.PluginsEnabled) { this.Bubble(new Command() { CommandType = CommandType.TextCommandsRegister, Scope = new CommandScopeModel() { ConnectionGuid = this.ConnectionGuid }, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = this.PluginGuid, PluginCommand = "TestCommand", Name = "Test", Description = "Tests a command, outputting the results to player chat.", Commands = new List<String>() { "Test" } } } } } } }); this.Bubble(new Command() { CommandType = CommandType.TextCommandsRegister, Scope = new CommandScopeModel() { ConnectionGuid = this.ConnectionGuid }, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = this.PluginGuid, PluginCommand = "KillCommand", Name = "Kill", Description = "Kills any matching players, sending a message to them that the action was for tesing.", Commands = new List<String>() { "Kill" } } } } } } }); this.Bubble(new Command() { CommandType = CommandType.TextCommandsRegister, Scope = new CommandScopeModel() { ConnectionGuid = this.ConnectionGuid }, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = this.PluginGuid, PluginCommand = "HelpCommand", Priority = 100, Name = "Help", Description = "Provides help about another command.", Commands = new List<String>() { "Help" } } } } } } }); } base.GenericEvent(e); }
/// <summary> /// See the Potato.Examples.Events project for details on why this event handler exists. /// </summary> /// <param name="e"></param> public override void GenericEvent(GenericEvent e) { base.GenericEvent(e); if (e.GenericEventType == GenericEventType.PluginsEnabled) { // You don't need to store a reference to this object as it'll only be executed // the once then forgotten. new Migrations() { BubbleObjects = { // Tell the controller to bubble commands to this object, which will // then eventually pass the commands onto Potato. this } }.Execute(); // That's it. Your migration/tables/collection should be all updated! } }
/// <summary> /// If you override this method then you should call the base, unless you want to implement your /// own functionality. All actions here are dispatched to other virtual methods that you can override in /// your plugin if you just want to prevent/alter some default functionality. /// </summary> /// <param name="e"></param> public virtual void GenericEvent(GenericEvent e) { if (e.GenericEventType == GenericEventType.PluginsLoaded) { this.GenericEventTypePluginLoaded(e); } else if (e.GenericEventType == GenericEventType.PluginsUnloading) { this.GenericEventTypePluginUnloading(e); } else if (e.GenericEventType == GenericEventType.TextCommandExecuted) { this.GenericEventTypeTextCommandExecuted(e); } }
/// <summary> /// A text command has been executed and it's callback directs to this plugin. /// </summary> /// <remarks>We convert to a new command and push it through to this plugin, /// which just cleans up the plugin implementation a little bit but converting /// a plugin executed command to a local command. Snazzified.</remarks> /// <param name="e"></param> protected virtual void GenericEventTypeTextCommandExecuted(GenericEvent e) { this.Tunnel(new Command() { Origin = CommandOrigin.Local, Name = e.Now.TextCommands.First().PluginCommand, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { Events = new List<IGenericEvent>() { e } } } } }); }
/// <summary> /// Consider this the plugin destructor /// </summary> /// <param name="e"></param> protected virtual void GenericEventTypePluginUnloading(GenericEvent e) { this.WriteConfig(); }
/// <summary> /// Consider this your constructor. /// </summary> /// <param name="e"></param> protected virtual void GenericEventTypePluginLoaded(GenericEvent e) { this.LoadConfig(); }
public void TestPushEventsDisposedEventIsRemoved() { var pushEndPoint = new PushEventsEndPoint(); var genericEventArgs = new GenericEvent() { Message = "What up?" }; pushEndPoint.Append(genericEventArgs); genericEventArgs.Dispose(); Assert.AreEqual(0, pushEndPoint.EventsStream.Count); }