From 9db0e70425efc3e4f4ecc2ab5cc662253ac11935 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sat, 30 May 2026 18:37:48 +0200 Subject: [PATCH] Introduce round management improvements, tab completion for `/hg register`, and plugin.yml configuration --- .../java/com/alttd/hunger_games/Main.java | 5 ++-- .../hunger_games/commands/BaseCommand.java | 7 +++-- .../commands/subcommands/Register.java | 4 +++ .../hunger_games/config/AbstractConfig.java | 4 +++ .../com/alttd/hunger_games/config/Config.java | 3 ++ src/main/resources/plugin.yml | 28 +++++++++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/plugin.yml diff --git a/src/main/java/com/alttd/hunger_games/Main.java b/src/main/java/com/alttd/hunger_games/Main.java index 87e7294..a81cfab 100644 --- a/src/main/java/com/alttd/hunger_games/Main.java +++ b/src/main/java/com/alttd/hunger_games/Main.java @@ -17,6 +17,7 @@ import org.bukkit.plugin.java.JavaPlugin; @Slf4j public final class Main extends JavaPlugin { + private Round round; private RoundService roundService; private PlayerService playerService; private PlayerTeleporterService playerTeleporterService; @@ -32,7 +33,7 @@ public final class Main extends JavaPlugin { } private void registerServices() { - Round round = Round.createSingletonInstance(); + round = Round.createSingletonInstance(); roundService = RoundService.createSingletonInstance(round); playerTeleporterService = PlayerTeleporterService.createSingletonInstance(); playerService = PlayerService.createSingletonInstance(roundService, playerTeleporterService); @@ -44,7 +45,7 @@ public final class Main extends JavaPlugin { } private void registerCommands() { - BaseCommand command = new BaseCommand(this, roundService, playerService); + BaseCommand command = new BaseCommand(this, roundService, playerService, round); } private void registerEvents() { diff --git a/src/main/java/com/alttd/hunger_games/commands/BaseCommand.java b/src/main/java/com/alttd/hunger_games/commands/BaseCommand.java index 529a75e..0360774 100644 --- a/src/main/java/com/alttd/hunger_games/commands/BaseCommand.java +++ b/src/main/java/com/alttd/hunger_games/commands/BaseCommand.java @@ -3,8 +3,10 @@ package com.alttd.hunger_games.commands; import com.alttd.hunger_games.Main; import com.alttd.hunger_games.commands.subcommands.Register; import com.alttd.hunger_games.commands.subcommands.RoundState; +import com.alttd.hunger_games.commands.subcommands.StartRound; import com.alttd.hunger_games.config.Messages; import com.alttd.hunger_games.services.PlayerService; +import com.alttd.hunger_games.services.Round; import com.alttd.hunger_games.services.RoundService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -21,7 +23,7 @@ import java.util.stream.Collectors; public class BaseCommand implements CommandExecutor, TabExecutor { private final List subCommands; - public BaseCommand(Main main, RoundService roundService, PlayerService playerService) { + public BaseCommand(Main main, RoundService roundService, PlayerService playerService, Round round) { PluginCommand command = main.getCommand("hungergames"); if (command == null) { subCommands = null; @@ -34,7 +36,8 @@ public class BaseCommand implements CommandExecutor, TabExecutor { subCommands = new ArrayList<>(List.of( new RoundState(roundService), - new Register(playerService) + new Register(playerService), + new StartRound(round) )); } diff --git a/src/main/java/com/alttd/hunger_games/commands/subcommands/Register.java b/src/main/java/com/alttd/hunger_games/commands/subcommands/Register.java index a2cdc6f..a24439f 100644 --- a/src/main/java/com/alttd/hunger_games/commands/subcommands/Register.java +++ b/src/main/java/com/alttd/hunger_games/commands/subcommands/Register.java @@ -7,6 +7,7 @@ import com.alttd.hunger_games.data_objects.PLAYER_STATE; import com.alttd.hunger_games.services.PlayerService; import lombok.extern.slf4j.Slf4j; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -97,6 +98,9 @@ public class Register extends SubCommand { @Override public List getTabComplete(CommandSender commandSender, String[] args) { + if (args.length == 2) { + return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(); + } return List.of(); } diff --git a/src/main/java/com/alttd/hunger_games/config/AbstractConfig.java b/src/main/java/com/alttd/hunger_games/config/AbstractConfig.java index 8bc3598..b67201e 100644 --- a/src/main/java/com/alttd/hunger_games/config/AbstractConfig.java +++ b/src/main/java/com/alttd/hunger_games/config/AbstractConfig.java @@ -180,4 +180,8 @@ abstract class AbstractConfig { ConfigurationSection getConfigurationSection(String path) { return yaml.getConfigurationSection(path); } + + ConfigurationSection createSection(String path) { + return yaml.createSection(path); + } } diff --git a/src/main/java/com/alttd/hunger_games/config/Config.java b/src/main/java/com/alttd/hunger_games/config/Config.java index 55f2aa2..d19e28b 100644 --- a/src/main/java/com/alttd/hunger_games/config/Config.java +++ b/src/main/java/com/alttd/hunger_games/config/Config.java @@ -57,6 +57,9 @@ public class Config extends AbstractConfig { COUNTDOWN = Duration.ofSeconds(countdownSeconds); ConfigurationSection configurationSection = config.getConfigurationSection(prefix + "stages"); + if (configurationSection == null) { + configurationSection = config.createSection(prefix + "stages"); + } Set keys = configurationSection.getKeys(false); STAGES = getGameStages(keys, configurationSection); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..f00bf37 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,28 @@ +name: HungerGames +version: ${version} +main: com.alttd.hunger_games.Main +api-version: "1.21" + +commands: + hungergames: + description: Main HungerGames command + aliases: [hg] + usage: / + +permissions: + hungergames.register: + description: Register a player for the game + default: op + hungergames.roundstate: + description: Check the current round state + default: true + hungergames.start: + description: Start a HungerGames round + default: op + hungergames.*: + description: Wildcard permission for all HungerGames commands + default: op + children: + hungergames.register: true + hungergames.roundstate: true + hungergames.start: true