Compare commits
No commits in common. "d7160b86cd0892a635cc0981d9245c43469661ce" and "161344b30c53071efa6d27bc61c9963638033b5a" have entirely different histories.
d7160b86cd
...
161344b30c
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -40,7 +40,4 @@ bin/
|
|||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
||||
### Ignore bat files ###
|
||||
*bat
|
||||
.DS_Store
|
||||
|
|
@ -20,8 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Slf4j @Getter
|
||||
public class BaseCommand implements CommandExecutor, TabExecutor {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
||||
|
|
@ -40,8 +39,8 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
|||
new Reload(main),
|
||||
new RoundState(roundService),
|
||||
new Register(playerService),
|
||||
new StartRound(round, roundService)
|
||||
));
|
||||
new StartRound(round)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -77,11 +76,11 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
|||
|
||||
if (args.length <= 1) {
|
||||
res.addAll(subCommands.stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getName)
|
||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||
.toList()
|
||||
);
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getName)
|
||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||
.toList()
|
||||
);
|
||||
} else {
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission())) {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@ package com.alttd.hunger_games.commands.subcommands;
|
|||
|
||||
import com.alttd.hunger_games.commands.SubCommand;
|
||||
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.RoundService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -15,17 +12,10 @@ import java.util.List;
|
|||
public class StartRound extends SubCommand {
|
||||
|
||||
private final Round round;
|
||||
private final RoundService roundService;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
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()));
|
||||
}
|
||||
round.startRound();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,25 +111,19 @@ abstract class AbstractConfig {
|
|||
return yaml.getDouble(path, yaml.getDouble(path));
|
||||
}
|
||||
|
||||
boolean isValidSection(String prefix, String path) {
|
||||
return getConfigurationSection(prefix + path) != null;
|
||||
}
|
||||
|
||||
boolean isEmpty(String prefix, String path) {
|
||||
boolean contains(String prefix, String path) {
|
||||
path = prefix + path;
|
||||
return yaml.get(path) == null;
|
||||
return !yaml.contains(path);
|
||||
}
|
||||
|
||||
Optional<Location> getLocation(String prefix, String path) {
|
||||
if (!isValidSection(prefix, path)) {
|
||||
log.warn("No location configuration for {}", prefix + path);
|
||||
if (contains(prefix, path)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
//destination.start-center.world
|
||||
|
||||
String rootPath = prefix + path + ".";
|
||||
if (isEmpty(rootPath, "world") || isEmpty(rootPath, "x") || isEmpty(rootPath, "y") || isEmpty(rootPath, "z")) {
|
||||
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")));
|
||||
if (contains(rootPath, "world") || contains(rootPath, path + "x") || contains(rootPath, path + "y") || contains(rootPath, path + "z")) {
|
||||
log.error("Invalid location configuration for {}", path);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ public class Config extends AbstractConfig {
|
|||
private static final String prefix = "round.";
|
||||
|
||||
public static Duration COUNTDOWN = Duration.ofSeconds(10);
|
||||
public static int INITIAL_BORDER_SIZE = 5000;
|
||||
public static List<GameStage> STAGES = List.of(
|
||||
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(1000).build(),
|
||||
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(750).build(),
|
||||
|
|
@ -56,7 +55,6 @@ public class Config extends AbstractConfig {
|
|||
private static void load() {
|
||||
int countdownSeconds = config.getInt(prefix, "countdown-seconds", Math.toIntExact(COUNTDOWN.toSeconds()));
|
||||
COUNTDOWN = Duration.ofSeconds(countdownSeconds);
|
||||
INITIAL_BORDER_SIZE = config.getInt(prefix, "initial-border-size", INITIAL_BORDER_SIZE);
|
||||
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix + "stages");
|
||||
if (configurationSection == null) {
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class Messages extends AbstractConfig {
|
|||
public static class 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")
|
||||
private static void load() {
|
||||
|
|
@ -70,21 +70,6 @@ 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 {
|
||||
private static final String prefix = "reconnect.";
|
||||
|
||||
|
|
@ -116,14 +101,4 @@ public class Messages extends AbstractConfig {
|
|||
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,60 +1,19 @@
|
|||
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 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
|
||||
public class GameStageHandler {
|
||||
|
||||
private static final int BORDER_TRANSITION_SECONDS = 10;
|
||||
|
||||
public static void handleStageChange(int worldBorderSize) {
|
||||
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);
|
||||
//TODO change world border size and handle stage change
|
||||
}
|
||||
|
||||
public static void handleCountdownEnd() {
|
||||
broadcast(Messages.GAME.STARTED);
|
||||
//TODO free players and handle stage change
|
||||
}
|
||||
|
||||
public static void handleWarmup() {
|
||||
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);
|
||||
//TODO tp players to start area etc (might be handled by state change already, so maybe just messages)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class Round {
|
|||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
roundState = ROUND_STATE.COUNTDOWN;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user