From 7ae758f3cb0f129d46331e7682130b2f326c432f Mon Sep 17 00:00:00 2001 From: Myles <43725835+MylesAndMore@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:11:05 +0000 Subject: roundEnd maybe works now wheeee also more reformatting because I will never be satisfied with my code --- src/main/java/com/MylesAndMore/tumble/Game.java | 49 ++++++++++++++----------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/tumble/Game.java index 4142aba..470b99b 100644 --- a/src/main/java/com/MylesAndMore/tumble/Game.java +++ b/src/main/java/com/MylesAndMore/tumble/Game.java @@ -4,7 +4,6 @@ import com.MylesAndMore.tumble.api.Generator; import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; import java.util.*; @@ -69,7 +68,7 @@ public class Game { // If the layer generation succeeds, give players diamond shovels giveItems(lobbyPlayers, new ItemStack(Material.DIAMOND_SHOVEL)); // Send all players from lobby to the game - teleportPlayers(lobbyPlayers); + scatterPlayers(lobbyPlayers); // Keep in mind that after this runs, this command will complete and return true } else { @@ -80,7 +79,7 @@ public class Game { roundType = gameType; if (generateLayers(gameType)) { giveItems(lobbyPlayers, new ItemStack(Material.SNOWBALL)); - teleportPlayers(lobbyPlayers); + scatterPlayers(lobbyPlayers); } else { return false; @@ -92,13 +91,13 @@ public class Game { roundType = "shovels"; generateLayers("shovels"); giveItems(lobbyPlayers, new ItemStack(Material.DIAMOND_SHOVEL)); - teleportPlayers(lobbyPlayers); + scatterPlayers(lobbyPlayers); } else { roundType = "snowballs"; generateLayers("snowballs"); giveItems(lobbyPlayers, new ItemStack(Material.SNOWBALL)); - teleportPlayers(lobbyPlayers); + scatterPlayers(lobbyPlayers); } } else { @@ -121,7 +120,7 @@ public class Game { * This method should be called on the death of one of the Game's players * @param player The player who died */ - public void playerDeath(@NotNull Player player) { + public void playerDeath(Player player) { player.setGameMode(GameMode.SPECTATOR); // If there are more than 2 players in the game, if (roundPlayers.size() > 2) { @@ -198,6 +197,11 @@ public class Game { return true; } + /** + * Distributes items to a provided list of players + * @param players The player list for which to distribute the items to + * @param itemStack The ItemStack to be distributed + */ private void giveItems(List players, ItemStack itemStack) { for (Player aPlayer : players) { // Get a singular player from the player list and give that player the specified item @@ -205,6 +209,18 @@ public class Game { } } + /** + * Sets the gamemodes of a provided list of players + * @param players The player list for which to set the gamemodes of + * @param gameMode The GameMode to set + */ + private void setGamemode(List players, GameMode gameMode) { + for (Player aPlayer : players) { + // Get a singular player from the player list and set their gamemode to the specified gamemode + aPlayer.setGameMode(gameMode); + } + } + // THIS METHOD IS DEPRECATED!! // It has been replaced by teleportPlayers(), I'm just leaving this just in case teleportPlayers() doesn't work out /** @@ -246,7 +262,7 @@ public class Game { * Teleports a list of players to the specified scatter locations in the gameWorld * @param players a List of Players to teleport */ - private void teleportPlayers(List players) { + private void scatterPlayers(List players) { // Get the coords of the game's spawn location double x = gameSpawn.getX(); double y = gameSpawn.getY(); @@ -274,16 +290,7 @@ public class Game { } } - private void setSurvival() { - for (List spectators = gamePlayers; spectators.size() > 0; spectators.remove(0)) { - // Get a singular player from the player list - Player spectatorPlayer = spectators.get(0); - // Set that player's gamemode to survival - spectatorPlayer.setGameMode(GameMode.SURVIVAL); - } - } - - private void roundEnd(@NotNull Player winner) { + private void roundEnd(Player winner) { // Set the wins of the player to their current # of wins + 1 gameWins.set(gamePlayers.indexOf(winner), (gameWins.get(gamePlayers.indexOf(winner)) + 1)); Bukkit.getServer().broadcastMessage(ChatColor.GREEN + winner.getName() + " has won the round!"); @@ -298,16 +305,16 @@ public class Game { // Re-generate layers generateLayers(gameType); // Re-scatter players - teleportPlayers(gamePlayers); + scatterPlayers(gamePlayers); // Set their gamemodes to survival - setSurvival(); + setGamemode(gamePlayers, GameMode.SURVIVAL); } } - private void gameEnd(@NotNull Player winner) { + private void gameEnd(Player winner) { Bukkit.getServer().broadcastMessage(ChatColor.GOLD + winner.getName() + " has won the game!"); // Send players back to lobby - + } } \ No newline at end of file -- cgit v1.2.3