feat(commands): report aura progress
This commit is contained in:
@@ -2,6 +2,8 @@ package games.dmg.creeperfear;
|
||||
|
||||
import games.dmg.creeperfear.aura.AuraRules;
|
||||
import games.dmg.creeperfear.aura.CreeperAuraListener;
|
||||
import games.dmg.creeperfear.command.CreeperAuraCommand;
|
||||
import games.dmg.creeperfear.command.ProgressMessages;
|
||||
import games.dmg.creeperfear.feedback.ProgressDisplay;
|
||||
import games.dmg.creeperfear.feedback.ProgressFeedback;
|
||||
import games.dmg.creeperfear.listener.CreeperDeathListener;
|
||||
@@ -10,6 +12,7 @@ import games.dmg.creeperfear.listener.PlayerSessionListener;
|
||||
import games.dmg.creeperfear.progress.ProgressService;
|
||||
import games.dmg.creeperfear.progress.SqliteProgressRepository;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -34,6 +37,8 @@ public final class CreeperFearPlugin extends JavaPlugin {
|
||||
new PlayerSessionListener(progressService, getLogger()), this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new CreeperAuraListener(progressService, auraRules), this);
|
||||
Objects.requireNonNull(getCommand("creeperaura"), "creeperaura command")
|
||||
.setExecutor(new CreeperAuraCommand(this, progressService, new ProgressMessages(auraRules)));
|
||||
getServer().getOnlinePlayers().forEach(player -> progressService.loadOnline(player.getUniqueId())
|
||||
.exceptionally(failure -> {
|
||||
getLogger().log(Level.SEVERE,
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package games.dmg.creeperfear.command;
|
||||
|
||||
import games.dmg.creeperfear.progress.AuraRank;
|
||||
import games.dmg.creeperfear.progress.PlayerProgress;
|
||||
import games.dmg.creeperfear.progress.ProgressService;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class CreeperAuraCommand implements CommandExecutor {
|
||||
private final JavaPlugin plugin;
|
||||
private final ProgressService progressService;
|
||||
private final ProgressMessages messages;
|
||||
|
||||
public CreeperAuraCommand(JavaPlugin plugin, ProgressService progressService, ProgressMessages messages) {
|
||||
this.plugin = plugin;
|
||||
this.progressService = progressService;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1 || !args[0].equalsIgnoreCase("progress")) {
|
||||
return false;
|
||||
}
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This form of the command can only be used by a player.");
|
||||
return true;
|
||||
}
|
||||
|
||||
progressService.find(player.getUniqueId()).whenComplete((stored, failure) ->
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> {
|
||||
if (failure != null) {
|
||||
plugin.getLogger().log(Level.SEVERE,
|
||||
"Could not read Creeper Aura progress for " + player.getUniqueId(), failure);
|
||||
sender.sendMessage(ChatColor.RED + "Creeper Aura progress is temporarily unavailable.");
|
||||
return;
|
||||
}
|
||||
PlayerProgress progress = stored.orElseGet(() -> new PlayerProgress(
|
||||
player.getUniqueId(), player.getName(), AuraRank.LOCKED, 0));
|
||||
sender.sendMessage(ChatColor.GREEN + messages.describe(progress));
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package games.dmg.creeperfear.command;
|
||||
|
||||
import games.dmg.creeperfear.aura.AuraRules;
|
||||
import games.dmg.creeperfear.progress.AuraRank;
|
||||
import games.dmg.creeperfear.progress.PlayerProgress;
|
||||
|
||||
public final class ProgressMessages {
|
||||
private final AuraRules rules;
|
||||
|
||||
public ProgressMessages(AuraRules rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public String describe(PlayerProgress progress) {
|
||||
if (progress.rank().isMaximum()) {
|
||||
return "Creeper Aura VI — maximum rank reached; progression complete.";
|
||||
}
|
||||
int requirement = rules.requirementForCurrentRank(progress.rank());
|
||||
int remaining = Math.max(0, requirement - progress.tierKills());
|
||||
String rank = progress.rank() == AuraRank.LOCKED ? "Locked" : progress.rank().name();
|
||||
return "Creeper Aura " + rank + " — " + progress.tierKills() + "/" + requirement
|
||||
+ " current-tier kills; " + remaining + " remaining.";
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,12 @@ main: games.dmg.creeperfear.CreeperFearPlugin
|
||||
api-version: '26.2'
|
||||
author: dmg.games
|
||||
description: Unlock Creeper Aura ranks by defeating creepers.
|
||||
commands:
|
||||
creeperaura:
|
||||
description: Check and administer Creeper Aura progression.
|
||||
usage: /<command> progress
|
||||
permission: creeperfear.progress
|
||||
permissions:
|
||||
creeperfear.progress:
|
||||
description: Check personal Creeper Aura progression.
|
||||
default: true
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package games.dmg.creeperfear.command;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import games.dmg.creeperfear.aura.AuraRules;
|
||||
import games.dmg.creeperfear.progress.AuraRank;
|
||||
import games.dmg.creeperfear.progress.PlayerProgress;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ProgressMessagesTest {
|
||||
private final ProgressMessages messages = new ProgressMessages(AuraRules.defaults());
|
||||
|
||||
@Test
|
||||
void reportsCurrentTierAndRemainingKills() {
|
||||
PlayerProgress progress = new PlayerProgress(UUID.randomUUID(), "Player", AuraRank.II, 40);
|
||||
|
||||
assertEquals(
|
||||
"Creeper Aura II — 40/100 current-tier kills; 60 remaining.",
|
||||
messages.describe(progress));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportsCompletedProgressAtRankSix() {
|
||||
PlayerProgress progress = new PlayerProgress(UUID.randomUUID(), "Player", AuraRank.VI, 0);
|
||||
|
||||
assertEquals(
|
||||
"Creeper Aura VI — maximum rank reached; progression complete.",
|
||||
messages.describe(progress));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user