diff options
author | Myles <mylesandmore9@gmail.com> | 2022-12-07 19:06:55 -0600 |
---|---|---|
committer | Myles <mylesandmore9@gmail.com> | 2022-12-07 19:06:55 -0600 |
commit | 0860c7913225943cd16f8a149ec9cf0b407ce359 (patch) | |
tree | 429b355a883c66a7ba796627307f9582f8b12e02 | |
parent | 8a1072641f30af8c06361a03a302321822c3ce7f (diff) | |
download | Tumble-0860c7913225943cd16f8a149ec9cf0b407ce359.tar.gz Tumble-0860c7913225943cd16f8a149ec9cf0b407ce359.tar.bz2 Tumble-0860c7913225943cd16f8a149ec9cf0b407ce359.zip |
bug fixes and duplicate game glitch fixed
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/Game.java | 25 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/commands/StartGame.java | 16 |
2 files changed, 28 insertions, 13 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/tumble/Game.java index 439cbb1..117faff 100644 --- a/src/main/java/com/MylesAndMore/tumble/Game.java +++ b/src/main/java/com/MylesAndMore/tumble/Game.java @@ -318,33 +318,38 @@ public class Game { gameWins.set(gamePlayers.indexOf(winner), (gameWins.get(gamePlayers.indexOf(winner)) + 1)); // Clear old layers (as a fill command, this would be /fill ~-20 ~-4 ~-20 ~20 ~ ~20 relative to spawn) Generator.generateCuboid(new Location(gameSpawn.getWorld(), gameSpawn.getX() - 20, gameSpawn.getY() - 4, gameSpawn.getZ() - 20), new Location(gameSpawn.getWorld(), gameSpawn.getX() + 20, gameSpawn.getY(), gameSpawn.getZ() + 20), Material.AIR); - playSound(gamePlayers, Sound.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.HOSTILE, 1, 1); + playSound(gamePlayers, Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.BLOCKS, 5, 0); // If the player has three wins, they won the game, so initiate the gameEnd if (gameWins.get(gamePlayers.indexOf(winner)) == 3) { gameEnd(winner); } // If that player doesn't have three wins, nobody else does, so we need another round else { - displayTitles(gamePlayers, ChatColor.RED + "Round over!", ChatColor.GOLD + winner.getName() + " has won the round!", 2, 20, 2); + displayTitles(gamePlayers, ChatColor.RED + "Round over!", ChatColor.GOLD + winner.getName() + " has won the round!", 5, 60, 5); // Re-generate layers generateLayers(gameType); displayMessage(gamePlayers, ChatColor.BLUE + "A new round will begin in ten seconds!"); - // Wait 10s (100t) for tp method + // Wait 5s (100t) for tp method Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { // Re-scatter players + gameState = "starting"; scatterPlayers(gamePlayers); - displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1); - playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 2); - // Set their gamemodes to survival - setGamemode(gamePlayers, GameMode.SURVIVAL); - }, 200); + // Wait another 5s for game start + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1); + playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 2); + // Set their gamemodes to survival + setGamemode(gamePlayers, GameMode.SURVIVAL); + gameState = "running"; + }, 100); + }, 100); } } private void gameEnd(Player winner) { // Announce win - displayTitles(gamePlayers, ChatColor.RED + "Game over!", ChatColor.GOLD + winner.getName() + " has won the game!", 4, 40, 2); - displayMessage(gamePlayers, ChatColor.BLUE + "Teleporting back in five seconds..."); + displayTitles(gamePlayers, ChatColor.RED + "Game over!", ChatColor.GOLD + winner.getName() + " has won the game!", 5, 60, 5); + displayMessage(gamePlayers, ChatColor.BLUE + "Teleporting back in ten seconds..."); // Wait 10s (200t), then Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { // Set their gamemodes to survival diff --git a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java index 2e531ef..5577173 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java +++ b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java @@ -7,6 +7,8 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import java.util.Objects; + public class StartGame implements CommandExecutor { public void startGame(CommandSender sender, String[] args) { // Check if sender has perms to run command @@ -17,14 +19,22 @@ public class StartGame implements CommandExecutor { if (TumbleManager.getPlayersInLobby().size() > 0) { // Check if there is a gameWorld specified in config if (TumbleManager.getGameWorld() != null) { - sender.sendMessage("Starting game, please wait."); // Use multiverse to load game world // If the load was successful, start game if (TumbleManager.getMVWorldManager().loadWorld(TumbleManager.getGameWorld())) { // Check which gamemode to initiate from the config file if (!Game.getGame().startGame()) { - // If game type does not exist, give sender feedback - sender.sendMessage(ChatColor.RED + "Failed to recognize game of type " + ChatColor.GRAY + TumbleManager.getPlugin().getConfig().getString("gameMode")); + // Sender feedback for if the game failed to start + if (Objects.equals(Game.getGame().getGameState(), "starting")) { + sender.sendMessage(ChatColor.RED + "A game is already starting!"); + } + else if (Objects.equals(Game.getGame().getGameState(), "running")) { + sender.sendMessage(ChatColor.RED + "A game is already running!"); + } + else { + sender.sendMessage(ChatColor.RED + "Failed to recognize game of type " + ChatColor.GRAY + TumbleManager.getPlugin().getConfig().getString("gameMode")); + } + sender.sendMessage(ChatColor.BLUE + "Starting game, please wait."); } } // If load was unsuccessful, give feedback |