Plugin integration with Essentials AFK

Discussion in 'Plugin Development' started by Edge209, May 16, 2012.

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

    Edge209

    I'd like to be able to integrate my plugin with Essentials AFK function. Ideally I'd like my plugin to get a notification when Essentials changes a players AFK status. If that is not possible having the ability for my plugin to check a players current AFK status may be sufficient.

    Can anyone tell me if there is a API to interact with Essentials AFK?

    Thanks.
     
  2. Offline

    Father Of Time

    There is an essentials API, but I don't know if it contains anything afk related as I've only used it for the economy api. Here is a link to the API source code for Essentials:

    https://github.com/essentials/Essentials/tree/master/Essentials/src/com/earth2me/essentials/api

    Do a little digging, see what pops up. :D

    edit: a little digging revealed that UserData contains the following function:

    Code:
    public boolean isAfk()
    {
        return afk;
    }
    And user data can be cast if you import the Essentials external library; so yes, it's possible.

    I hope this helps!
     
  3. Offline

    Edge209

    Thanks! This does help ... some. I'm still leaning plugin development and this is new territory for me. If I hack aound enough I'll eventually figure it out, but it would be a great help if there was an example I could look at which already interfacing via the Essentials API and casting the user data. Would you happen to have any suggestions on where I could find an example. I tried to search and find something but no luck.

    Thanks again.
     
  4. Offline

    Craftiii4

    If you import the api, then based on father of times comment. You should just be able to use if (player.isAfk() == true) {
     
  5. Offline

    Edge209

    Thanks, I'll give it a shot
     
  6. Offline

    Father Of Time

    No, I don't believe that will work because PlayerData is Essentials wrapper for Bukkit's Player class. You will need to look into how to cast a Bukkit Player object to a Essentials PlayerData (I've never done this, sorry I don't know).

    I would imagine Essentials itself has some function that returns this information if you pass it the player object, something like: (pseudo code)

    Code:
        private Essentials essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
        PlayerData pd = essentials.getPlayerData( playername );
        if( pd.idAfk() )
        {
            // is asleep
        }
        else
        {
            // is awake
        }
    Please note that this was written free hand and without looking up any of the information, so the Plugin class name of essentials is likely wrong, and you likely can't get the player data from the essentials main plugin class, but one of its managers, and also the name of the function that gets the playerdata object is likely not called "getPlayerData( playername )".

    This is all the understanding you will need to move forward, the rest is just a matter of researching the Essentials API to find what functions will give you what you want, and how to access those functions.

    I hope this helps give you a little more direction, good luck with your project!
     
  7. Offline

    Edge209

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page