Introduce round management improvements, tab completion for /hg register, and plugin.yml configuration
This commit is contained in:
parent
5743bc63a5
commit
9db0e70425
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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<SubCommand> 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)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,4 +180,8 @@ abstract class AbstractConfig {
|
|||
ConfigurationSection getConfigurationSection(String path) {
|
||||
return yaml.getConfigurationSection(path);
|
||||
}
|
||||
|
||||
ConfigurationSection createSection(String path) {
|
||||
return yaml.createSection(path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> keys = configurationSection.getKeys(false);
|
||||
STAGES = getGameStages(keys, configurationSection);
|
||||
}
|
||||
|
|
|
|||
28
src/main/resources/plugin.yml
Normal file
28
src/main/resources/plugin.yml
Normal file
|
|
@ -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: /<command> <subcommand>
|
||||
|
||||
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
|
||||
Loading…
Reference in New Issue
Block a user