Skip to content

Commit

Permalink
feat: game preselection (bungee.random-game-selection.preselect-games…
Browse files Browse the repository at this point in the history
…), fixed wrong game in motd
  • Loading branch information
Misat11 committed May 8, 2024
1 parent e7197d0 commit 0a52cb1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
33 changes: 33 additions & 0 deletions plugin/src/main/java/org/screamingsandals/bedwars/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class Main extends JavaPlugin implements BedwarsAPI {
private TabManager tabManager;
public static List<String> autoColoredMaterials = new ArrayList<>();
private Metrics metrics;
private Game selectedGame;
private boolean preSelectGames;

static {
// ColorChanger list of materials
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand All @@ -617,6 +634,8 @@ public void onDisable() {
}

metrics = null;
selectedGame = null;
preSelectGames = false;
}

private boolean setupEconomy() {
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,20 @@ 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%]");
checkOrSetConfig(modify, "bungee.motd.running", "%name%: Game is running [%current%/%max%]");
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<>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,8 @@ public void run() {
}

if (isBungeeEnabled()) {
Main.getInstance().reselectGame();

preServerRestart = true;

if (!getConnectedPlayers().isEmpty()) {
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 0a52cb1

Please sign in to comment.