you can look at a reference implementation
so the first thing you want to do is add SFA as a dependency
in your pom.xml
, add jitpack as a repository (if you haven't already) and add the SFA dependency
you should maybe use the latest commit
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.slimefun</groupId>
<artifactId>slimefun4</artifactId>
<version>RC-30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.qwertyuioplkjhgfd</groupId>
<artifactId>SlimefunAdvancements</artifactId>
<version>bb966ea180</version>
<scope>provided</scope>
</dependency>
</dependencies>
then in your plugin.yml
, add SFAdvancements
as a dependency
depend: [ Slimefun, SFAdvancements ]
Create a class that extends me.char321.sfadvancements.api.criteria.Criterion
Add a constructor that calls a super constructor.
Choose one that accepts a name parameter please
Amount defaults to one, it's the number of times the criterion needs to be performed by a player to complete it.
You can then add any extra parameters, fields, and getters that you want your criterion requirements to hold.
Criterion objects are per yml object as defined in advancements.yml
Then you want to have a CriterionCompleter that completes your criterion type.
Create a class that implements me.char321.sfadvancements.core.criteria.completer.CriterionCompleter
getCriterionClass()
should return the class of the criterion you just created.
register(Criterion)
is called whenever a criterion is loaded of type getCriterionClass()
,
so store the incoming criteria in a collection or map or something.
This is where you would complete your criteria.
You can add a listener or just a method that is called elsewhere whenever someone performs your criteria.
Then, just call Criterion#perform(Player p)
, and that will increment the player's progress for that criteria (and complete it if it was completed).
To register your completer, just create a new instance and call register()
(without any parameters).
To register your criteria type (and make it configurable), call CriteriaTypes.putType(String, Function<ConfigurationSection, Criterion>)
.
The string is the type of criteria that is specified in advancements.yml
:
myadvancement:
...
criteria:
mycriterion:
name: ...
type: <this string>
...
The function is what turns a configuration section to a criterion object.
It refers to the mycriterion
section in the example above.
This way, you can customize how your criterion is configured.
The function will likely look something like this:
config -> {
String id = config.getName();
// optional
int amount = config.getInt("amount");
if (amount == 0) { // if no amount is specified
amount = 1;
}
// boilerplate
String name = config.getString("name");
if(name == null) {
name = id;
}
// this is where you can add custom configurability
double chance = config.getDouble("chance");
// if you want to get itemstacks, you can use ConfigUtils.getItem(config, path)
// return a criterion from the config
return new RandomCriterion(id, amount, name, chance);
}
Adding your own advancements are very simple.
Simply include files called sfgroups.yml
and sfadvancements.yml
which define your custom groups and advancements, respectively.
It is recommended that any groups you use in sfadvancements.yml
are defined in sfgroups.yml
, because if the group does not exist, the advancement will not appear.
Now, to add these advancements , just type /sfa import <plugin name>
, and they should be imported!
(Any groups and advancements that have the same key as an existing group/advancement will not be imported.)
And that's it!
Once again, you can always look at a reference implementation.
If you're still confused, feel free to ask in the Slimefun Addon Community discord server.