Compare commits
3 Commits
161344b30c
...
d7160b86cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7160b86cd | ||
|
|
02228f570d | ||
|
|
c2d83492d1 |
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -41,3 +41,6 @@ bin/
|
||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
### Ignore bat files ###
|
||||||
|
*bat
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j @Getter
|
@Slf4j
|
||||||
|
@Getter
|
||||||
public class BaseCommand implements CommandExecutor, TabExecutor {
|
public class BaseCommand implements CommandExecutor, TabExecutor {
|
||||||
private final List<SubCommand> subCommands;
|
private final List<SubCommand> subCommands;
|
||||||
|
|
||||||
|
|
@ -39,8 +40,8 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
||||||
new Reload(main),
|
new Reload(main),
|
||||||
new RoundState(roundService),
|
new RoundState(roundService),
|
||||||
new Register(playerService),
|
new Register(playerService),
|
||||||
new StartRound(round)
|
new StartRound(round, roundService)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -76,11 +77,11 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
||||||
|
|
||||||
if (args.length <= 1) {
|
if (args.length <= 1) {
|
||||||
res.addAll(subCommands.stream()
|
res.addAll(subCommands.stream()
|
||||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getName)
|
.map(SubCommand::getName)
|
||||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
SubCommand subCommand = getSubCommand(args[0]);
|
SubCommand subCommand = getSubCommand(args[0]);
|
||||||
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission())) {
|
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission())) {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ package com.alttd.hunger_games.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.hunger_games.commands.SubCommand;
|
import com.alttd.hunger_games.commands.SubCommand;
|
||||||
import com.alttd.hunger_games.config.Messages;
|
import com.alttd.hunger_games.config.Messages;
|
||||||
|
import com.alttd.hunger_games.data_objects.ROUND_STATE;
|
||||||
import com.alttd.hunger_games.services.Round;
|
import com.alttd.hunger_games.services.Round;
|
||||||
|
import com.alttd.hunger_games.services.RoundService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -12,10 +15,17 @@ import java.util.List;
|
||||||
public class StartRound extends SubCommand {
|
public class StartRound extends SubCommand {
|
||||||
|
|
||||||
private final Round round;
|
private final Round round;
|
||||||
|
private final RoundService roundService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
round.startRound();
|
ROUND_STATE roundState = roundService.getRoundState();
|
||||||
|
if (roundState == ROUND_STATE.PLAYER_REGISTRATION) {
|
||||||
|
round.startRound();
|
||||||
|
} else {
|
||||||
|
commandSender.sendRichMessage(Messages.START_ROUND.CAN_NOT_START_ROUND,
|
||||||
|
Placeholder.parsed("round_state", roundState.getHumandReadableName()));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,19 +111,25 @@ abstract class AbstractConfig {
|
||||||
return yaml.getDouble(path, yaml.getDouble(path));
|
return yaml.getDouble(path, yaml.getDouble(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean contains(String prefix, String path) {
|
boolean isValidSection(String prefix, String path) {
|
||||||
|
return getConfigurationSection(prefix + path) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isEmpty(String prefix, String path) {
|
||||||
path = prefix + path;
|
path = prefix + path;
|
||||||
return !yaml.contains(path);
|
return yaml.get(path) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Location> getLocation(String prefix, String path) {
|
Optional<Location> getLocation(String prefix, String path) {
|
||||||
if (contains(prefix, path)) {
|
if (!isValidSection(prefix, path)) {
|
||||||
|
log.warn("No location configuration for {}", prefix + path);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
//destination.start-center.world
|
||||||
String rootPath = prefix + path + ".";
|
String rootPath = prefix + path + ".";
|
||||||
if (contains(rootPath, "world") || contains(rootPath, path + "x") || contains(rootPath, path + "y") || contains(rootPath, path + "z")) {
|
if (isEmpty(rootPath, "world") || isEmpty(rootPath, "x") || isEmpty(rootPath, "y") || isEmpty(rootPath, "z")) {
|
||||||
log.error("Invalid location configuration for {}", path);
|
ConfigurationSection configurationSection = getConfigurationSection(prefix + path);
|
||||||
|
log.error("Invalid location configuration for:\n\t{}", configurationSection.getKeys(false).stream().map(key -> rootPath + key).collect(Collectors.joining("\n\t")));
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public class Config extends AbstractConfig {
|
||||||
private static final String prefix = "round.";
|
private static final String prefix = "round.";
|
||||||
|
|
||||||
public static Duration COUNTDOWN = Duration.ofSeconds(10);
|
public static Duration COUNTDOWN = Duration.ofSeconds(10);
|
||||||
|
public static int INITIAL_BORDER_SIZE = 5000;
|
||||||
public static List<GameStage> STAGES = List.of(
|
public static List<GameStage> STAGES = List.of(
|
||||||
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(1000).build(),
|
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(1000).build(),
|
||||||
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(750).build(),
|
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(750).build(),
|
||||||
|
|
@ -55,6 +56,7 @@ public class Config extends AbstractConfig {
|
||||||
private static void load() {
|
private static void load() {
|
||||||
int countdownSeconds = config.getInt(prefix, "countdown-seconds", Math.toIntExact(COUNTDOWN.toSeconds()));
|
int countdownSeconds = config.getInt(prefix, "countdown-seconds", Math.toIntExact(COUNTDOWN.toSeconds()));
|
||||||
COUNTDOWN = Duration.ofSeconds(countdownSeconds);
|
COUNTDOWN = Duration.ofSeconds(countdownSeconds);
|
||||||
|
INITIAL_BORDER_SIZE = config.getInt(prefix, "initial-border-size", INITIAL_BORDER_SIZE);
|
||||||
|
|
||||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix + "stages");
|
ConfigurationSection configurationSection = config.getConfigurationSection(prefix + "stages");
|
||||||
if (configurationSection == null) {
|
if (configurationSection == null) {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ public class Messages extends AbstractConfig {
|
||||||
public static class ROUND_STATE {
|
public static class ROUND_STATE {
|
||||||
private static final String prefix = "round-state.";
|
private static final String prefix = "round-state.";
|
||||||
|
|
||||||
public static String ROUND_STATE = "<green>Current round state is: <gold>round_state</gold></green>";
|
public static String ROUND_STATE = "<green>Current round state is: <gold><round_state></gold></green>";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
|
|
@ -70,6 +70,21 @@ public class Messages extends AbstractConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GAME {
|
||||||
|
private static final String prefix = "game.";
|
||||||
|
|
||||||
|
public static String WARMUP = "<gold>The Hunger Games are starting soon! Get ready!</gold>";
|
||||||
|
public static String STARTED = "<green><bold>The Hunger Games has begun! Good luck!</bold></green>";
|
||||||
|
public static String BORDER_SHRINK = "<red>The border is shrinking to <size> blocks!</red>";
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
WARMUP = config.getString(prefix, "warmup", WARMUP);
|
||||||
|
STARTED = config.getString(prefix, "started", STARTED);
|
||||||
|
BORDER_SHRINK = config.getString(prefix, "border-shrink", BORDER_SHRINK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class RECONNECT {
|
public static class RECONNECT {
|
||||||
private static final String prefix = "reconnect.";
|
private static final String prefix = "reconnect.";
|
||||||
|
|
||||||
|
|
@ -101,4 +116,14 @@ public class Messages extends AbstractConfig {
|
||||||
GAME_RUNNING = config.getString(prefix, "game-running", GAME_RUNNING);
|
GAME_RUNNING = config.getString(prefix, "game-running", GAME_RUNNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class START_ROUND {
|
||||||
|
private static final String prefix = "start-round.";
|
||||||
|
public static String CAN_NOT_START_ROUND = "<red>The round can not be started because the current state is <state>.</red>";
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
CAN_NOT_START_ROUND = config.getString(prefix, "can-not-start", CAN_NOT_START_ROUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,60 @@
|
||||||
package com.alttd.hunger_games.game;
|
package com.alttd.hunger_games.game;
|
||||||
|
|
||||||
|
import com.alttd.hunger_games.config.Config;
|
||||||
|
import com.alttd.hunger_games.config.Messages;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldBorder;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class GameStageHandler {
|
public class GameStageHandler {
|
||||||
|
|
||||||
|
private static final int BORDER_TRANSITION_SECONDS = 10;
|
||||||
|
|
||||||
public static void handleStageChange(int worldBorderSize) {
|
public static void handleStageChange(int worldBorderSize) {
|
||||||
//TODO change world border size and handle stage change
|
World world = getWorld().orElseThrow(() -> new IllegalStateException("No worlds available during state change,"));
|
||||||
|
|
||||||
|
WorldBorder border = world.getWorldBorder();
|
||||||
|
border.setSize(worldBorderSize, BORDER_TRANSITION_SECONDS);
|
||||||
|
|
||||||
|
String message = Messages.GAME.BORDER_SHRINK
|
||||||
|
.replace("<size>", String.valueOf(worldBorderSize));
|
||||||
|
broadcast(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleCountdownEnd() {
|
public static void handleCountdownEnd() {
|
||||||
//TODO free players and handle stage change
|
broadcast(Messages.GAME.STARTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleWarmup() {
|
public static void handleWarmup() {
|
||||||
//TODO tp players to start area etc (might be handled by state change already, so maybe just messages)
|
Location center = Config.DESTINATION.START_CENTER;
|
||||||
|
if (center == null || center.getWorld() == null) {
|
||||||
|
throw new IllegalStateException("Start center is not set during warmup.");
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldBorder border = center.getWorld().getWorldBorder();
|
||||||
|
border.setCenter(center.getX(), center.getZ());
|
||||||
|
border.setSize(Config.ROUND.INITIAL_BORDER_SIZE);
|
||||||
|
|
||||||
|
broadcast(Messages.GAME.WARMUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<World> getWorld() {
|
||||||
|
Location center = Config.DESTINATION.START_CENTER;
|
||||||
|
if (center != null && center.getWorld() != null) {
|
||||||
|
return Optional.ofNullable(center.getWorld());
|
||||||
|
}
|
||||||
|
return Bukkit.getWorlds().isEmpty() ? Optional.empty() : Optional.of(Bukkit.getWorlds().getFirst());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void broadcast(String message) {
|
||||||
|
Component component = MiniMessage.miniMessage().deserialize(message);
|
||||||
|
Bukkit.broadcast(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public class Round {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
if (roundState.equals(ROUND_STATE.PLAYER_REGISTRATION)) {
|
if (!roundState.equals(ROUND_STATE.PLAYER_REGISTRATION)) {
|
||||||
throw new IllegalStateException("Round can not be started before player registration.");
|
throw new IllegalStateException("Round can not be started before player registration.");
|
||||||
}
|
}
|
||||||
roundState = ROUND_STATE.COUNTDOWN;
|
roundState = ROUND_STATE.COUNTDOWN;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user