Compare commits
3 Commits
5743bc63a5
...
161344b30c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
161344b30c | ||
|
|
c969873e0a | ||
|
|
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,10 +33,10 @@ 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);
|
||||
playerService = PlayerService.createSingletonInstance(round, roundService, playerTeleporterService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ 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.Reload;
|
||||
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 +24,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;
|
||||
|
|
@ -33,8 +36,10 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
|||
command.setAliases(List.of("hg"));
|
||||
|
||||
subCommands = new ArrayList<>(List.of(
|
||||
new Reload(main),
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.alttd.hunger_games.commands.subcommands;
|
||||
|
||||
import com.alttd.hunger_games.Main;
|
||||
import com.alttd.hunger_games.commands.SubCommand;
|
||||
import com.alttd.hunger_games.config.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Reload extends SubCommand {
|
||||
|
||||
private final Main main;
|
||||
|
||||
public Reload(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
main.reloadConfigs();
|
||||
commandSender.sendRichMessage(Messages.GENERIC.RELOAD_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.RELOAD;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String ROUND_STATE = "<green>Show the current round state: <gold>/hg roundstate</gold></green>";
|
||||
public static String REGISTER = "<green>Register a player for the game: <gold>/hg register <player></gold></green>";
|
||||
public static String START_ROUND = "<green>Start the game: <gold>/hg start</gold></green>";
|
||||
public static String RELOAD = "<green>Reload config and messages: <gold>/hg reload</gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -37,6 +38,7 @@ public class Messages extends AbstractConfig {
|
|||
ROUND_STATE = config.getString(prefix, "round-state", ROUND_STATE);
|
||||
REGISTER = config.getString(prefix, "register", REGISTER);
|
||||
START_ROUND = config.getString(prefix, "start", START_ROUND);
|
||||
RELOAD = config.getString(prefix, "reload", RELOAD);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,12 +48,14 @@ public class Messages extends AbstractConfig {
|
|||
public static String NO_PERMISSION = "<red><hover:show_text:'<red><permission></red>'>You don't have permission for this command</hover></red>";
|
||||
public static String PLAYER_ONLY = "<red>This command can only be executed as a player</red>";
|
||||
public static String PLAYER_NOT_FOUND = "<red>Unable to find online player <player></red>";
|
||||
public static String RELOAD_SUCCESS = "<green>Config and messages have been reloaded.</green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
||||
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
||||
PLAYER_NOT_FOUND = config.getString(prefix, "player-only", PLAYER_NOT_FOUND);
|
||||
RELOAD_SUCCESS = config.getString(prefix, "reload-success", RELOAD_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ import com.alttd.hunger_games.config.Messages;
|
|||
import com.alttd.hunger_games.data_objects.DESTINATION;
|
||||
import com.alttd.hunger_games.data_objects.PLAYER_STATE;
|
||||
import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PlayerService implements RoundListener {
|
||||
|
||||
private static PlayerService instance = null;
|
||||
|
|
@ -19,11 +17,17 @@ public class PlayerService implements RoundListener {
|
|||
private final PlayerTeleporterService playerTeleporterService;
|
||||
private ROUND_STATE roundState;
|
||||
|
||||
public static PlayerService createSingletonInstance(RoundService roundService, PlayerTeleporterService playerTeleporterService) {
|
||||
public PlayerService(Round round, RoundService roundService, PlayerTeleporterService playerTeleporterService) {
|
||||
this.roundService = roundService;
|
||||
this.playerTeleporterService = playerTeleporterService;
|
||||
this.roundState = round.register(this);
|
||||
}
|
||||
|
||||
public static PlayerService createSingletonInstance(Round round, RoundService roundService, PlayerTeleporterService playerTeleporterService) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("PlayerService is already initialized.");
|
||||
}
|
||||
instance = new PlayerService(roundService, playerTeleporterService);
|
||||
instance = new PlayerService(round, roundService, playerTeleporterService);
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
|
|||
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