diff options
author | Myles <43725835+MylesAndMore@users.noreply.github.com> | 2022-12-02 14:37:53 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 14:37:53 -0600 |
commit | c4fc5e933f3651dd4ee9431d19bb70f3eef5abb8 (patch) | |
tree | 3dbdb281bf3f43da3e42e3daa289eda08809ffc0 | |
parent | 12cbc14f647e9707d855dc5523a8d28c6c95d892 (diff) | |
download | Tumble-c4fc5e933f3651dd4ee9431d19bb70f3eef5abb8.tar.gz Tumble-c4fc5e933f3651dd4ee9431d19bb70f3eef5abb8.tar.bz2 Tumble-c4fc5e933f3651dd4ee9431d19bb70f3eef5abb8.zip |
begin the game object (eventual replacement for gamemanager)
also added another field in the TumbleManager for getting the game type
Diffstat (limited to '')
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/Game.java | 99 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/TumbleManager.java | 1 |
2 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/tumble/Game.java new file mode 100644 index 0000000..dcc3a78 --- /dev/null +++ b/src/main/java/com/MylesAndMore/tumble/Game.java @@ -0,0 +1,99 @@ +package com.MylesAndMore.tumble; + +import com.MylesAndMore.tuble.TumbleManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.Location; +import org.bukkit.World; + +import Java.util.Arrays; +import Java.util.Collections; +import Java.util.List; + +public final class Game { + // Define the gameInstnace + private static Game gameInstance; + + // Private Game() constructor for singleton instance + private Game() { } + + // Other priate methods for getters and setters go here + + // Define local game vars + // The gameType keeps the current game type (shocker) + String gameType = null; + + // Creates a new Game + // This will return true if the game succeeds creation, and false if not + private static boolean createGame() { + if (Objects.equals(TumbleManager.getGameType(), "shovels")) { + // shovels logic + gameType = "shovels" + } + else if (Objects.equals(TumbleManager.getGameType(), "snowballs")) { + // snowballs + gameType = "snowballs" + } + else if (Objects.equals(TumbleManager.getGameType(), "mixed")) { + // mixed (choose random shovels or snowballs) + gameType = "mixed" + } + else { + // The game type in the config did not match a specified game type; return false to signify that + return false; + } + return true; + } + + private static boolean sendPlayers() { + World gameWorld = Bukkit.getWorld(TumbleManager.getGameWorld()); + // Define the game world's spawnpoint as a new Location + Location gameSpawn = new Location(gameWorld.getSpawnLocation()); + // Get the X, Y, and Z coords of that location + Location x = gameSpawn.getX(); + Location y = gameSpawn.getY(); + Location z = gameSpawn.getZ(); + // Create Locations to scatter players around the first layer + // These are just edited off the original spawn location; + // they assume that the first layer has a radius of 17 blocks (it always will w/ the current generator code) + List<Location> scatterLocations = Arrays.asList( + new Location(gameWorld, (x - 16), y, z); + new Location(gameWorld, x, y, (z - 16)); + new Location(gameWorld, (x + 16), y, z);; + new Location(gameWorld, x, y, (z + 16)) + ); + // Shuffle the location list so players don't always spawn in the same location (basically, actually scatter the locations) + Collections.shuffle(scatterLocations); + // While there are still players in the lobby, send them to the gameWorld + // This is just a way of sending everybody in the lobby to the game + for (List<Player> playersInLobby = TumbleManager.getPlayersInLobby(); playersInLobby.size() > 0; playersInLobby = TumbleManager.getPlayersInLobby() & scatterLoations.remove(0)) { + // Get a singular player from the player list + Player aPlayer = playersInLobby.get(0); + // Get a singular location from the scatter list + Location aLocation = scatterLoations.get(0); + // Teleport that player to that scatter location + aPlayer.teleport(aLocation); + } + + // Add a little break because it can take the clients a bit to load into the new world + // Then, transition to another method because this one is getting really long + // In that method: set a flag to monitor the playerDeathEvent so we know when all the players have died + // Also start music + } + + + + // Public method to get the game instance (singleton logic) + public static Game getGame() { + if (gameInstance == null) { + gameInstance = new Game(); + } + return gameInstance; + } + + // Public method to get the game type + // This is public because you aren't modifying the game, just getting its type, so there shouldn't be any conflicts + public static String getGameType() { + return gameType; + } +}
\ No newline at end of file diff --git a/src/main/java/com/MylesAndMore/tumble/TumbleManager.java b/src/main/java/com/MylesAndMore/tumble/TumbleManager.java index 0b62494..aeecd44 100644 --- a/src/main/java/com/MylesAndMore/tumble/TumbleManager.java +++ b/src/main/java/com/MylesAndMore/tumble/TumbleManager.java @@ -18,6 +18,7 @@ public class TumbleManager { public static String getPermissionMessage() { return TumbleManager.getPlugin().getConfig().getString("permissionMessage"); } public static String getGameWorld() { return TumbleManager.getPlugin().getConfig().getString("gameWorld"); } public static String getLobbyWorld() { return TumbleManager.getPlugin().getConfig().getString("lobbyWorld"); } + public static String getGameType() { return TumbleManager.getPlugin().getConfig().getString("gameType") } public static List<Player> getPlayersInGame() { return Bukkit.getServer().getWorld(TumbleManager.getGameWorld()).getPlayers(); } public static List<Player> getPlayersInLobby() { return Bukkit.getServer().getWorld(TumbleManager.getLobbyWorld()).getPlayers(); } |