Getting information from other plugins? [SOLVED]

Discussion in 'Plugin Development' started by kabbage, Feb 25, 2012.

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

    kabbage

    Right now, I'm trying to get the groups a player is in from PermissionsBukkit. Here's how I tried to do this.
    Code:
    import java.util.List;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import com.platymuus.bukkit.permissions.Group;
    import com.platymuus.bukkit.permissions.PermissionsPlugin;
    public class RankTeleportListener implements Listener {
    private PermissionsPlugin plugin;
     
    public void registerEvents(PluginManager pm) {
        pm.registerEvents(this, plugin);
    }
     
    @EventHandler
    public void onPlayerJoin (PlayerJoinEvent event) {
        List<Group> groups = plugin.getPlayerInfo(event.getPlayer().getName()).getGroups();
     
    }
    However, this creates an Event Exception whenever I run it. I know I've got the actual event set up correctly, as everything works fine if I put something else in the OnPlayerJoin listener, but when I try to do anything from the permissions plugin, I get errors.
     
  2. Offline

    Njol

    Look at the stack trace, there's more than just one exception in it.
     
  3. Offline

    kabbage

    There's also an InvocationTargetException and a NullPointerException.
    Edit: These exceptions are all coming up when a player joins, not when the server starts.
     
  4. well you don't set the plugin variable to a value only declaring it. (If the code didn't changed.)
     
  5. Offline

    Njol

    You should be able to figure out the problem by yourself with the stack trace.
    If you're unable to do so, post the stack trace and where the two exceptions originated from (i.e. the files mentioned in the lines directly below the exceptions, and please mark the lines at which the exceptions occurred)

    edit: well that one was easy but I couldn't see it :rolleyes:
     
  6. Offline

    kabbage

    I can't figure out the problem from the stack trace, as I have no idea how to reference other plugins in the first place. I'm not really asking how to solve the error, I'm asking for someone to explain how to get information from other plugins. (Such as calling the method, getPlayerInfo() from PermissionsBukkit)
     
  7. Offline

    Njol

    Put this in your plugin's onEnable():
    Code:java
    1. Plugin p = Bukkit.getPluginManager().getPlugin("PermissionsBukkit")
    2. if (p == null || !(p instanceof PermissionsPlugin)) {
    3. Bukkit.getlogger().info("PermissionBukkit not found");
    4. } else {
    5. permissions = (PermissionsPlugin) p;
    6. }

    where permissions is a static field, i.e. "static PermissionsPlugin permissions = null".
    Remember that everytime you want to check groups you have to check whether permissions is not null first.
    Don't forget to add PermissionsBukkit as dependency to your plugin.yml (i.e. add the line "softdepend: [PermissionsBukkit]")

    PS: If you want your plugin to fully depend on PermissionsBukkit use "depend: [PermissionsBukkit]" instead of softdepend in the plugin.yml. In this case if PermissionBukkit is not present on the server your plugin won't load at all.
     
    kabbage likes this.
  8. Offline

    kabbage

    Alright, perfect. Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page