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

Developers

Pyves edited this page Oct 26, 2017 · 31 revisions

Setting your own working copy of the project

Ensure you have a working version of the JDK (Java Development Kit).

The following steps are for the Eclipse development environment, but will be similar on other IDEs.

  • Fork the repository by clicking on the Fork icon on the top right of the page. You can also simply clone or download it by going to the main page.
  • In Eclipse, go to File -> Import... -> Maven -> Existing Maven Projects.
  • In the Root Directory field, select the location where you downloaded the Advanced Achievements repository.
  • Tick the pom.xml box that appears in the Projects field and click Finish.
  • To compile the plugin, in the Package Explorer window, right click on the imported project, then Run As -> Maven Install.
  • The plugin will be generated in the target folder of the project.

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.
  • Add Advanced Achievements as a dependency or soft-dependency in your plugin.yml:
# Make Advanced Achievements compulsory:
depend: [AdvancedAchievements]
# Or make Advanced Achievements optional:
softdepend: [AdvancedAchievements]

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!

  • Define a new category by adding a value to the NormalAchievements.java enum in the com.hm.achievement.category package. For instance:
// CATEGORYCODENAME("CategoryNameInConfigs", "category-language-parameter-for-gui", "Default Name in GUI", "Comments in config.yml."),
ARROWS("Arrows", "list-arrows", "Arrows Shot", "When an arrow is shot."),
  • 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 item 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) {
		...
	}
}
  • Make sure you add some code to verify that Advanced Achievements is running with a minimum version of 5.0, and register the listener to your plugin. For instance in your main plugin class:
...
if (Bukkit.getPluginManager().isPluginEnabled("AdvancedAchievements")) {
    Plugin pluginInstance = Bukkit.getPluginManager().getPlugin("AdvancedAchievements");
    // Check whether the running version contains the PlayerAdvancedAchievementEvent class.
    if (Integer.parseInt(Character.toString(pluginInstance.getDescription().getVersion().charAt(0))) >= 5) {
        getServer().getPluginManager().registerEvents(new PlayerAdvancedAchievementListener(), this);
    }
}
...
  • Add Advanced Achievements as a dependency or soft-dependency in your plugin.yml:
# Make Advanced Achievements compulsory:
depend: [AdvancedAchievements]
# Or make Advanced Achievements optional:
softdepend: [AdvancedAchievements]
  • Congratulations, your listener code will be run each time a player receives an achievement!
Clone this wiki locally