Solved Softdepends

Discussion in 'Plugin Development' started by Hex_27, Dec 17, 2014.

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

    Hex_27

    I wanted a soft depend on factions, but without factions, it will say that it can't find factions. Is there a way for me to let the plugin ignore anything that has to do with factions if factions isn't present?
     
  2. @Hex_27 If factions is not found, then don't enable any of your faction related content. One easy way to do this would be to have a class dedicated to your faction stuff, and then only enable that class (i.e. by registering events/commands) if factions was found :)
     
  3. Bukkit.getPlugin("PluginName") != null
    Plugin exists
     
  4. Offline

    Hex_27

    @AdamOpzm So I need make alternate versions of my classes with nothing to do with factions? And also, if I softdepend muliple plugins, then how do I check for that? I can't possibly make tons of classes for each scenario
     
  5. Offline

    mythbusterma

    @Hex_27

    It's not ideal, but it would likely be best to congregate everything that requires factions into a group of classes that all implement interfaces, and have separate versions of those classes that implement the same interface, and instantiate them based on whether or not you have factions.
     
  6. Offline

    Hex_27

    @Mythbusterma yes, but for example, if I softdepend worldguard AND factions, and the owner doesn't have 1 of them, do I need to make 4 different classes based on 4 different scenarios?
     
  7. Offline

    mythbusterma

    @Hex_27

    Assuming they needed to be in the same class, but I'm sure you can figure a way around that.
     
  8. @Hex_27 My class idea was just an example. There are other solutions, if you think about it enough. Hint: You won't get "class not found" errors if the methods don't attempt to find the classes they know don't exist ;)
     
  9. Offline

    Hex_27

    @AdamQpzm How? I can't do a try/ catch on imports.
    @mythbusterma They don't, but now I'm thinking of cloning every single class that contains factions imports and just make new ones that don't import factions.
     
  10. Online

    timtower Administrator Administrator Moderator

    @Hex_27 Don't try to get instances of the classes that are from factions.
     
  11. Offline

    Hex_27

    @timtower So.. there's no way for me to let my code ignore anything in the class that has to do with factions? (Now I'm using 2 different sets of classes, one if factions is present, and the other for when factions is not present.)
     
  12. Online

    timtower Administrator Administrator Moderator

    @Hex_27 Your way is a good one. Can't recall how I did stuff like this in the past. I believe that I just ignored a certain variable.
     
  13. Offline

    Hex_27

    @timtower I decided to make new classes because my ordinary classes already have a LOT of if() stuff, such that the code is...a little untidy. Would be hard to make another surrounding if and double the code size.
     
  14. Online

    timtower Administrator Administrator Moderator

    @Hex_27 Make sure to use an interface in between :p
     
Thread Status:
Not open for further replies.

Share This Page