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

Adding new categories

Pierre-Yves B edited this page Oct 14, 2021 · 6 revisions

Adding simple categories directly in Advanced Achievements is really easy and does not require advanced Java knowledge: it's mostly a matter of following the code that's already written! Let's take the example of the Eggs achievement category and see how it's built.

  • In NormalAchievements.java, there is an entry declaring the achievement category:
    EGGS("Eggs"),
  • There is a file EggsListener.java which keeps track of statistic increases for that category. Some highlights:
    • an import statement is defined for the PlayerEggThrowEvent on line 10: import org.bukkit.event.player.PlayerEggThrowEvent;
    • the achievement declaration from NormalAchievements.java is specified on line 28: super(NormalAchievements.EGGS, ...
    • the aforementioned Bukkit event is used on line 32: ... onPlayerEggThrow(PlayerEggThrowEvent event) ...
    • all the rest of the code in the file will be common for most other achievement categories.
  • In ReloadableModule.java, a few lines of code make sure that the category is properly configured when the plugin starts up:
    @Binds
    @IntoSet
    abstract Reloadable bindEggsListener(EggsListener eggsListener);
    
    Note the statement on line 28: import com.hm.achievement.listener.statistics.EggsListener;
  • Default permissions are configured in plugin.yml:
    • on lines 197 to 199, the permission for the Eggs category is defined:
      achievement.count.eggs:
        description: Allows egg statistics in database to increase.
        default: true
      
    • on line 107, achievement.count.eggs: true ensures that any player who has parent permission achievement.count.* will also have the eggs one.
  • The default category name displayed in the GUI is defined in lang.yml on line 160: list-eggs: "Eggs Thrown"
  • The default category item displayed in the GUI is defined in gui.yml on lines 68 and 69:
    Eggs:
      Item: egg
    
    All material names defined here can be used for the item.

That's all! If you've created a new category and happy with your work, why not contribute and open a pull request?