Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Developers

Pyves edited this page Mar 30, 2017 · 31 revisions

Using the API

  • Download the latest version of Advanced Achievements from Bukkit or Spigot.
  • Add the file to the build path of your project.
  • Add a piece of code similar to the following in your project:
import com.hm.achievement.api.AdvancedAchievementsAPI;
import com.hm.achievement.api.AdvancedAchievementsBukkitAPI;
...

if (Bukkit.getPluginManager().isPluginEnabled("AdvancedAchievements")) {
    Plugin pluginInstance = Bukkit.getPluginManager().getPlugin("AdvancedAchievements");
    // Check whether the running version contains the API classes.
    if (Integer.parseInt(Character.toString(pluginInstance.getDescription().getVersion().charAt(0))) >= 5) {
        AdvancedAchievementsAPI advancedAchievementsAPI = AdvancedAchievementsBukkitAPI.linkAdvancedAchievements();
        advancedAchievementsAPI. ...
    }
}
...
  • Use your AdvancedAchievementsAPI object as you wish! The interface with commented method signatures is available here.

Implementing new categories

Adding simple categories is rather straightforward and does not require advanced Java knowledge: it's mostly a matter of following the code that's already written!

  • Fork the repository by following the instructions given on the home page.
  • Define a new category by adding a value to the NormalAchievements.java enum in the com.hm.achievement.category package.
  • Add a new listener class to the com.hm.achievement.listener package. AchieveDropListener.java is a very simple example you can use as a reference.
  • Add a new field corresponding to your listener class in AdvancedAchievements.java. Register your listener in the registerListeners() method. Simply follow the existing code.
  • Add a new default permission value in plugin.yml (achievement.count. followed by the category name in lower case). This file is situated in the resources folder.
  • Add a new default GUI object in gui.yml. This file is situated in the resources folder.
  • Add your achievements for this new category in config.yml. You're done!

If you're happy with what you've done, why not contribute and open a pull request?


Listening to achievement events

In your own plugin project, you might want to be notified when a player receives an achievement. That's simple!

  • Download the latest version of Advanced Achievements from Bukkit or Spigot.
  • Add the file to the build path of your project.
  • Add a new class similar to the following in your project:
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.hm.achievement.utils.PlayerAdvancedAchievementEvent;
...

public class PlayerAdvancedAchievementListener implements Listener {

	...

	@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
	public void onPlayerAdvancedAchievementReception(PlayerAdvancedAchievementEvent event) {
		...
	}
}
  • Register this listener to your plugin. For instance in your main plugin class:
getServer().getPluginManager().registerEvents(new PlayerAdvancedAchievementListener(), this);
Clone this wiki locally