diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/Main.java b/plugin/src/main/java/org/screamingsandals/bedwars/Main.java index 1deff6195..61c8164a6 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/Main.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/Main.java @@ -102,6 +102,8 @@ public class Main extends JavaPlugin implements BedwarsAPI { private TabManager tabManager; public static List autoColoredMaterials = new ArrayList<>(); private Metrics metrics; + private Game selectedGame; + private boolean preSelectGames; static { // ColorChanger list of materials @@ -183,6 +185,10 @@ public static void addGame(Game game) { public static void removeGame(Game game) { instance.games.remove(game.getName()); + if (instance.selectedGame == game) { + instance.selectedGame = null; + instance.reselectGame(); + } } public static Game getInGameEntity(Entity entity) { @@ -597,6 +603,17 @@ public void onEnable() { metrics.addCustomChart(new SimplePie("edition", () -> "Free")); metrics.addCustomChart(new SimplePie("build_number", () -> VersionInfo.BUILD_NUMBER)); + if ( + configurator.config.getBoolean("bungee.enabled") + && configurator.config.getBoolean("bungee.random-game-selection.enabled") + && configurator.config.getBoolean("bungee.random-game-selection.preselect-games") + ) { + Bukkit.getScheduler().runTaskLater(this, () -> { + selectedGame = (Game) getRandomWaitingGameForBungeeMode(); + preSelectGames = true; + }, 2L); + } + Bukkit.getConsoleSender().sendMessage("§fEverything is loaded! If you like our work, consider visiting our Patreon! <3"); Bukkit.getConsoleSender().sendMessage("§fhttps://www.patreon.com/screamingsandals"); } @@ -617,6 +634,8 @@ public void onDisable() { } metrics = null; + selectedGame = null; + preSelectGames = false; } private boolean setupEconomy() { @@ -820,4 +839,18 @@ public static boolean isDisabling() { public void se(boolean bool) { setEnabled(bool); } + + public boolean isPreSelectGames() { + return preSelectGames; + } + + public Game getSelectedGame() { + return selectedGame; + } + + public void reselectGame() { + if (preSelectGames) { + selectedGame = (Game) getRandomWaitingGameForBungeeMode(); + } + } } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/config/Configurator.java b/plugin/src/main/java/org/screamingsandals/bedwars/config/Configurator.java index 32abfef31..e79dd1787 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/config/Configurator.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/config/Configurator.java @@ -177,7 +177,8 @@ public void createFiles() { checkOrSetConfig(modify, "bungee.server", "hub"); checkOrSetConfig(modify, "bungee.auto-game-connect", false); checkOrSetConfig(modify, "bungee.kick-when-proxy-too-slow", true); - checkOrSetConfig(modify, "bungee.select-random-game", true); + checkOrSetConfig(modify, "bungee.random-game-selection.enabled", config.getBoolean("bungee.select-random-game", true)); + checkOrSetConfig(modify, "bungee.random-game-selection.preselect-games", false); checkOrSetConfig(modify, "bungee.motd.enabled", false); checkOrSetConfig(modify, "bungee.motd.waiting", "%name%: Waiting for players [%current%/%max%]"); checkOrSetConfig(modify, "bungee.motd.waiting_full", "%name%: Game is full [%current%/%max%]"); @@ -185,6 +186,11 @@ public void createFiles() { checkOrSetConfig(modify, "bungee.motd.rebuilding", "%name%: Rebuilding..."); checkOrSetConfig(modify, "bungee.motd.disabled", "%name%: Game is disabled"); + if (config.isSet("bungee.select-random-game")) { + modify.set(true); + config.set("bungee.select-random-game", null); + } + checkOrSetConfig(modify, "farmBlocks.enable", false); checkOrSetConfig(modify, "farmBlocks.blocks", new ArrayList<>()); diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java b/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java index d0ef7ed4e..731677b77 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java @@ -2363,6 +2363,8 @@ public void run() { } if (isBungeeEnabled()) { + Main.getInstance().reselectGame(); + preServerRestart = true; if (!getConnectedPlayers().isEmpty()) { @@ -2380,6 +2382,8 @@ public void run() { .dispatchCommand(Main.getInstance().getServer().getConsoleSender(), "restart"); } else if (Main.getConfigurator().config.getBoolean("bungee.serverStop")) { Bukkit.shutdown(); + } else { + preServerRestart = false; } } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/listener/BungeeMotdListener.java b/plugin/src/main/java/org/screamingsandals/bedwars/listener/BungeeMotdListener.java index 08fa37c82..2c4c392bf 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/listener/BungeeMotdListener.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/listener/BungeeMotdListener.java @@ -33,7 +33,14 @@ public void onServerListPing(ServerListPingEvent slpe) { return; } - Game game = Main.getGame(Main.getGameNames().get(0)); + Game game; + if (Main.getInstance().isPreSelectGames()) { + game = Main.getInstance().getSelectedGame(); + } else if (Main.getConfigurator().config.getBoolean("bungee.random-game-selection.enabled")) { + game = (Game) Main.getInstance().getRandomWaitingGameForBungeeMode(); + } else { + game = Main.getGame(Main.getGameNames().get(0)); + } if (game == null) { return; diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java b/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java index 78acb00cb..2fe3d428b 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java @@ -297,9 +297,14 @@ public void onPlayerJoin(PlayerJoinEvent event) { new BukkitRunnable() { public void run() { try { - Game game; - if (Main.getConfigurator().config.getBoolean("bungee.select-random-game")) { - game = (Game) Main.getInstance().getRandomWaitingGameForBungeeMode(); + Game game = null; + if (Main.getConfigurator().config.getBoolean("bungee.random-game-selection.enabled")) { + if (Main.getInstance().isPreSelectGames()) { + game = Main.getInstance().getSelectedGame(); + } + if (game == null) { + game = (Game) Main.getInstance().getRandomWaitingGameForBungeeMode(); + } } else { game = (Game) Main.getInstance().getFirstWaitingGame(); }