AdvancedAFK - API

How can I get if a player is AFK from my plugin

Nothing easier then that :P
Import my plugin jar as library and use this code in your plugin:

This goes beneath "public class YourPluginName":

public static boolean useAdvancedAfk = false;

This goes into your "onEnable" method:

It will set "useAdvancedAfk" to true if AdvancedAfk is installed

try{
  if(advancedafk.AFK_API.isInstalled()){
	//AdvancedAFK is installed
	//here you can set a boolean to true which then
	//tells other code to use "isAfk()"
	Bukkit.getServer().getLogger().info("AdvancedAFK hooked!!!");
	useAdvancedAfk = true;
  }
}catch(NoClassDefFoundError nCDFE){
	//AdvancedAFK is NOT installed/NOT found or wrong version
	//Here you can set a boolean to false which then
	//tells other code to NOT use "isAfk()"
	Bukkit.getServer().getLogger().info("AdvancedAFK not installed");
	useAdvancedAfk = false;
}

Or you can use this:

if(getServer().getPluginManager().isPluginEnabled("Advanced AFK")){
	Bukkit.getServer().getLogger().info("AdvancedAFK hooked!!!");
	useAdvancedAfk = true;
}else{
	Bukkit.getServer().getLogger().info("AdvancedAFK not installed");
	useAdvancedAfk = false;
}

This goes where you wanna check if a player is AFK:

if(useAdvancedAfk && advancedafk.AFK_API.isAfk(player)){
	player.sendMessage("You are afk !!");
}else{
	//AdvancedAfk not installed/Player is NOT AFK
}

Comments

Posts Quoted:
Reply
Clear All Quotes