Use methods of external Jar's

Discussion in 'Plugin Development' started by twinflyer, Jan 31, 2012.

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


    Hey guys,
    I'm learning Java for nearly one year now. Untill now I was happy with the things I can, but I need a bit help now.
    I want to check, which Quest a player's doing after typing in a command.
    The quests are made in Citizens.

    I found this:

    On line 431 is this piece of Code:


    How can I use "getQuestName()" in my own plugin?
    Or is this impossible to do?

  2. Offline


    Not impossible, but it does require a little knowledge of how to hook into other plugins. Perusing the source code of Citizens shows that all of the classes and methods involved in that call are public, and that you can get a PlayerProfile object with the static method PlayerProfile.getProfile(player.getName()).

    So far so good: you can call those methods from your plugin. But to actually hook into the plugin, you will want to use the Bukkit PluginManager class to ensure it's loaded, something like this:
    2. // Static field in your main plugin class. This is not necessarily the "best" way
    3. // to make this field visible to other classes in your plugin, but it's quick & easy
    4. // for this example
    5. public static boolean citizensEnabled = false;
    7. // called sometime during your onEnable() method
    8. PluginManager pm = Bukkit.getPluginManager();
    9. Plugin citizensPlugin = pm.getPlugin("Citizens");
    10. if (citizensPlugin != null) {
    11. // the citizens plugin is available to us
    12. citizensEnabled = true;
    13. }
    15. // ... somewhere else in your plugin ...
    16. if (YourPlugin.citizensEnabled) {
    17. PlayerProfile profile = PlayerProfile.getProfile(player.getName());
    18. String questName = profile.getProgress.getQuestName();
    19. // ... etc ...
    20. }

    Some other comments:
    • You will need to add Citizens as a build dependency in your IDE (or Maven if you're using that to build your plugin).
    • You will also need to add Citizens as a dependency in your plugin.yml using the depend: or softdepend: keyword, depending on whether this functionality is essential or optional in your plugin.
    • Caveat: unless the author(s) of Citizens have actually made this part of a publicly documented API, it's your problem if they change anything (e.g. method or class names/visibility/signatures). If they do, your plugin will break and you'll be rushing to get a new version released.
  3. Offline


    thanks you two :)
    will read trough your Posts/links and post again later.

    It says PlayerProfile cannot be resolved (to a type) :S
    I have no Idea wich import I have to use. I thought :;
    but this import "cannot be resolved" , too.

    Sorry, but that's totaly new for me, I never hooked into any plugin without a REALLY good documentation.
  4. Offline


    Right, that's because you need to add Citizens as a build dependency in your IDE, in the same way you added Bukkit.
  5. Offline


    I added Citizend as External Jar in eclipse in the same way i did it with the craftbukkit jar (JavaBuilt path -> Add external Jar)

    if I type "import net.c" eclipse shows some citizens imports. But PlayerProfile isn available.
  6. Offline


    Aha. Looks like that particular package isn't in the core Citizens.jar. You'll also need to add Quester.jar as a build dependency.
  7. Offline


    sorry for not answering, I was on holiday ;D

    I added Citizens and Quester as built dependency, but the Quester.jar isn't located in the olugins folder. Its in plugins/Citizens/types/Quester.jar

    I think thats the reason why bukkit is unable to load the quester.jar (UnknownDependencyException)

    Could you tell me how to change the path of the dependencys inside the plugin.yml?

  8. Offline

    Deleted user

    we now get an "null error" on
    PlayerProfile profile = PlayerProfile.getProfile(player
    we have done some null checks with
    if (PlayerProfile.getProfile(player.getName()) == null) {
                            System.out.println("KEIN SPIELERPROFILE!");
  9. Offline


    the error occures at the "PlayerProfile.getProfile(player.getName())"
    Even the null check throws this error, bevor it really checks if its a null.

    I really don't know whats wrong there, I hope somebody can help us.
Thread Status:
Not open for further replies.

Share This Page