Skip to content

Commit

Permalink
Add action bar methods to SkillsUser API
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Jul 1, 2024
1 parent 4e36188 commit b3038b0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
26 changes: 26 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 @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public interface SkillsUser {

Expand Down Expand Up @@ -301,4 +302,29 @@ public interface SkillsUser {
*/
int getJobLimit();

/**
* Sends an action bar to the user and pauses other AuraSkills action bars for the default duration (750ms or 15 ticks).
*
* @param message the message to send
*/
void sendActionBar(String message);

/**
* Sends an action bar to the user and pauses other AuraSkills action bars for the specified duration.
*
* @param message the action bar message
* @param duration the duration
* @param timeUnit the time unit of the duration
*/
void sendActionBar(String message, int duration, TimeUnit timeUnit);

/**
* Pauses AuraSkills action bars for a certain duration. While idle and xp action bars will be paused, others like ability
* messages may still be sent.
*
* @param duration the duration to pause
* @param timeUnit the time unit of the duration
*/
void pauseActionBar(int duration, TimeUnit timeUnit);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import dev.aurelium.auraskills.api.trait.TraitModifier;
import dev.aurelium.auraskills.api.user.SkillsUser;
import dev.aurelium.auraskills.common.AuraSkillsPlugin;
import dev.aurelium.auraskills.common.ui.ActionBarManager;
import dev.aurelium.auraskills.common.user.User;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class ApiSkillsUser implements SkillsUser {

Expand Down Expand Up @@ -221,4 +223,21 @@ public int getJobLimit() {
return user.getJobLimit();
}

@Override
public void sendActionBar(String message) {
plugin.getUiProvider().sendActionBar(user, message);
plugin.getUiProvider().getActionBarManager().setPaused(user, ActionBarManager.PAUSE_MS, TimeUnit.MILLISECONDS);
}

@Override
public void sendActionBar(String message, int duration, TimeUnit timeUnit) {
plugin.getUiProvider().sendActionBar(user, message);
plugin.getUiProvider().getActionBarManager().setPaused(user, duration, timeUnit);
}

@Override
public void pauseActionBar(int duration, TimeUnit timeUnit) {
plugin.getUiProvider().getActionBarManager().setPaused(user, duration, timeUnit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public abstract class ActionBarManager {

public static final int PAUSE_MS = 750;
protected final AuraSkillsPlugin plugin;
private final UiProvider uiProvider;

Expand Down Expand Up @@ -239,7 +240,7 @@ public void sendAbilityActionBar(User user, String message) {
}

plugin.getUiProvider().sendActionBar(user, actionBarText);
setPaused(user, 15 * 50, TimeUnit.MILLISECONDS);
setPaused(user, PAUSE_MS, TimeUnit.MILLISECONDS);
}

private String getXpActionBarMessage(User user, Skill skill, double currentXp, double levelXp, double xpGained, int level, boolean maxed, double income) {
Expand Down

0 comments on commit b3038b0

Please sign in to comment.