diff --git a/server/config.properties b/server/config.properties index 95f619e..5f88592 100644 --- a/server/config.properties +++ b/server/config.properties @@ -1,6 +1,11 @@ #Server Configuration -#Fri Aug 09 15:20:10 CEST 2024 +#Sun Oct 13 13:31:46 CEST 2024 +game.allowforce=true +game.maxslots=12 +game.minslots=4 +game.waittime=5 server.ip=0.0.0.0 -server.port=25565 server.mode=online +server.port=25565 +server.proxysecret= server.slots=0 diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/Server.java b/src/main/java/dev/celestialfox/spectrumsurvival/Server.java index c730e41..ad689a9 100644 --- a/src/main/java/dev/celestialfox/spectrumsurvival/Server.java +++ b/src/main/java/dev/celestialfox/spectrumsurvival/Server.java @@ -14,17 +14,10 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.adventure.audience.Audiences; import net.minestom.server.command.CommandManager; -import net.minestom.server.event.server.ServerListPingEvent; -import net.minestom.server.extras.MojangAuth; -import net.minestom.server.extras.bungee.BungeeCordProxy; -import net.minestom.server.extras.velocity.VelocityProxy; -import net.minestom.server.ping.ResponseData; import net.minestom.server.timer.TaskSchedule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Random; - public class Server { // Other private static final Logger logger = LoggerFactory.getLogger(Server.class); @@ -55,6 +48,7 @@ public static void main(String[] args) { logger.info("{ Config File Checks }"); Checks.slots(); Checks.mode(); + Checks.gameSettings(); // Server Start MinecraftServer.setBrandName("Spectrum Survival"); diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/QueueCommand.java b/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/QueueCommand.java index bad7151..672f45c 100644 --- a/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/QueueCommand.java +++ b/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/QueueCommand.java @@ -2,16 +2,12 @@ import dev.celestialfox.spectrumsurvival.game.managers.GameManager; import dev.celestialfox.spectrumsurvival.game.managers.QueueManager; +import dev.celestialfox.spectrumsurvival.utils.config.GameSettings; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.arguments.ArgumentType; -import net.minestom.server.entity.GameMode; import net.minestom.server.entity.Player; -import net.minestom.server.item.ItemStack; -import net.minestom.server.item.Material; -import net.minestom.server.potion.Potion; -import net.minestom.server.potion.PotionEffect; public class QueueCommand extends Command { public QueueCommand() { @@ -24,10 +20,14 @@ public QueueCommand() { } else if (arg1.equals("leave")) { QueueManager.removePlayer(player); } else if (arg1.equals("force")) { - if (QueueManager.getPlayerQueue(player) != null) { - GameManager.startGame(QueueManager.getPlayerQueue(player)); + if (GameSettings.getAllowForce()) { + if (QueueManager.getPlayerQueue(player) != null) { + GameManager.startGame(QueueManager.getPlayerQueue(player)); + } else { + player.sendMessage(Component.text("You're not in a queue!", NamedTextColor.RED)); + } } else { - player.sendMessage(Component.text("You're not in a queue!", NamedTextColor.RED)); + player.sendMessage(Component.text("/queue force command is disabled in the config", NamedTextColor.RED)); } } } diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/StatsCommand.java b/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/StatsCommand.java new file mode 100644 index 0000000..28fefe2 --- /dev/null +++ b/src/main/java/dev/celestialfox/spectrumsurvival/game/commands/StatsCommand.java @@ -0,0 +1,19 @@ +package dev.celestialfox.spectrumsurvival.game.commands; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.minestom.server.command.builder.Command; +import net.minestom.server.command.builder.arguments.ArgumentType; +import net.minestom.server.entity.Player; + +public class StatsCommand extends Command { + public StatsCommand() { + super("stats", "statistics"); + addSyntax(((sender, context) -> { + final Player player = context.get("player"); + if (sender instanceof Player playerSender) { + playerSender.sendMessage(Component.text("Stats are not available in this version yet.", NamedTextColor.RED)); + } + }), ArgumentType.Entity("player")); + } +} diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/game/managers/QueueManager.java b/src/main/java/dev/celestialfox/spectrumsurvival/game/managers/QueueManager.java index 149f6a9..9d81bdf 100644 --- a/src/main/java/dev/celestialfox/spectrumsurvival/game/managers/QueueManager.java +++ b/src/main/java/dev/celestialfox/spectrumsurvival/game/managers/QueueManager.java @@ -2,6 +2,7 @@ import dev.celestialfox.spectrumsurvival.utils.Misc; import dev.celestialfox.spectrumsurvival.game.classes.GameQueue; +import dev.celestialfox.spectrumsurvival.utils.config.GameSettings; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; @@ -20,8 +21,9 @@ public class QueueManager { public static List queues = new ArrayList<>(); private static final HashMap countdownTasks = new HashMap<>(); - private static int minPlayers = 6; - private static int maxPlayers = 12; + private static int minPlayers = GameSettings.getMinSlots(); + private static int maxPlayers = GameSettings.getMaxSlots(); + private static int waitTime = GameSettings.getWaitTime(); // in seconds public static Instance lobbyInstance; public static void joinPlayer(Player player) { @@ -84,7 +86,7 @@ private static void startCountdown(GameQueue queue) { return; } - final int[] countdown = {5}; // Countdown timer in seconds + final int[] countdown = {waitTime}; // Countdown timer in seconds // Schedule a task to send the title every second Task task = MinecraftServer.getSchedulerManager().buildTask(() -> { diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Checks.java b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Checks.java index a2681f2..cf55f13 100644 --- a/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Checks.java +++ b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Checks.java @@ -70,4 +70,39 @@ public static void mode() { Configuration.properties.setProperty("server.mode", "online"); } } + + public static void gameSettings() { + logger.info("Checking game settings..."); + int minSlots = GameSettings.getMinSlots(); + int maxSlots = GameSettings.getMaxSlots(); + boolean queueAllowForce = GameSettings.getAllowForce(); + int queueWaitTime = GameSettings.getWaitTime(); + + if (minSlots < 2) { + logger.error("Minimum slots cannot be less than 2."); + System.exit(0); + } else { + logger.info("Minimum slots set to: " + minSlots); + } + + if (maxSlots < minSlots) { + logger.error("Maximum slots cannot be less than the minimum slots."); + System.exit(0); + } else { + logger.info("Maximum slots set to: " + maxSlots); + } + + if (queueAllowForce) { + logger.info("Queue force join is enabled."); + } else { + logger.info("Queue force join is disabled."); + } + + if (queueWaitTime < 0) { + logger.error("Queue wait time cannot be negative."); + System.exit(0); + } else { + logger.info("Queue wait time set to: " + queueWaitTime + " seconds."); + } + } } diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Configuration.java b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Configuration.java index 0173df7..7b64ba5 100644 --- a/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Configuration.java +++ b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/Configuration.java @@ -28,6 +28,10 @@ public static void createDefaultConfig() { properties.setProperty("server.mode", "online"); properties.setProperty("server.slots", "0"); properties.setProperty("server.proxysecret", ""); + properties.setProperty("game.minslots", "4"); + properties.setProperty("game.maxslots", "12"); + properties.setProperty("game.waittime", "5"); + properties.setProperty("game.allowforce", "true"); properties.store(outputStream, "Server Configuration"); logger.info("Default config file created successfully."); @@ -52,4 +56,16 @@ static int getServerSlots() { static String getProxySecret() { return properties.getProperty("server.proxysecret"); } + static int getGameMinSlots() { + return Integer.parseInt(properties.getProperty("game.minslots")); + } + static int getGameMaxSlots() { + return Integer.parseInt(properties.getProperty("game.maxslots")); + } + static int getQueueWaitTime() { + return Integer.parseInt(properties.getProperty("game.waittime")); + } + static boolean getQueueAllowForce() { + return Boolean.parseBoolean(properties.getProperty("game.allowforce")); + } } \ No newline at end of file diff --git a/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/GameSettings.java b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/GameSettings.java new file mode 100644 index 0000000..36b48a7 --- /dev/null +++ b/src/main/java/dev/celestialfox/spectrumsurvival/utils/config/GameSettings.java @@ -0,0 +1,16 @@ +package dev.celestialfox.spectrumsurvival.utils.config; + +public class GameSettings { + public static int getMinSlots() { + return Configuration.getGameMinSlots(); + } + public static int getMaxSlots() { + return Configuration.getGameMaxSlots(); + } + public static int getWaitTime() { + return Configuration.getQueueWaitTime(); + } + public static boolean getAllowForce() { + return Configuration.getQueueAllowForce(); + } +}