feat(admin): add Tyrant point grant command
This commit is contained in:
@@ -17,6 +17,7 @@ public final class TyrantAdminCommand implements CommandExecutor {
|
||||
private final ManagedRoleEffects effects;
|
||||
private final Clock clock;
|
||||
private final ArenaLocationStore arenaLocations;
|
||||
private final TyrantProgressionService progression = new TyrantProgressionService();
|
||||
|
||||
public TyrantAdminCommand(
|
||||
TyrantStateManager stateManager,
|
||||
@@ -69,6 +70,7 @@ public final class TyrantAdminCommand implements CommandExecutor {
|
||||
case "resume" -> resume(sender);
|
||||
case "reset" -> reset(sender, arguments);
|
||||
case "arena" -> arena(sender, arguments);
|
||||
case "grantpoint" -> grantPoint(sender, arguments);
|
||||
default -> usage(sender);
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalStateException exception) {
|
||||
@@ -141,6 +143,20 @@ public final class TyrantAdminCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.GREEN + "Tyrant game reset.");
|
||||
}
|
||||
|
||||
private void grantPoint(CommandSender sender, String[] arguments) {
|
||||
if (arguments.length != 1) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Usage: /tyrantadmin grantpoint");
|
||||
return;
|
||||
}
|
||||
PersistentState snapshot = stateManager.snapshot();
|
||||
GameState updated = progression.grantPoint(snapshot.game());
|
||||
stateManager.replaceState(new LifecycleState(updated, snapshot.players()));
|
||||
stateManager.saveIfDirty();
|
||||
sender.sendMessage(ChatColor.GREEN + "Granted the Tyrant one point; now level "
|
||||
+ updated.tyrantLevel() + " and " + updated.unspentChoices()
|
||||
+ " unspent choices.");
|
||||
}
|
||||
|
||||
private void arena(CommandSender sender, String[] arguments) {
|
||||
if (arguments.length == 1 || arguments[1].equalsIgnoreCase("status")) {
|
||||
sender.sendMessage("Shared role arena: " + arenaLocations.location()
|
||||
@@ -194,6 +210,6 @@ public final class TyrantAdminCommand implements CommandExecutor {
|
||||
|
||||
private static void usage(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Usage: /tyrantadmin <status|start|pause|resume|reset confirm|arena set>");
|
||||
+ "Usage: /tyrantadmin <status|start|pause|resume|reset confirm|arena set|grantpoint>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
|
||||
public final class TyrantAdminTabCompleter implements TabCompleter {
|
||||
private static final String PERMISSION = "spigottyrant.admin";
|
||||
private static final List<String> SUBCOMMANDS = List.of(
|
||||
"status", "start", "pause", "resume", "reset", "arena"
|
||||
"status", "start", "pause", "resume", "reset", "arena", "grantpoint"
|
||||
);
|
||||
private final OnlinePlayerDirectory onlinePlayers;
|
||||
|
||||
|
||||
@@ -20,6 +20,25 @@ public final class TyrantProgressionService {
|
||||
);
|
||||
}
|
||||
|
||||
public GameState grantPoint(GameState state) {
|
||||
if (state.lifecycle() != GameLifecycle.RUNNING) {
|
||||
throw new IllegalStateException("Tyrant game must be running.");
|
||||
}
|
||||
if (state.tyrantId().isEmpty()) {
|
||||
throw new IllegalStateException("There is no current Tyrant.");
|
||||
}
|
||||
if (state.tyrantLevel() == Integer.MAX_VALUE
|
||||
|| state.unspentChoices() == Integer.MAX_VALUE) {
|
||||
throw new IllegalStateException("Tyrant progression cannot be increased further.");
|
||||
}
|
||||
return copyProgress(
|
||||
state,
|
||||
state.tyrantLevel() + 1,
|
||||
state.unspentChoices() + 1,
|
||||
state.purchases()
|
||||
);
|
||||
}
|
||||
|
||||
public PurchaseResult purchase(
|
||||
GameState state,
|
||||
UUID buyerId,
|
||||
|
||||
@@ -13,7 +13,7 @@ commands:
|
||||
usage: /vigilante <menu|item|invite <player>|accept|dismiss <player>|leave>
|
||||
tyrantadmin:
|
||||
description: Administer the Spigot Tyrant game.
|
||||
usage: /tyrantadmin <status|start|pause|resume|reset confirm|arena <set|status>>
|
||||
usage: /tyrantadmin <status|start|pause|resume|reset confirm|arena <set|status>|grantpoint>
|
||||
permission: spigottyrant.admin
|
||||
permissions:
|
||||
spigottyrant.admin:
|
||||
|
||||
Reference in New Issue
Block a user