Skip to content

Commit

Permalink
Added some game settings
Browse files Browse the repository at this point in the history
Added ideas from issue #5
  • Loading branch information
AndusDEV committed Oct 13, 2024
1 parent be29ed7 commit a02cce8
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 20 deletions.
9 changes: 7 additions & 2 deletions server/config.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 1 addition & 7 deletions src/main/java/dev/celestialfox/spectrumsurvival/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +21,9 @@
public class QueueManager {
public static List<GameQueue> queues = new ArrayList<>();
private static final HashMap<GameQueue, Task> 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) {
Expand Down Expand Up @@ -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(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit a02cce8

Please sign in to comment.