Solved Including One Jar Into Your Plugin's Jar

Discussion in 'Plugin Development' started by ERROR372, Jul 7, 2013.

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

    ERROR372

    So I've been working on a Permissions plugin, and needed it to work with WorldEdit, WorldGuard, Craftbook, and CommandBook. For this, I need to implement com.sk89q.wepif.PermissionsProvider.

    To do this, I right-clicked on my project folder, clicked Properties, went to Java Build Path, and added the external WorldEdit jar. This fixed my problem of importing the class. Now the only problem I have is that when I run a server that doesn't have WorldEdit as a plugin, it doesn't load my permissions plugin, and gives me a NoClassDefFoundError. Obviously this is because the WorldEdit jar is not in the server folder. But I don't want this. I want my plugin to be able to operate with or without WorldEdit.

    I also followed this tutorial to no avail: https://forums.bukkit.org/threads/tutorial-use-external-library-s-with-your-plugin.103781/

    So either, I need to find a way to make my plugin read files from the added External Jar (which it's obviously not doing), or a way to only import/implement the PermissionsProvider class when the plugin is present.

    Any ideas? I'm really stumped =\
     
  2. Offline

    soulofw0lf

    making a soft depend is actually part of the default bukkit plugin creation tutorial if i'm not mistaken.
     
  3. Offline

    ERROR372

    soulofw0lf

    Should have mentioned that. Tried a softdepend in the plugin.yml, didn't work as well. In fact, it's still there... softdepend: [WorldEdit]
     
  4. Offline

    soulofw0lf

    you also need to make a check to only call the methods if world edit is present
     
  5. Offline

    ERROR372

    soulofw0lf

    Thing about that is that in order for WorldEdit to recognize my plugin as the one that provides permissions, I have to either do:

    import com.sk89q.wepif.PermissionsProvider
    or
    public final class GeneralPermissions extends JavaPlugin implements com.sk89q.wepif.PermissionsProvider

    Of course, if the WorldEdit jar is not in the plugins folder, this throws the NoClassDefFoundError.
     
  6. Offline

    soulofw0lf

  7. Offline

    Bammerbom

    if(getServer().getPluginManager().getPlugin("") != null){
     
  8. Offline

    ERROR372

    Jhtzb

    Right, that's how I check if the plugin is there, but I need to know that before I even hit any of the code. As stated above, I have to either:

    import com.sk89q.wepif.PermissionsProvider;
    or
    public final class GeneralPermissions extends JavaPlugin implements com.sk89q.wepif.PermissionsProvider

    and that's where it causes the problem. I can't put checks in before either of those (unless I can, and there's a way I don't know of).
     
  9. Offline

    Me4502


    You'll need to somehow check before the class is even loaded... I'd recommend looking into GroupManager, as suggested above. If you use SuperPerms however this shouldn't even be required. WorldEdit has amazing support for SuperPerms (DinnerPerms in WEPIF)
     
  10. Offline

    ERROR372

    Me4502

    I looked into GroupManager, couldn't find a thing at all related to what I need.

    I hate to ask, but I've looked up all I can, and not found much information on SuperPerms. Most relevant information I found was that it "had one line to check if a user had permission or not". Well that's not helpful for what I need to do. I assume (from my reading) that SuperPerms is "built-in" to the bukkit API. So, how do I go about hooking into it, and having WorldEdit recognize my plugin as the permissions provider?
     
  11. Offline

    Me4502


    There are addPermissions methods in Player or something.
     
  12. Offline

    ERROR372

    Me4502

    Sure, I did that. Made permission attachments and everything. But WorldEdit doesn't recognize my plugin as the permission giver, so anything that uses WEPIF (WorldEdit, WorldGuard, CraftBook, CommandBook), I can't give permissions to regular players for those. I'm not sure if I am missing a class that I need to create, or whatnot. Driving me insane. I just want this plugin to work with WorldEdit (and the others mentioned), and without it.
     
  13. Offline

    Me4502


    From what I can tell in the WorldEdit WEPIF code, to use PermissionsProvider you must depend WorldEdit, or at least depend it as a library (Similar to WorldGuard, CraftBook, etc which all depend as a lib, not a plugin)
     
    ERROR372 likes this.
  14. Offline

    ERROR372

    Me4502

    Thanks for that. Seems to almost work perfectly. Only thing I'm getting is null problems forcing me to do a /reload. After the /reload, it works perfectly fine. Might have to do with running a 1.6.1 jar on a 1.6.2 server though, not sure. Also, noticed in the plugin folder, the WorldEdit jar I used as the library was there... is that normal (i sorta assume so)?

    Followed this to get the library: https://forums.bukkit.org/threads/tutorial-use-external-library-s-with-your-plugin.103781/
     
  15. Offline

    Me4502


    Wait, WorldEdit.jar is inside your plugins jar file? Thats very bad and should be removed. What null problems do you have? /reload can be very dangerous and requiring it for your plugin to work is incredibly bad.
     
  16. Offline

    ERROR372

    I put the WorldEdit.jar inside a lib folder, and used the code from the link I put in my last post to get the file and such. Is that not how it works? I'm looking into this Maven shading stuff, not sure if I'm going in the completely wrong direction though =P

    Null stuff:

    Code:
    01:06:50 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing '/wand' in co
    m.sk89q.bukkit.util.DynamicPluginCommand(/wand)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    3)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon
    nection.java:964)
            at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j
    ava:882)
            at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    :839)
            at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    :118)
            at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    90)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.VerifyError: (class: com/sk89q/worldedit/LocalPlayer, metho
    d: passThroughForwardWall signature: (I)Z) Incompatible argument to function
            at com.sk89q.worldedit.bukkit.WorldEditPlugin.wrapPlayer(WorldEditPlugin
    .java:346)
            at com.sk89q.worldedit.bukkit.WorldEditPlugin.wrapCommandSender(WorldEdi
    tPlugin.java:351)
            at com.sk89q.worldedit.bukkit.WorldEditPlugin.onCommand(WorldEditPlugin.
    java:242)
            at com.sk89q.bukkit.util.DynamicPluginCommand.execute(DynamicPluginComma
    nd.java:52)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            ... 14 more
    But yeah, (plugin is called GeneralPermissions) I go into the GeneralPermissions folder (which houses other directories and the config.yml), and there's the WorldEdit.jar. And yes, I know requiring a /reload is bad, trying to fix that part =P
     
  17. Offline

    Me4502

    Thats not null... You were giving a method an argument which it doesn't want.
     
  18. Offline

    ERROR372

    Me4502

    Nevermind, seems I didn't need that link's code. Just had to put the WorldEdit.jar inside the lib folder, and it works perfectly after removing that code. Even says "WEPIF: Using GeneralPermissions plugin for permissions". I assume that's all I have to do. WorldEdit.jar is no longer in GeneralPermissions folder, and no /reload is necessary.

    And about that error, all I did was "//wand", which should have been perfectly fine. Think it was the extra WorldEdit jar causing some problems.

    I think it's all good. Sound that way to you?
     
  19. Offline

    Me4502


    Yes, that sounds all good. The extra jar probably caused those errors.
     
    ERROR372 likes this.
  20. Offline

    ERROR372

    Me4502

    Thank you very much. I appreciate the time you took to help me out, can't wait for this plugin to be finished =)
     
Thread Status:
Not open for further replies.

Share This Page