Advertisement
Guest User

Untitled

a guest
Jan 29th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. using ModuleShared;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4.  
  5. //Your namespace must match the assembly name and the filename. Do not change one without changing the other two.
  6. namespace ValheimSyncPlugin
  7. {
  8. //The first class must be called PluginName
  9. public class PluginMain : AMPPlugin
  10. {
  11. private readonly Settings _settings;
  12. private readonly ILogger log;
  13. private readonly IConfigSerializer _config;
  14. private readonly IPlatformInfo platform;
  15. private readonly IRunningTasksManager _tasks;
  16. private readonly IApplicationWrapper application;
  17. private readonly IPluginMessagePusher message;
  18. private readonly IFeatureManager features;
  19.  
  20. //All constructor arguments after currentPlatform are optional, and you may ommit them if you don't
  21. //need that particular feature. The features you request don't have to be in any particular order.
  22. //Warning: Do not add new features to the feature manager here, only do that in Init();
  23. public PluginMain(ILogger log, IConfigSerializer config, IPlatformInfo platform,
  24. IRunningTasksManager taskManager, IApplicationWrapper Application,
  25. IPluginMessagePusher Message, IFeatureManager Features)
  26. {
  27. //These are the defaults, but other mechanisms are available.
  28. config.SaveMethod = PluginSaveMethod.KVP;
  29. config.KVPSeparator = "=";
  30. this.log = log;
  31. _config = config;
  32. this.platform = platform;
  33. _settings = config.Load<Settings>(AutoSave: true); //Automatically saves settings when they're changed.
  34. _tasks = taskManager;
  35. application = Application;
  36. message = Message;
  37. features = Features;
  38. _settings.SettingModified += Settings_SettingModified;
  39. }
  40.  
  41. /*
  42. Rundown of the different interfaces you can ask for in your constructor:
  43. IRunningTasksManager - Used to put tasks in the left hand side of AMP to update the user on progress.
  44. IApplicationWrapper - A reference to the running application from the running module.
  45. IPluginMessagePusher - For 'push' type notifications that your front-end code can react to via PushedMessage in Plugin.js
  46. IFeatureManager - To expose/consume features to/from other plugins.
  47. */
  48.  
  49. //Your init function should not invoke any code that depends on other plugins.
  50. //You may expose functionality via IFeatureManager.RegisterFeature, but you cannot yet use RequestFeature.
  51. public override void Init(out WebMethodsBase APIMethods)
  52. {
  53. APIMethods = new WebMethods(_tasks);
  54.  
  55. }
  56.  
  57. void Settings_SettingModified(object sender, SettingModifiedEventArgs e)
  58. {
  59. //If you need to export settings to a different application, this is where you'd do it.
  60. }
  61.  
  62. public override bool HasFrontendContent => true;
  63.  
  64. //This gets called after every plugin is loaded. From here on it's safe
  65. //to use code that depends on other plugins and use IFeatureManager.RequestFeature
  66. public override void PostInit()
  67. {
  68. }
  69.  
  70. public override IEnumerable<SettingStore> SettingStores => Utilities.EnumerableFrom(_settings);
  71.  
  72.  
  73. public void StopServer()
  74. {
  75. application.Stop();
  76.  
  77. }
  78. }
  79.  
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement