Skip to content

Commit

Permalink
Add new SkillsUser methods to API
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Jan 13, 2024
1 parent 28e23f1 commit 1f52b39
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.aurelium.auraskills.api;

import dev.aurelium.auraskills.api.item.ItemManager;
import dev.aurelium.auraskills.api.region.Regions;

public interface AuraSkillsBukkit {
Expand All @@ -11,6 +12,13 @@ public interface AuraSkillsBukkit {
*/
Regions getRegions();

/**
* Gets the item manager used to add modifiers, multipliers, and requirements to items.
*
* @return the item manager
*/
ItemManager getItemManager();

/**
* Gets the instance of the {@link AuraSkillsBukkit} API,
* throwing {@link IllegalStateException} if the API is not loaded yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public interface AuraSkillsApi {
*/
Handlers getHandlers();

<T> T getItemManager(Class<T> itemManagerClass);

/**
* Gets the instance of the {@link AuraSkillsApi},
* throwing {@link IllegalStateException} if the API is not loaded yet.
Expand Down
42 changes: 42 additions & 0 deletions api/src/main/java/dev/aurelium/auraskills/api/user/SkillsUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import dev.aurelium.auraskills.api.skill.Skill;
import dev.aurelium.auraskills.api.stat.Stat;
import dev.aurelium.auraskills.api.stat.StatModifier;
import dev.aurelium.auraskills.api.trait.Trait;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.Map;
import java.util.UUID;

public interface SkillsUser {
Expand Down Expand Up @@ -77,6 +80,13 @@ public interface SkillsUser {
*/
void setSkillLevel(Skill skill, int level);

/**
* Gets the user's average skill level of all enabled skills.
*
* @return the skill average
*/
double getSkillAverage();

/**
* Gets the level of a stat.
*
Expand Down Expand Up @@ -137,6 +147,38 @@ public interface SkillsUser {
*/
void removeStatModifier(String name);

/**
* Gets a stat modifier from its name.
*
* @param name the name of the modifier
* @return the stat modifier, or null if none exists with the name.
*/
@Nullable
StatModifier getStatModifier(String name);

/**
* Gets a map of all the user's stat modifiers.
*
* @return the map of all stat modifiers
*/
Map<String, StatModifier> getStatModifiers();

/**
* Gets the total level of a trait, including non-plugin base values.
*
* @param trait the trait to get the level of
* @return the total effective level
*/
double getEffectiveTraitLevel(Trait trait);

/**
* Gets the level of a trait from only the plugin's stats and trait modifiers.
*
* @param trait the trait to get the level of
* @return the bonus trait level
*/
double getBonusTraitLevel(Trait trait);

/**
* Gets the level of an ability.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ public int getResourceId() {
return 81069;
}

public AuraSkillsBukkit getApiBukkit() {
return apiBukkit;
}

@Override
public AuraSkillsApi getApi() {
return api;
Expand Down Expand Up @@ -550,12 +554,8 @@ public EventHandler getEventHandler() {
return eventHandler;
}

@Override
public <T> T getItemManager(Class<T> itemManagerClass) {
if (itemManagerClass.equals(ItemManager.class)) {
return itemManagerClass.cast(itemManager);
}
throw new IllegalArgumentException("Invalid itemManagerClass");
public ItemManager getItemManager() {
return itemManager;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package dev.aurelium.auraskills.bukkit.api;

import dev.aurelium.auraskills.api.AuraSkillsBukkit;
import dev.aurelium.auraskills.api.item.ItemManager;
import dev.aurelium.auraskills.api.region.Regions;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.api.implementation.ApiRegions;

public class ApiAuraSkillsBukkit implements AuraSkillsBukkit {

private final ApiRegions blockTracker;
private final ItemManager itemManager;

public ApiAuraSkillsBukkit(AuraSkills plugin) {
this.blockTracker = new ApiRegions(plugin);
this.itemManager = plugin.getItemManager();
}

@Override
public Regions getRegions() {
return blockTracker;
}

@Override
public ItemManager getItemManager() {
return itemManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public interface AuraSkillsPlugin {

EventHandler getEventHandler();

<T> T getItemManager(Class<T> itemManagerClass);

// Message convenience methods

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,4 @@ public Handlers getHandlers() {
return handlers;
}

@Override
public <T> T getItemManager(Class<T> itemManagerClass) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

import dev.aurelium.auraskills.api.ability.Ability;
import dev.aurelium.auraskills.api.mana.ManaAbility;
import dev.aurelium.auraskills.api.trait.Trait;
import dev.aurelium.auraskills.api.user.SkillsUser;
import dev.aurelium.auraskills.api.skill.Skill;
import dev.aurelium.auraskills.api.stat.Stat;
import dev.aurelium.auraskills.api.stat.StatModifier;
import dev.aurelium.auraskills.common.AuraSkillsPlugin;
import dev.aurelium.auraskills.common.user.User;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.Map;
import java.util.UUID;

public class ApiSkillsUser implements SkillsUser {
Expand Down Expand Up @@ -69,6 +72,11 @@ public void setSkillLevel(Skill skill, int level) {
user.setSkillLevel(skill, level);
}

@Override
public double getSkillAverage() {
return user.getSkillAverage();
}

@Override
public double getStatLevel(Stat stat) {
return user.getStatLevel(stat);
Expand Down Expand Up @@ -109,6 +117,26 @@ public void removeStatModifier(String name) {
user.removeStatModifier(name);
}

@Override
public @Nullable StatModifier getStatModifier(String name) {
return user.getStatModifier(name);
}

@Override
public Map<String, StatModifier> getStatModifiers() {
return user.getStatModifiers();
}

@Override
public double getEffectiveTraitLevel(Trait trait) {
return user.getEffectiveTraitLevel(trait);
}

@Override
public double getBonusTraitLevel(Trait trait) {
return user.getBonusTraitLevel(trait);
}

@Override
public int getAbilityLevel(Ability ability) {
return user.getAbilityLevel(ability);
Expand Down

0 comments on commit 1f52b39

Please sign in to comment.