Making modular Commands

Discussion in 'Plugin Development' started by HackintoshMan, Jul 17, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    HackintoshMan

    I would like the option for my users to be able to disable a command from the plugin completely, so if they disable /home on my plugin then they can use /home on a different plugin. I could have every command group (Home commands, TP commands, time commands) as separate jars and make them dependent to the master plugin. Would that be dumb or is there a better way?
     
  2. Offline

    Alxlre

    HackintoshMan That would be very dumb. For each command, you should have a HashSet containing all the players names who have disabled that command. Then when the command is executed, you should check if that player has disabled the command and make them not be able to execute the command.

    Considering you want to have another plugin override yours, I'm afraid what you thought of is the only way.
     
  3. Offline

    Wingzzz

    File containing a list of commands each of type boolean, if true, enabled... If false, disabled-- meaning your plugin will not listen for it. When you use onCommand(...).. before if(command.getName().equalsIgnoreCase("") { yada yada, just say:
    Code:java
    1. if(config.getBoolean("commands.COMMAND_I'M_CHECKING_FOR") == false) {
    2. return true;
    3. }

    There are better ways, but that comes with more complex ways of handling commands, and at that point if you had a system like that, this wouldn't even be a concern.

    Good luck with transferring to the modular life style! It's a great way to be, and I highly recommend everyone to attempt to be more modular with their projects!
     
  4. Offline

    HackintoshMan

    I have config with a list of commands:

    Code:
    Commmands:
      Time: true
      Spawn: true
      Setspawn: true
      Biome: true
      Tp: true
      Tphere: true
      Kick: true
      Kill: true
      Ignite: true
      Strike: true
      Heal: true
      Spawnmob: true
    
    I want to just not register the ones with false, but since they are i the plugin.yml I don't think I can do that because they are still technically used by my plugin...


    The commands would be disabled for the entire server, not individual players.
     
  5. Offline

    Wingzzz

    HackintoshMan
    If you know about reflection, or are capable of more complex systems, you could try making an abstract class to extend to make commands(IE: MyNewCommand extends AbstractCommand). AbstractCommand should extend Command, then you can add anything you want for extra methods etc... Then, make a command manager that uses reflection to grab the CommandMap(in CB not Bukkit), now once you've got a hold of it, when you go to register your commands via the methods you write in the command handler to register them via the command map, you just check the config to see whether or not they're enabled/disabled(true/false) and register accordingly.
     
  6. Offline

    HackintoshMan

    I got to about the second line and then you lost me:eek: I am by far NOT advanced:D

    Would it seem ok to have like a bundle that gets downloaded (ZIP file) and inside it are:

    Main plugin
    Home commands
    TP commands
    Ban Commands

    and all of the command plugins are dependent upon the main plugin. Would there be extra memory being used?
     
  7. Offline

    Wingzzz

    Depends on what they do. I would honestly just put them all in one plugin. Just because they depend on something doesn't mean they need to be separate. Unless by modular you meant add/remove jars, which isn't really the greatest way of handling whether or not something is enabled/disabled.

    (Also, sorry about my earlier post, I didn't know how much you were capable of, and as well I may have not worded things properly.)
     
Thread Status:
Not open for further replies.

Share This Page