Skip to content

Commit

Permalink
Add jobs commands and placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed May 17, 2024
1 parent 69f0d29 commit 2f6bf23
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void registerBaseCommands(PaperCommandManager manager) {
manager.registerCommand(new OpenMenuCommand(plugin));
manager.registerCommand(new ManaAbilityCommand(plugin));
manager.registerCommand(new TraitCommand(plugin));
manager.registerCommand(new JobsCommand(plugin));
}

public void registerSkillCommands(PaperCommandManager manager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package dev.aurelium.auraskills.bukkit.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.annotation.*;
import dev.aurelium.auraskills.api.skill.Skill;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.common.message.MessageBuilder;
import dev.aurelium.auraskills.common.message.type.ACFCoreMessage;
import dev.aurelium.auraskills.common.message.type.CommandMessage;
import dev.aurelium.auraskills.common.user.User;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.Locale;

@CommandAlias("%skills_alias")
@Subcommand("jobs")
public class JobsCommand extends BaseCommand {

private final AuraSkills plugin;

public JobsCommand(AuraSkills plugin) {
this.plugin = plugin;
}

@Subcommand("add")
@CommandCompletion("@skills @players")
@CommandPermission("auraskills.command.jobs")
public void onAddOther(CommandIssuer issuer, Skill job, @Flags("other") @CommandPermission("auraskills.command.jobs.other") @Optional User user) {
Locale locale = plugin.getLocale(issuer);
if (user == null) {
if (issuer.isPlayer()) {
Player player = issuer.getIssuer();
addJobToPlayer(plugin.getUser(player), job, locale, issuer);
} else {
issuer.sendMessage(plugin.getMsg(ACFCoreMessage.NOT_ALLOWED_ON_CONSOLE, locale));
}
} else {
addJobToPlayer(user, job, locale, issuer);
}
}

private void addJobToPlayer(User user, Skill job, Locale locale, CommandIssuer issuer) {
if (user.getJobs().size() < user.getJobLimit()) {
if (!user.getJobs().contains(job)) {
user.addJob(job);
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_ADD_ADDED, "player", user.getUsername(),
"job", job.getDisplayName(locale) + ChatColor.RESET)
.send(issuer);
} else {
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_ADD_EXISTING, "player", user.getUsername(),
"job", job.getDisplayName(locale) + ChatColor.RESET)
.send(issuer);
}
} else {
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_ADD_LIMITED, "player", user.getUsername())
.send(issuer);
}
}

@Subcommand("remove")
@CommandCompletion("@skills @players")
@CommandPermission("auraskills.command.jobs")
public void onRemove(CommandIssuer issuer, Skill job, @Flags("other") @CommandPermission("auraskills.command.jobs.other") @Optional User user) {
Locale locale = plugin.getLocale(issuer);
if (user == null) {
if (issuer.isPlayer()) {
Player player = issuer.getIssuer();
removeJobFromPlayer(plugin.getUser(player), job, locale, issuer);
} else {
issuer.sendMessage(plugin.getMsg(ACFCoreMessage.NOT_ALLOWED_ON_CONSOLE, locale));
}
} else {
removeJobFromPlayer(user, job, locale, issuer);
}
}

private void removeJobFromPlayer(User user, Skill job, Locale locale, CommandIssuer issuer) {
if (user.getJobs().contains(job)) {
user.removeJob(job);
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_REMOVE_REMOVED, "player", user.getUsername(),
"job", job.getDisplayName(locale) + ChatColor.RESET)
.send(issuer);
} else {
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_REMOVE_UNCHANGED, "player", user.getUsername(),
"job", job.getDisplayName(locale) + ChatColor.RESET)
.send(issuer);
}
}

@Subcommand("removeall")
@CommandCompletion("@players")
@CommandPermission("auraskills.command.jobs")
public void onRemoveAll(CommandIssuer issuer, @Flags("other") @CommandPermission("auraskills.command.jobs.other") @Optional User user) {
Locale locale = plugin.getLocale(issuer);
if (user == null) {
if (issuer.isPlayer()) {
Player player = issuer.getIssuer();
removeAllJobs(plugin.getUser(player), locale, issuer);
}
} else {
removeAllJobs(user, locale, issuer);
}
}

private void removeAllJobs(User user, Locale locale, CommandIssuer issuer) {
user.clearAllJobs();
MessageBuilder.create(plugin).locale(locale).prefix()
.message(CommandMessage.JOBS_REMOVEALL_REMOVED, "player", user.getUsername())
.send(issuer);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dev.aurelium.auraskills.common.util.text.TextUtil;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -309,6 +310,22 @@ public String onPlaceholderRequest(Player player, String identifier) {
}
}

if (identifier.startsWith("jobs_")) {
User user = plugin.getUser(player);
switch (identifier) {
case "jobs_list":
return String.join(",", user.getJobs().stream().map(s -> s.getId().getKey()).toList());
case "jobs_list_formatted":
return String.join(ChatColor.RESET + ", ", user.getJobs().stream()
.map(s -> s.getDisplayName(plugin.getDefaultLanguage()))
.toList());
case "jobs_count":
return String.valueOf(user.getJobs().size());
case "jobs_limit":
return String.valueOf(user.getJobLimit());
}
}

return null;
}

Expand Down Expand Up @@ -433,7 +450,11 @@ private String checkLeaderboardPlaceholders(String identifier) {
"%auraskills_multiplier_[skill]%",
"%auraskills_multiplier_percent%",
"%auraskills_multiplier_percent_[skill]%",
"%auraskills_actionbar_status%"
"%auraskills_actionbar_status%",
"%auraskills_jobs_list",
"%auraskills_jobs_list_formatted",
"%auraskills_jobs_count",
"%auraskills_jobs_limit"
);
}
}
4 changes: 4 additions & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ permissions:
default: op
auraskills.command.manaability.resetcooldown:
default: op
auraskills.command.jobs:
default: op
auraskills.command.jobs.other:
default: op
auraskills.multiplier:
default: false
auraskills.skill.farming:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public enum Command {
ITEM_REQUIREMENT_LIST,
ITEM_REQUIREMENT_REMOVEALL,
ITEM_UNREGISTER,
JOBS_ADD,
JOBS_REMOVE,
JOBS_REMOVEALL,
LANG,
MANA,
MODIFIER_ADD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public enum CommandMessage implements MessageKey {
ITEM_UNREGISTER_NOT_REGISTERED(Command.ITEM_UNREGISTER, "not_registered"),
ITEM_IGNORE_ADD,
ITEM_IGNORE_REMOVE,
JOBS_ADD_ADDED,
JOBS_ADD_LIMITED,
JOBS_ADD_EXISTING,
JOBS_REMOVE_REMOVED,
JOBS_REMOVE_UNCHANGED,
JOBS_REMOVEALL_REMOVED,
LANG_SET,
LANG_NOT_FOUND(Command.LANG, "not_found"),
MANA_DISPLAY,
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/messages/messages_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,16 @@ commands:
ignore:
add: "<gray>Your item will now be ignored by mana ability interactions"
remove: "<gray>Your item will no longer be ignored by mana ability interactions"
jobs:
add:
added: "<white>The job {job} was successfully added to player {player}"
limited: "<yellow>Cannot add this job because player {player} has reached the job limit"
existing: "<yellow>Player {player} already has the job {job}"
remove:
removed: "<white>Removed job {job} from player {player}"
unchanged: "<yellow>Nothing was changed since player {player} does not have the job {job}"
removeall:
removed: "<white>Removed all jobs from player {player}"
lang:
set: "<gray>Language set to <aqua>{lang}"
not_found: "<yellow>Language not found!"
Expand Down

0 comments on commit 2f6bf23

Please sign in to comment.