• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Disabling Other Plugins

    Discussion in 'Community Developer Forum' started by newb23, Apr 13, 2015.

    1. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Kind of a continuation of my last thread, but, this might make it easier to search for for people later. :p

      I am attempting to compile a string of all currently enabled plugins, disable all of them, run my plugin, then re-enable ONLY the plugins that I previously disabled.

      I looked into only disabling one plugin at a time, but the API listing @ PluginManager Class and through the object browser does not list a one-by-one basis.


      I have attached my code for a full review, but, the issues in question are at lines 209 - 213 in Movement.cs

      [HIDE]
      Code:
                      foreach (var enabledPlugins in PluginManager.GetEnabledPlugins())
                      {
                          Logging.Write("[RetBot] Plugins Enabled: " + enabledPlugins);
                          PluginManager.ShutdownAllPlugins();
                      }
      
      [/HIDE]

      and at lines 273 - 274 in Movement.cs.

      [HIDE]
      Code:
                      Logging.Write("RetBot Tasking Completed. Releasing control!");
                      PluginManager.SetEnabledPlugins(plugins: enabledPlugins);
      
      [/HIDE]

      What I am missing, is why I cannot take the var enabledPlugins @ line 209 and call it from 274. I assumed that GetEnabledPlugins() put them into a list called enabledPlugins?
      Am I just trying to declare and pass the value wrong, or, do I need to set up the variable elsewhere? I'm not really sure. :p

      Thank you for your help!
       

      Attached Files:

    2. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,335
      Likes Received:
      380
      Trophy Points:
      83
      PluginManager.ShutdownAllPlugins();
      Do not use this. This is is for when plugins are reloaded and really shouldn't be public...

      You just need to do something like...

      private List<PluginContainer> plugins = new ...

      foreach(var plugin in PluginManager.Plugins)
      {

      if (plugin.Plugin != this && plugin.Enabled)
      {
      plugin.Enabled = false;
      plugins.Add(plugin);
      }

      }

      then just iterate over the ones you stored and turn them back on when you are done(make sure to clear the list after that)
       
    3. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Haha, I thought it was a little sketchy, but I was trying to follow what I saw in the API. I really, really am trying to learn the ins and outs of this programming thing, and am trying hard to avoid having my code labeled as your so-called "shit code". ;)

      I'll work out getting this edited in there. Thank you, Mastahg.
       
    4. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Okay, so, I added the code you provided, looks to be good except for this.

      [01:21:33.228 N] Compiler Error: c:\Users\Omni\Desktop\RB\Plugins\RetBot\Movement.cs(212,47) : error CS0026: Keyword 'this' is not valid in a static property, static method, or static field initializer


      I assume there is another way to say this? (My Plugin)

      I tried to make the keyword a string called "RetBot", but the compiler did not like that.

      I tried to make the containing method non-static, which set off a myriad of methods that needed to be edited, and ultimately would not compile.

      I also tried to move it out of the retainermove method, but, I can't because I need it to execute every time I DO go to move, as that is the only place that I would run into issues.

      I then tried to make it it's own method and then call it from within the retainermove method, but, I got lost in when exactly I was trying to call.



      Slight Edit @ 1907 PST:

      Lines Changed:

      208 - 214 TO:

      [HIDE]
      Code:
                      var plugins = new List<PluginContainer>();
      
      
                      foreach (var plugin in PluginManager.Plugins.Where(plugin => plugin.Plugin != this && plugin.Enabled))
                      {
                          plugin.Enabled = false; 
                          plugins.Add(plugin);
                      }
      
      [/HIDE]

      274 - 279 TO:

      [HIDE]
      Code:
                      Logging.Write("RetBot Tasking Completed. Releasing control!");
                      foreach (var plugin in plugins)
                      {
                              plugin.Enabled = true;
                              plugins.Remove(plugin);
                      }
      
      [/HIDE]
       

      Attached Files:

      Last edited: Apr 13, 2015
    5. Psicu

      Psicu New Member

      Joined:
      Feb 1, 2015
      Messages:
      20
      Likes Received:
      3
      Trophy Points:
      0
      I am not a C# programmer, but I think you could do something like this:

      Code:
      (plugin.Plugin.Name != "RetBot" && plugin.Enabled)
      @EDIT

      Another way I think it may work is doing something like:

      Code:
      _root = new ActionRunCoroutine(r => MovementActions.RetainerMove(this));
      Code:
       public static async Task<bool> RetainerMove(RetBot _this)
      ...
      (plugin.Plugin != _this && plugin.Enabled)
      
       
      Last edited: Apr 14, 2015
      newb23 likes this.
    6. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      The first method you linked does not work whatsoever, the second I had attempted and failed earlier after I couldn't figure out the exceptions/implementation.

      HOWEVER!

      Your way of implementing it worked like a charm! Thank you!
       
    7. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,335
      Likes Received:
      380
      Trophy Points:
      83
      This error is because you are trying to use 'this' inside a static function. You shouldn't really need anything static as should only be one instance of your plugin at a time.
       
    8. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Yeah. I'm not really sure when I made all of my methods static to be honest, but as I was trying to retroactively make them non-static I made the entire plugin non-functional. With the call that Psicu posted a little while ago it seems to be working properly, a little hiccup right as the plugin starts, but only if another plugin teleports before mine is loaded and sets itself to run.

      Following that initial teleport prior to my plugin running though, everything seems to be running fantastically!

      Thank you for your help yet again!
       

    Share This Page