Skip to content

Commit

Permalink
Add custom content API
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Nov 5, 2023
1 parent 24ae16a commit 273e0bb
Show file tree
Hide file tree
Showing 41 changed files with 1,249 additions and 211 deletions.
17 changes: 17 additions & 0 deletions api/src/main/java/dev/aurelium/auraskills/api/AuraSkillsApi.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.aurelium.auraskills.api;

import dev.aurelium.auraskills.api.message.MessageManager;
import dev.aurelium.auraskills.api.registry.NamespacedRegistry;
import dev.aurelium.auraskills.api.skill.XpRequirements;
import dev.aurelium.auraskills.api.user.UserManager;

import java.io.File;

public interface AuraSkillsApi {

/**
Expand All @@ -29,6 +32,20 @@ public interface AuraSkillsApi {
*/
XpRequirements getXpRequirements();

/**
* Gets the {@link NamespacedRegistry} for the given namespace and content directory,
* which is used to register custom skills, stats, abilities, etc.
*
* @param namespace The name of the plugin this is being called by to uniquely identify custom content.
* The namespace will be forced to lowercase. Referencing custom content in config files is done
* by appending "namespace/" to the name of the content.
* @param contentDirectory The directory where configuration files for custom content will be loaded from.
* For Bukkit, pass in JavaPlugin#getDataFolder to use the plugin's config folder.
* @return the namespaced registry to register custom content
* @throws IllegalArgumentException if the namespace is "auraskills", which is not allowed
*/
NamespacedRegistry getRegistry(String namespace, File contentDirectory);

/**
* Gets the instance of the {@link AuraSkillsApi},
* throwing {@link IllegalStateException} if the API is not loaded yet.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package dev.aurelium.auraskills.api.ability;

import dev.aurelium.auraskills.api.annotation.Inject;
import dev.aurelium.auraskills.api.registry.NamespacedId;
import dev.aurelium.auraskills.api.registry.NamespacedRegistry;
import dev.aurelium.auraskills.api.skill.Skill;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Locale;
import java.util.Map;

public class CustomAbility implements Ability {

@Inject
private AbilityProvider provider;

private final NamespacedId id;
private final boolean hasSecondaryValue;
@Nullable
private final String displayName;
@Nullable
private final String description;
@Nullable
private final String info;

private CustomAbility(NamespacedId id, boolean hasSecondaryValue, @Nullable String displayName, @Nullable String description, @Nullable String info) {
this.id = id;
this.hasSecondaryValue = hasSecondaryValue;
this.displayName = displayName;
this.description = description;
this.info = info;
}

public static CustomAbilityBuilder builder(NamespacedRegistry registry, String name) {
return new CustomAbilityBuilder(NamespacedId.from(registry.getNamespace(), name));
}

@Override
public String getDisplayName(Locale locale) {
return displayName != null ? displayName : provider.getDisplayName(this, locale);
}

@Override
public String getDescription(Locale locale) {
return description != null ? description : provider.getDescription(this, locale);
}

@Override
public String getInfo(Locale locale) {
return info != null ? info : provider.getInfo(this, locale);
}

@Override
public String name() {
return id.getKey().toUpperCase(Locale.ROOT);
}

@Override
public boolean hasSecondaryValue() {
return hasSecondaryValue;
}

@Override
public boolean isEnabled() {
return provider.isEnabled(this);
}

@Override
public double getBaseValue() {
return provider.getBaseValue(this);
}

@Override
public double getSecondaryBaseValue() {
return provider.getSecondaryBaseValue(this);
}

@Override
public double getValue(int level) {
return provider.getValue(this, level);
}

@Override
public double getValuePerLevel() {
return provider.getValuePerLevel(this);
}

@Override
public double getSecondaryValuePerLevel() {
return provider.getSecondaryValuePerLevel(this);
}

@Override
public double getSecondaryValue(int level) {
return provider.getSecondaryValue(this, level);
}

@Override
public Skill getSkill() {
return provider.getSkill(this);
}

@Override
public NamespacedId getId() {
return id;
}

@Override
public int getMaxLevel() {
return provider.getMaxLevel(this);
}

@Override
public int getUnlock() {
return provider.getUnlock(this);
}

@Override
public int getLevelUp() {
return provider.getLevelUp(this);
}

@Override
public boolean optionBoolean(String key) {
return provider.optionBoolean(this, key);
}

@Override
public boolean optionBoolean(String key, boolean def) {
return provider.optionBoolean(this, key, def);
}

@Override
public int optionInt(String key) {
return provider.optionInt(this, key);
}

@Override
public int optionInt(String key, int def) {
return provider.optionInt(this, key, def);
}

@Override
public double optionDouble(String key) {
return provider.optionDouble(this, key);
}

@Override
public double optionDouble(String key, double def) {
return provider.optionDouble(this, key, def);
}

@Override
public String optionString(String key) {
return provider.optionString(this, key);
}

@Override
public String optionString(String key, String def) {
return provider.optionString(this, key, def);
}

@Override
public List<String> optionStringList(String key) {
return provider.optionStringList(this, key);
}

@Override
public Map<String, Object> optionMap(String key) {
return provider.optionMap(this, key);
}

public static class CustomAbilityBuilder {

private final NamespacedId id;
private boolean hasSecondaryValue;
private String displayName;
private String description;
private String info;

public CustomAbilityBuilder(NamespacedId id) {
this.id = id;
}

public CustomAbilityBuilder hasSecondaryValue(boolean hasSecondaryValue) {
this.hasSecondaryValue = hasSecondaryValue;
return this;
}

public CustomAbilityBuilder displayName(String displayName) {
this.displayName = displayName;
return this;
}

public CustomAbilityBuilder description(String description) {
this.description = description;
return this;
}

public CustomAbilityBuilder info(String info) {
this.info = info;
return this;
}

public CustomAbility build() {
return new CustomAbility(id, hasSecondaryValue, displayName, description, info);
}

}

}
Loading

0 comments on commit 273e0bb

Please sign in to comment.