API - CryptoMorin/SkillsPro GitHub Wiki
SkillsPro API is quite stable and easy to learn. Anyone with basic Java knowledge can use the API.
The API will definitely change if needed without hesitation, so some plugins might break after API updates.
Currently, SkillsPro doesn't have a Maven repository. The best thing to do is to just import the JAR directly.
Don't forget to add SkillsPro
to your plugin.yml
-> softdepend
All the objects have optimized equals
and hashCode
methods that can be used. You can figure out most of the things you're looking for just by following your IDE's auto completions. Take a look at some examples at the end of the page.
90% of the API is thread-safe unless the method is dealing with Bukkit related operations.
Basics
Getting a player's data.
Player player = ...;
SkilledPlayer info = SkilledPlayer.getSkilledPlayer(player);
Updating player stats
Updates a player stats such as their health, max energy and etc...
HealthAndEnergyManager.updateStats(player);
Creating a new party
Player leader = ...;
SkillsParty party = SkillsParty.createParty(leader, name);
PvP Checks
This will check if they are in the same party or are friends.
SkilledPlayer info1 = ...;
SkilledPlayer info2 = ...;
boolean friendly = info1.isFrendly(info2);
Getting a skills item
ConfigurationSection section = SkillsPro.get().getConfig().getConfigurationSection("skills-items." + type);
if (section == null) return;
ItemStack item = XItemStack.deserialize(section);
item = ItemNBT.addSimpleTag(item, SkillItemManager.SKILL_ITEM, section.getString("skills-item-type"));
Events
Name | Description |
---|---|
SkillXPGainEvent |
Called when a player gets skills XP after killing. |
SkillSoulGainEvent |
Called when a player gets skills souls after killing. |
SkillLevelUpEvent |
Called when a player levels up after getting enough XP. SkilledPlayer#levelUp |
SkillToggleAbilityEvent |
Called when a player disables or enables an ability from /skills improve GUI. |
SkillEnergyChangeEvent |
Called when a player's energy changes. |
SkilLActiveStateChangeEvent |
Called when a player is ready to use an active skill. |
CustomHudChangeEvent |
Called when the ActionBar or Bossbar is updated. |
EidolonImbalanceChangeEvent |
Called when an Eidolon's energy is full and it's switching between light and dark form. |
Custom Skills & Abilities
Players can already make custom skills with different abilities by just adding a new file in the Skills
folder. There's no in-game feature to make custom abilities as most of the SkillsPro abilities are unique and cannot be made by normal editors.
You can still make a new skill from the code. The order of this is important.
Skill skill = new Skill(name);
YamlAdapter adapter = new YamlAdapter(new File(plugin.getDataFolder(), path), resourcePath).register();
skill.setAdapter(adapter);
SkillManager.registerScalings(skill);
SkillManager.register(skill);
Abilities
Before registering your skill, you have to register your abilities. There are two types of abilities:
Passive Abilities
These abilities activate themselves with events. Ability class has a method called checkup
You usually have to do this as the first thing in your event before doing anything else. This method will do several basic checks and return null if the player can't use this ability for whatever reason.
public class SwordsmanJigsaw extends Ability {
public SwordsmanJigsaw() {
super("Swordsman", "jigsaw");
}
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
Player player = event.getPlayer();
SkilledPlayer info = checkup(player);
if (info == null) return;
}
}
Active Abilities
These abilities only activate manually by the player. Instead of checkup
, you have to use activeCheckup
for these abilities.
There are two types of active abilities. Instant and non-instant. The 3rd argument in the ActiveAbility constructor determines whether this is an instant ability or not.
Non-Instant Active Abilities
They only activate after the player activated the ability using activation keys, and they hit an entity as the ability's target. The main event used for these abilities are EntityDamageByEntityEvent
public class SwordsmanJigsaw extends ActiveAbility {
public SwordsmanJigsaw() {
super("Swordsman", "jigsaw", false);
}
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
Player player = event.getPlayer();
SkilledPlayer info = activeCheckup(player);
if (info == null) return;
}
}
Instant Active Abilities
They activate immediately after the player used the activation keys. These abilities do not have a specific target. They'll be activated from a method called useSkill
that you have to override.
public class SwordsmanJigsaw extends ActiveAbility {
public SwordsmanJigsaw() {
super("Swordsman", "jigsaw", true);
}
@Override
public void useSkill(Player player) {
SkilledPlayer info = activeCheckup(player);
if (info == null) return;
}
}
Do not use scaling methods inside the ability's constructor for scheduled timers or anything else. Override this method instead:
@Override
public void start() {
addTask(new BukkitRunnable());
}
This will start the schedulers after the skill is registered. Note that You need to use addTask
to prevent memory leaks on reloads.
To set the title and the description of the ability, simply override these two methods.
A simple way to translate placeholders is to use ServiceHandler.translatePlaceholders()
@Override
public String getTitle(SkilledPlayer info) {
return name;
}
@Override
public String getDescription(SkilledPlayer info) {
return description;
}
If you want to translate a placeholder in the ability's description in /skill improve
you can also override a method called applyEdits
This method returns an array of objects with a pair-like structure. variable, replacement, variable2, replacement2, variable3, replacemenet3, ..., ...
@Override
public Object[] applyEdits(SkilledPlayer info) {
return new Object[]{"%chance%", getScalingDescription(info, getExtra(info, "chance").getString()), ..., ...};
}
To register an ability simply do:
AbilityManager.register(new MyAbility());