diff options
| author | Myles <mylesandmore9@gmail.com> | 2024-08-01 00:45:40 -0500 | 
|---|---|---|
| committer | Myles <mylesandmore9@gmail.com> | 2024-08-01 00:45:40 -0500 | 
| commit | b9295115ff968b3d6d941ac3af91afe598420202 (patch) | |
| tree | 448cfea72c58ad9faf2e487d86ac4e72463ed7fc | |
| parent | 908e3347eafb1c5c2d214dc434b9bb0a07133444 (diff) | |
| download | Tumble-b9295115ff968b3d6d941ac3af91afe598420202.tar.gz Tumble-b9295115ff968b3d6d941ac3af91afe598420202.tar.bz2 Tumble-b9295115ff968b3d6d941ac3af91afe598420202.zip | |
standardize style and language
- standardize code style across PR
- change some language/fix typos in documentation (code + external)
20 files changed, 141 insertions, 157 deletions
| diff --git a/OG_GUIDE.md b/OG_GUIDE.md index f7302a1..da75d93 100644 --- a/OG_GUIDE.md +++ b/OG_GUIDE.md @@ -16,7 +16,7 @@ In this guide, I'll go over how to set up the Tumble plugin with the original ga      Tip: set a specific directory to store your worlds in with the `world-container` setting in `bukkit.yml` -3. Set `level-name` in server.properities to `lobby` +3. Set `level-name` in server.properties to `lobby`  4. Take note of the names of the world folders, we will need this in a moment.  5. Start and join your server.  6. Import your arena worlds. This can be done with the multiverse command `/mv import <your-world-name> normal` @@ -93,25 +93,25 @@ In this guide, I'll go over how to set up the Tumble plugin with the original ga           z: -340.5           world: lobby     ``` -8. Reload the plugin with `/tmbl reload`. +8. Reload the plugin with `/tumble reload`. -9. Join the game using `/tmbl join basic mixed` +9. Join the game using `/tumble join basic mixed`  (swap the arena and game type for whichever one you want to play).  You're done! Happy playing!  ## Recommended plugins +These plugins, while not required, can help to provide a more thorough minigame experience. +  - [WorldGuard](https://dev.bukkit.org/projects/worldguard) and [CyberWorldReset](https://www.spigotmc.org/resources/cyberworldreset-standard-%E2%9C%A8-regenerate-worlds-scheduled-resets-lag-optimized%E3%80%8C1-8-1-19%E3%80%8D.96834/) -Protect players from breaking blocks in the lobby and reset any redstone they activated. +   - Protect players from breaking blocks in the lobby and reset any redstone they activated.  - [ViaVersion](https://www.spigotmc.org/resources/viaversion.19254/) and [ViaBackwards](https://www.spigotmc.org/resources/viabackwards.27448/) -Allow older and newer clients to connect to your server. +   - Allow older and newer players to connect to your server.  - [Geyser](https://geysermc.org/download#geyser) and [Floodgate](https://geysermc.org/download#floodgate) -Allow Bedrock clients to connect to your server. - -- [ProtectEnviromnemt](https://www.spigotmc.org/resources/protectenvironment.82736/) -Stop water and lava flow (useful for Halloween map) - +   - Allow Bedrock clients to connect to your server. +- [ProtectEnvironment](https://www.spigotmc.org/resources/protectenvironment.82736/) +   - Stop water and lava flow (useful for Halloween map). @@ -11,73 +11,73 @@ But in Tumble, you play on randomly generated layers of blocks, using shovels, s  ## Features   -- Choose from three different game modes present in the original game: shovels, snowballs, and mixed   -- Four types of random layer generation   +- Choose from three different game modes present in the original game: shovels, snowballs, and mixed +- Four types of random layer generation  - 15 unique, themed layer varieties  - Quick and easy setup and use -- Support for 2-8 players   -- Highly customizable   -- Open-source codebase   +- Support for 2-8 players  - Multiple arenas and concurrent games -- Heavily configurable +- Highly customizable, heavily configurable +- Open-source codebase  ## Setup -1. [Download](https://github.com/MylesAndMore/tmbl/releases) the plugin's JAR file and place it in your server's plugins directory. +1. [Download](https://github.com/MylesAndMore/tumble/releases) the plugin's JAR file and place it in your server's plugins directory.  2. Place the worlds for your lobby and arenas in your server's worlds directory.      - If you would like an experience similar to the original game, see [my guide](OG_GUIDE.md) for using the original worlds.    3. Start your server.  4. Import your worlds using a plugin like Multiverse. ```/mv import myWorld normal```. -5. Create your first arena `/tmbl create myArena` -6. Set the spawn point of the arena `/tmbl setgamespawn myArena` +5. Create your first arena `/tumble create myArena` +6. Set the spawn point of the arena `/tumble setgamespawn myArena`     - **Note**: The layers will generate relative to this location. Ensure that the area is clear, 20 blocks in each direction. -7. You're done! You can now join the game ```/tmbl join myArena mixed```. +7. You're done! You can now join the game ```/tumble join myArena mixed```.  Scroll down for more options to configure your game.    ## Commands / Permissions -| Command                             | Description                                                                        | Permission              | -|-------------------------------------|------------------------------------------------------------------------------------|-------------------------| -| `/tmbl join <arenaName> [gameType]` | Join a Tumble match. Can infer game type if a game is already started in the arena | `tumble.join`           | -| `/tmbl leave`                       | Quit a Tumble match                                                                | `tumble.leave`          | -| `/tmbl forcestart [arenaName]`      | Force start a Tumble match. Can infer arena if you are in one                      | `tumble.forcestart`     | -| `/tmbl forcestop [arenaName]`       | Force stop a Tumble match. Can infer arena if you are in one                       | `tumble.forcestop`      | -| `/tmbl reload`                      | Reload the plugin's configs.                                                       | `tumble.reload`         | -| `/tmbl create <arenaName>`          | Create a new arena                                                                 | `tumble.create`         | -| `/tmbl remove <arenaName>`          | Remove an arena                                                                    | `tumble.remove`         | -| `/tmbl setgamespawn <arenaName>`    | Set game spawn to your current position                                            | `tumble.setgamespawn`   | -| `/tmbl setkillylevel <arenaName>`   | Set the arena's Y-level to kill players at to current Y coordinate                 | `tumble.setkillylevel`  | -| `/tmbl setlobby <arenaName>`        | Set the arena's lobby to current location                                          | `tumble.setlobby`       | -| `/tmbl setwaitarea <arenaName>`     | Set the arena's wait area to the current location                                  | `tumble.setwaitarea`    | -| `/tmbl setwinnerlobby <arenaName>`  | Set the arena's lobby to the current location                                      | `tumble.setwinnerlobby` | - +| Command                               | Description                                                                         | Permission              | +|---------------------------------------|-------------------------------------------------------------------------------------|-------------------------| +| `/tumble join <arenaName> [gameType]` | Join a Tumble match. Can infer game type if a game is already started in the arena. | `tumble.join`           | +| `/tumble leave`                       | Leave a Tumble match.                                                               | `tumble.leave`          | +| `/tumble forcestart [arenaName]`      | Force start a Tumble match. Can infer arena if you are in one.                      | `tumble.forcestart`     | +| `/tumble forcestop [arenaName]`       | Force stop a Tumble match. Can infer arena if you are in one.                       | `tumble.forcestop`      | +| `/tumble reload`                      | Reload the plugin's configuration.                                                  | `tumble.reload`         | +| `/tumble create <arenaName>`          | Create a new arena.                                                                 | `tumble.create`         | +| `/tumble remove <arenaName>`          | Remove an arena.                                                                    | `tumble.remove`         | +| `/tumble setgamespawn <arenaName>`    | Set the arena's game spawn to your current position.                                | `tumble.setgamespawn`   | +| `/tumble setkillylevel <arenaName>`   | Set the arena's Y-level to kill players at to current Y coordinate.                 | `tumble.setkillylevel`  | +| `/tumble setlobby <arenaName>`        | Set the arena's lobby to current location.                                          | `tumble.setlobby`       | +| `/tumble setwaitarea <arenaName>`     | Set the arena's wait area to the current location.                                  | `tumble.setwaitarea`    | +| `/tumble setwinnerlobby <arenaName>`  | Set the arena's lobby to the current location.                                      | `tumble.setwinnerlobby` | + +Note that the `/tmbl` command can be used as a shorter alias to `/tumble`.  ## Configuration   -Configuration for this plugin is stored in three files. +Configuration for this plugin is stored in three files:  ### config.yml -Stores common settings - -| Option                     | Type              | Default value | -|----------------------------|-------------------|---------------| -| `hide-join-leave-messages` | Boolean           | `false`       | -| `wait-duration`            | Integer (seconds) | `15`          | +Stores general settings. +| Option                     | Type    | Description                                                                    | Default value | +|----------------------------|---------|--------------------------------------------------------------------------------|---------------| +| `hide-join-leave-messages` | Boolean | Hides player join and leave messages in public chat.                           | `false`       | +| `wait-duration`            | Integer | Duration (in seconds) to wait for more players to join a game before starting. | `15`          |  ### arenas.yml -Stores data for each arena. You may add and remove arenas as you wish. +Stores data about each arena. +Arenas may be added and removed as you wish, either via the commands detailed above or by editing the `arenas.yml` file directly.  Each arena can contain the following locations:  | Location                 | Description                                                                         |  |--------------------------|-------------------------------------------------------------------------------------|  | `game-spawn` **Required* | The location where players will be teleported, and the layers will generate around. | -| `wait-area`              | The location where players will be teleported to before the game begins             | -| `lobby`                  | The location where players will be teleported to after the game                     | -| `winner-lobby`           | The location where the winner will be teleported after the game                     | +| `wait-area`              | The location where players will be teleported to before the game begins.            | +| `lobby`                  | The location where players will be teleported to after the game.                    | +| `winner-lobby`           | The location where the winner will be teleported after the game.                    |  Locations are stored using the following format:  ```yaml @@ -90,21 +90,17 @@ Locations are stored using the following format:  Each arena can also contain the following option: -| Option      | Type    | Description                                                     | -|-------------|---------|-----------------------------------------------------------------| -| `kill-at-y` | Integer | When a player falls below this Y-level, they will be eliminated | +| Option      | Type    | Description                                                      | +|-------------|---------|------------------------------------------------------------------| +| `kill-at-y` | Integer | When a player falls below this Y-level, they will be eliminated. |  ### language.yml -Most of this plugin's strings are configurable through this file. (Excluding from some console errors) +Most of this plugin's messages are configurable through this file (excluding some console errors).  All plugin chat messages will have the `prefix` prepended to them.  -Colors can be added using alternate color codes: -``` -&cRed Text -``` - +Colors can be added using alternate color codes; for example, `&cRed Text` will appear red in-game.  ## Issues & Feedback   -Feel free to report any bugs, leave feedback, ask questions, or submit ideas for new features on our [GitHub issues page](https://github.com/MylesAndMore/tmbl/issues/new)!   +Feel free to report any bugs, leave feedback, ask questions, or submit ideas for new features on the Tumble [GitHub issues page](https://github.com/MylesAndMore/tumble/issues/new)!   diff --git a/src/main/java/com/MylesAndMore/Tumble/Main.java b/src/main/java/com/MylesAndMore/Tumble/Main.java index eb1c4e0..3bfa6c0 100644 --- a/src/main/java/com/MylesAndMore/Tumble/Main.java +++ b/src/main/java/com/MylesAndMore/Tumble/Main.java @@ -13,7 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;  import java.util.Objects; -public class Main extends JavaPlugin{ +public class Main extends JavaPlugin {      public static Main plugin;      @Override @@ -32,7 +32,7 @@ public class Main extends JavaPlugin{      @Override      public void onDisable() { -        // stop running games +        // Stop any running games          for (Arena a : ArenaManager.arenas.values()) {              if (a.game != null) {                  a.game.stopGame(); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java index 3953bea..29583a4 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java @@ -29,17 +29,16 @@ public class ForceStart implements SubCommand, CommandExecutor, TabCompleter {      @Override      public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { -          Game game; +          if (args.length < 1 || args[0] == null) { -            // no arena passed in, try to infer from game player is in +            // No arena passed in, try to infer from game player is in              game = ArenaManager.findGamePlayerIsIn((Player)sender);              if (game == null) {                  sender.sendMessage(LanguageManager.fromKey("missing-arena-parameter"));                  return false;              } -        } -        else { +        } else {              String arenaName = args[0];              if (!ArenaManager.arenas.containsKey(arenaName)) {                  sender.sendMessage(LanguageManager.fromKey("invalid-arena").replace("%arena%",arenaName)); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java index 37d3465..f308979 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java @@ -31,14 +31,13 @@ public class ForceStop implements SubCommand, CommandExecutor, TabCompleter {          Game game;          if (args.length < 1 || args[0] == null) { -            // no arena passed in, try to infer from game player is in +            // No arena passed in, try to infer from game player is in              game = ArenaManager.findGamePlayerIsIn((Player)sender);              if (game == null) {                  sender.sendMessage(LanguageManager.fromKey("missing-arena-parameter"));                  return false;              } -        } -        else { +        } else {              String arenaName = args[0];              if (!ArenaManager.arenas.containsKey(arenaName)) {                  sender.sendMessage(LanguageManager.fromKey("invalid-arena").replace("%arena%",arenaName)); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java index 6ce33c3..3f1a8fb 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java @@ -50,8 +50,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {              return false;          }          String arenaName = args[0]; -        if (!ArenaManager.arenas.containsKey(arenaName)) -        { +        if (!ArenaManager.arenas.containsKey(arenaName)) {              sender.sendMessage(LanguageManager.fromKey("invalid-arena").replace("%arena%", arenaName));              return false;          } @@ -59,17 +58,16 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {          Game game;          if (args.length < 2 || args[1] == null) { -            // no type specified: try to infer game type from game taking place in the arena +            // No type specified: try to infer game type from game taking place in the arena              if (arena.game == null) { -                // cant infer if no game is taking place +                // Can't infer if no game is taking place                  sender.sendMessage(LanguageManager.fromKey("specify-game-type"));                  return false;              }              game = arena.game; -        } -        else { -            // type specified +        } else { +            // Game type specified              GameType type;              switch (args[1]) {                  case "shovels", "shovel"     -> type = GameType.SHOVELS; @@ -84,9 +82,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {              if (arena.game == null) {                  // no game is taking place in this arena, start one                  game = arena.game = new Game(arena, type); -            } -            else -            { +            } else {                  // a game is taking place in this arena, check that it is the right type                  if (arena.game.type == type) {                      game = arena.game; @@ -100,7 +96,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {              }          } -        // check to make sure the arena has a game spawn +        // Check to make sure the arena has a game spawn          if (game.arena.gameSpawn == null) {              if (p.isOp()) {                  sender.sendMessage(LanguageManager.fromKey("arena-not-ready-op")); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java b/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java index 79faef9..588755f 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java @@ -29,7 +29,6 @@ public class Reload implements SubCommand, CommandExecutor, TabCompleter {      @Override      public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { -          for (Arena a : ArenaManager.arenas.values()) {              if (a.game != null) {                  a.game.stopGame(); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java b/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java index 8b4f925..e7d1cf4 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java @@ -44,7 +44,7 @@ public class Tumble implements CommandExecutor, TabCompleter {              return false;          } -        // pass command action through to subCommand +        // Pass command action through to subCommand          subCmd.onCommand(sender, command, args[0], removeFirst(args));          return true;      } @@ -52,7 +52,7 @@ public class Tumble implements CommandExecutor, TabCompleter {      @Override      public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {          if (args.length == 1) { -            // show only subCommands the user has permission for +            // Show only subCommands the user has permission for              ArrayList<String> PermittedSubCmds = new ArrayList<>();              for (SubCommand subCmd: subCommands.values()) {                  if (sender.hasPermission(subCmd.getPermission())) { @@ -67,11 +67,10 @@ public class Tumble implements CommandExecutor, TabCompleter {                  return Collections.emptyList();              } -            // pass tab complete through to subCommand +            // Pass tab complete through to subCommand              if (subCommands.get(args[0]) instanceof TabCompleter tcmp) {                  return tcmp.onTabComplete(sender, command, args[0], removeFirst(args)); -            } -            else { +            } else {                  return null;              }          } diff --git a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java index ac7767a..2f21a32 100644 --- a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java +++ b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java @@ -58,12 +58,12 @@ public class ArenaManager {                  arena.waitArea = readWorld("arenas." + arenaName + ".wait-area");              } -            // validate +            // Validate arena locations              if (arena.gameSpawn == null) { -                plugin.getLogger().severe("arenas.yml: Arena " + arenaName + " is missing a game spawn, before you can join you must set it with '/tmbl setgamespawn'."); +                plugin.getLogger().severe("arenas.yml: Arena " + arenaName + " is missing a game spawn, before you can join you must set it with '/tumble setgamespawn'.");              } -            if (arena.gameSpawn == null) { -                plugin.getLogger().severe("arenas.yml: Arena " + arenaName + " is missing a lobby location. The spawn point of the default world will be used."); +            if (arena.lobby == null) { +                plugin.getLogger().warning("arenas.yml: Arena " + arenaName + " is missing a lobby location. The spawn point of the default world will be used.");              }              arenas.put(arena.name, arena); diff --git a/src/main/java/com/MylesAndMore/Tumble/config/ConfigManager.java b/src/main/java/com/MylesAndMore/Tumble/config/ConfigManager.java index 59d653a..2d2bd4c 100644 --- a/src/main/java/com/MylesAndMore/Tumble/config/ConfigManager.java +++ b/src/main/java/com/MylesAndMore/Tumble/config/ConfigManager.java @@ -27,6 +27,7 @@ public class ConfigManager {          defaultConfig = Objects.requireNonNull(config.getDefaults());          HideLeaveJoin = config.getBoolean("hide-join-leave-messages", false);          waitDuration = config.getInt("wait-duration", 15); +          validate();      } diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Arena.java b/src/main/java/com/MylesAndMore/Tumble/game/Arena.java index 71849e6..157c59c 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Arena.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Arena.java @@ -1,7 +1,6 @@  package com.MylesAndMore.Tumble.game;  import org.bukkit.Location; -import org.bukkit.World;  import org.jetbrains.annotations.NotNull;  /** diff --git a/src/main/java/com/MylesAndMore/Tumble/game/EventListener.java b/src/main/java/com/MylesAndMore/Tumble/game/EventListener.java index 9f1456e..c8331f7 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/EventListener.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/EventListener.java @@ -26,7 +26,7 @@ import java.util.Objects;  import static com.MylesAndMore.Tumble.Main.plugin;  /** - * An event listener for a game of tumble. + * An event listener for a game of Tumble.   */  public class EventListener implements Listener {      Game game; @@ -55,7 +55,7 @@ public class EventListener implements Listener {              event.setQuitMessage(null);          } -        // remove player from game if they leave during a game +        // Remove player from game if they leave during a game          if (game.gamePlayers.contains(event.getPlayer())) {              game.removePlayer(event.getPlayer());          } @@ -63,7 +63,7 @@ public class EventListener implements Listener {      @EventHandler      public void PlayerDeathEvent(PlayerDeathEvent event) { -        // inform the game that the player died and respawn them +        // Inform the game that the player died and respawn them          if (game.gamePlayers.contains(event.getEntity()) && game.gameState == GameState.RUNNING) {              game.playerDeath(event.getEntity());              Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> event.getEntity().spigot().respawn(), 10); @@ -109,8 +109,7 @@ public class EventListener implements Listener {                              event.getHitBlock().getType());                      event.getHitBlock().setType(Material.AIR);                  } -            } -            else if (event.getHitEntity() != null) { +            } else if (event.getHitEntity() != null) {                  if (event.getHitEntity() instanceof Player hitPlayer) {                      // Also cancel any knockback                      Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> hitPlayer.setVelocity(new Vector())); @@ -134,7 +133,7 @@ public class EventListener implements Listener {          if (Objects.equals(game.gameState, GameState.STARTING) && !equalPosition(event.getFrom(),event.getTo())) {              event.setCancelled(true);          } -        // kill player if they are below a Y level +        // Kill player if they are below configured Y level          if (game.arena.killAtY != null && game.gameState == GameState.RUNNING) {              if (event.getPlayer().getLocation().getY() <= game.arena.killAtY) {                  event.getPlayer().setHealth(0); @@ -226,5 +225,4 @@ public class EventListener implements Listener {                  (l1.getY() == l2.getY()) &&                  (l1.getZ() == l2.getZ());      } -  }
\ No newline at end of file diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Game.java b/src/main/java/com/MylesAndMore/Tumble/game/Game.java index e9b7223..5ccb757 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Game.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Game.java @@ -48,7 +48,7 @@ public class Game {      }      /** -     * Adds a player to the wait area. Called from /tmbl join +     * Adds a player to the wait area. Called from /tumble join       * Precondition: the game is in state WAITING       * @param p Player to add       */ @@ -62,15 +62,14 @@ public class Game {          }          if (gamePlayers.size() >= 2 && gameState == GameState.WAITING) {              autoStart(); -        } -        else { +        } else {              displayActionbar(Collections.singletonList(p), LanguageManager.fromKeyNoPrefix("waiting-for-players"));          }      }      /**       * Starts the game -     * Called from /tmbl forceStart or after the wait counter finishes +     * Called from /tumble forceStart or after the wait counter finishes       */      public void gameStart() { @@ -79,15 +78,15 @@ public class Game {              return;          } -        // cancel wait timer +        // Cancel wait timer          Bukkit.getServer().getScheduler().cancelTask(autoStartID);          autoStartID = -1; -        // register event listener +        // Register event listener          eventListener = new EventListener(this);          Bukkit.getServer().getPluginManager().registerEvents(eventListener, plugin); -        // save inventories (if not already done) +        // Save inventories (if not already done)          for (Player p : gamePlayers) {              if (!inventories.containsKey(p)) {                  inventories.put(p, p.getInventory().getContents()); @@ -107,22 +106,18 @@ public class Game {          scatterPlayers(gamePlayers);          // Put all players in spectator to prevent them from getting kicked for flying          setGamemode(gamePlayers, GameMode.SPECTATOR); -        // do it again in case they were not in the world yet -        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { -            setGamemode(gamePlayers, GameMode.SPECTATOR); -        }, 10); +        // Do it again in a bit in case they were not in the world yet +        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> setGamemode(gamePlayers, GameMode.SPECTATOR), 10);          clearInventories(gamePlayers);          clearArena();          prepareGameType(type);          // Begin the countdown sequence -        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { -            countdown(() -> { -                setGamemode(gamePlayers, GameMode.SURVIVAL); -                gameState = GameState.RUNNING; -            }); -        }, 100); +        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> countdown(() -> { +            setGamemode(gamePlayers, GameMode.SURVIVAL); +            gameState = GameState.RUNNING; +        }), 100);      }      /** @@ -140,7 +135,7 @@ public class Game {                  giveItems(gamePlayers, shovel);                  // Schedule a process to give snowballs after 2m30s (so people can't island, the OG game had this); -                // add 160t because of the countdown +                // Also add 160t because of the countdown                  gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {                      clearInventories(gamePlayers);                      giveItems(gamePlayers, new ItemStack(Material.SNOWBALL)); @@ -191,13 +186,11 @@ public class Game {              if (gameWins.get(winner) == 3) {                  gameEnd(); -            } -            else { // If that player doesn't have three wins, nobody else does, so we need another round +            } else { // If that player doesn't have three wins, nobody else does, so we need another round                  displayTitles(gamePlayers, LanguageManager.fromKeyNoPrefix("round-over"), LanguageManager.fromKeyNoPrefix("round-winner").replace("%winner%", winner.getDisplayName()), 5, 60, 5);                  Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, this::roundStart, 100);              } -        } -        else { +        } else {              displayTitles(gamePlayers, LanguageManager.fromKeyNoPrefix("round-over"), LanguageManager.fromKeyNoPrefix("round-draw"), 5, 60, 5);              Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, this::roundStart, 100);          } @@ -207,13 +200,12 @@ public class Game {       * Ends game: Displays overall winner and teleports players to lobby       */      private void gameEnd() { -          if (!gamePlayers.isEmpty()) {              setGamemode(gamePlayers, GameMode.SPECTATOR);              clearInventories(gamePlayers); -            // display winner +            // Display winner              Player winner = getPlayerWithMostWins(gameWins);              if (winner != null) {                  displayTitles(gamePlayers, LanguageManager.fromKeyNoPrefix("game-over"), LanguageManager.fromKeyNoPrefix("game-winner").replace("%winner%",winner.getDisplayName()), 5, 60, 5); @@ -231,8 +223,7 @@ public class Game {                      p.setGameMode(GameMode.SURVIVAL);                      if (p == winner && arena.winnerLobby != null) {                          p.teleport(arena.winnerLobby); -                    } -                    else { +                    } else {                          p.teleport(Objects.requireNonNull(arena.lobby));                      } @@ -254,7 +245,7 @@ public class Game {      /**       * Stops the game, usually while it is still going -     * called if too many players leave, or from /tmbl forceStop +     * Called if too many players leave, or from /tumble forceStop       */      public void stopGame() {          gamePlayers.forEach(this::removePlayer); @@ -275,15 +266,15 @@ public class Game {      public void removePlayer(Player p) {          gamePlayers.remove(p); -        // check if the game has not started yet +        // Check if the game has not started yet          if (gameState == GameState.WAITING) { -            // inform player that there are no longer enough players to start +            // Inform player that there are no longer enough players to start              if (gamePlayers.size() < 2) {                  displayActionbar(gamePlayers, LanguageManager.fromKeyNoPrefix("waiting-for-players"));              } -            // teleport player back and restore inventory +            // Teleport player back and restore inventory              if (arena.waitArea != null) {                  p.getInventory().clear();                  p.setGameMode(GameMode.SURVIVAL); @@ -292,14 +283,12 @@ public class Game {                      p.getInventory().setContents(inventories.get(p));                  }              } -        } -        else { -            // stop the game if there are not enough players +        } else { +            // Stop the game if there are not enough players              if (gamePlayers.size() < 2) {                  stopGame();              } -            // teleport player back and restore inventory              p.getInventory().clear();              p.setGameMode(GameMode.SURVIVAL);              p.teleport(arena.lobby); @@ -329,7 +318,7 @@ public class Game {       */      public void playerDeath(Player player) {          player.setGameMode(GameMode.SPECTATOR); -        // remove that player (who just died) from the roundPlayersArray, effectively eliminating them, +        // Remove that player (who just died) from the alive players, effectively eliminating them,          playersAlive.remove(player);          // If there are less than 2 players in the game (1 just died),          if (playersAlive.size() < 2 && gameState == GameState.RUNNING) { @@ -337,7 +326,7 @@ public class Game {          }      } -    // utility functions +    // -- Utility functions --      /**       * Teleports a list of players to the specified scatter locations in the gameWorld diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Generator.java b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java index c8ecb06..d91c9e6 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Generator.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java @@ -6,6 +6,8 @@ import org.bukkit.block.BlockFace;  import java.util.*; +// TODO: clean up generator (when layers refactor is done) +  /**   * Holds the methods that generate blocks in-game such as cylinders, cuboids, and block clumps.   */ @@ -24,12 +26,10 @@ public class Generator {          if (random.nextInt(4) == 0) {              // Circular layer              Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.SNOW_BLOCK), layers.getSafeMaterialList()); -        } -        else if (random.nextInt(4) == 1) { +        } else if (random.nextInt(4) == 1) {              // Square layer              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.SNOW_BLOCK), layers.getSafeMaterialList()); -        } -        else if (random.nextInt(4) == 2) { +        } else if (random.nextInt(4) == 2) {              // Multi-tiered circle              Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.SNOW_BLOCK), layers.getSafeMaterialList());              Generator.generateLayer(layer, 13, 1, Material.AIR); @@ -38,8 +38,7 @@ public class Generator {              Generator.generateLayer(layer, 4, 1, Material.AIR);              layer.setY(layer.getY() - 1);              Generator.generateClumps(Generator.generateLayer(layer, 4, 1, Material.PODZOL), layers.getMaterialList()); -        } -        else { +        } else {              // Multi-tiered square              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.SNOW_BLOCK), layers.getSafeMaterialList());              Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 13, layer.getY(), layer.getZ() - 13), new Location(layer.getWorld(), layer.getX() + 13, layer.getY(), layer.getZ() + 13), Material.AIR); @@ -68,16 +67,14 @@ public class Generator {              Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.STONE), layers.getMaterialList());              layer.setY(layer.getY() - 6);              Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.STONE), layers.getMaterialList()); -        } -        else if (random.nextInt(4) == 1) { +        } else if (random.nextInt(4) == 1) {              // Square layer              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.STONE), layers.getSafeMaterialList());              layer.setY(layer.getY() - 6);              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.STONE), layers.getMaterialList());              layer.setY(layer.getY() - 6);              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.STONE), layers.getMaterialList()); -        } -        else if (random.nextInt(4) == 2) { +        } else if (random.nextInt(4) == 2) {              // Multi-tiered circle              Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.STONE), layers.getSafeMaterialList());              Generator.generateLayer(layer, 13, 1, Material.AIR); @@ -104,8 +101,7 @@ public class Generator {              Generator.generateLayer(layer, 4, 1, Material.AIR);              layer.setY(layer.getY() - 1);              Generator.generateClumps(Generator.generateLayer(layer, 4, 1, Material.LIME_GLAZED_TERRACOTTA), layers.getMaterialList()); -        } -        else { +        } else {              // Multi-tiered square              Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 17, layer.getY(), layer.getZ() - 17), new Location(layer.getWorld(), layer.getX() + 17, layer.getY(), layer.getZ() + 17), Material.STONE), layers.getSafeMaterialList());              Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 13, layer.getY(), layer.getZ() - 13), new Location(layer.getWorld(), layer.getX() + 13, layer.getY(), layer.getZ() + 13), Material.AIR); diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Layers.java b/src/main/java/com/MylesAndMore/Tumble/game/Layers.java index 8954732..1685843 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Layers.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Layers.java @@ -6,6 +6,8 @@ import java.util.ArrayList;  import java.util.List;  import java.util.Random; +// TODO: make layers user-configurable through a LayerManager and a yaml +  /**   * Stores the different types of layers that can be generated   */ @@ -284,8 +286,7 @@ public class Layers {          safeMatList.add(gen11); // Troll glass layer      } -    // Define Random class -    Random random = new Random(); +    final Random random = new Random();      /**       * @return A random predefined List of Materials that are okay to use in the clump generator       */ diff --git a/src/main/java/com/MylesAndMore/Tumble/plugin/GameState.java b/src/main/java/com/MylesAndMore/Tumble/plugin/GameState.java index 06b2abe..e27c728 100644 --- a/src/main/java/com/MylesAndMore/Tumble/plugin/GameState.java +++ b/src/main/java/com/MylesAndMore/Tumble/plugin/GameState.java @@ -4,5 +4,5 @@ public enum GameState {      WAITING,      STARTING,      RUNNING, -    ENDING +    ENDING,  } diff --git a/src/main/resources/arenas.yml b/src/main/resources/arenas.yml index 3b755c3..6d3e3bb 100644 --- a/src/main/resources/arenas.yml +++ b/src/main/resources/arenas.yml @@ -1,2 +1,2 @@ -# NOTE: Coordinates cannot be zero! Use something like 0.5 -arenas: {}
\ No newline at end of file +# NOTE: No coordinate can be equal to zero! Use 0.5 instead if needed. +arenas: {} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ded50ef..b15acaf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,5 @@ -# Hides player join/leave messages in public chat +# Hides player join and leave messages in public chat  hide-join-leave-messages: false -# Duration in seconds to wait for more players to join +# Duration (in seconds) to wait for more players to join a game before starting  wait-duration: 15 - - diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 835d577..dabb5f4 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -1,5 +1,7 @@ +# All plugin chat messages will have this message prepended to them  prefix: "&f[&eTumble&f] " +# Error messages  unknown-command: "&4Unknown command '%command%'"  no-permission: "&4You do not have permission to perform this command! &7Required permission: '%permission%.'"  missing-arena-parameter: "&4Missing arena name!" @@ -9,13 +11,14 @@ no-game-in-arena: "&4No game is currently running in this arena!"  player-not-in-game: "&4You are not in a game!"  not-for-console: "&4This cannot be run by the console!"  game-in-progress: "&4This game is still in progress!&7 wait until it finishes or join another game." -another-type-in-arena: "A game of %type% is currently taking place in this arena!&7 choose another arena or join it with '/tmbl join %arena% %type%'." +another-type-in-arena: "A game of %type% is currently taking place in this arena!&7 choose another arena or join it with '/tumble join %arena% %type%'."  already-in-game: "&4You are already in a game! Leave it to join another one."  arena-not-ready: "&4This arena is not finished being set up!" -arena-not-ready-op: "&4Incomplete arena. &7Set a game spawn with '/tmbl setGameSpawn'." +arena-not-ready-op: "&4Incomplete arena. &7Set a game spawn with '/tumble setGameSpawn'."  specify-game-type: "&4No game is currently taking place in this arena! &7Provide the game type to start one." -create-success: "&aArena created successfully! &eBefore you can join, you must set a game spawn location with '/tmbl setgamespawn'." +# Success messages +create-success: "&aArena created successfully! &eBefore you can join, you must set a game spawn location with '/tumble setgamespawn'."  forcestart-success: "&aStarting game."  forcestop-success: "&aGame stopped."  join-success: "&aJoined game &d%arena% - %type%" @@ -24,6 +27,7 @@ reload-success: "&aConfig files reloaded. &eCheck console for errors."  remove-success: "&aArena removed."  set-success: "&aLocation set." +# Game messages  showdown: "&4Showdown!"  lobby-in-10: "&9Returning to lobby in ten seconds..."  waiting-for-players: "&aWaiting for players" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c8085b8..da7f8bd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@  main: com.MylesAndMore.Tumble.Main  name: Tumble -version: 1.0.4 +version: 2.0.0  description: 'A Minecraft: Java Edition plugin recreating the Tumble minigame from Minecraft Legacy Console Edition.'  api-version: 1.16  load: POSTWORLD @@ -10,8 +10,8 @@ softdepend: [Multiverse-Core]  commands:    tumble: -    description: Base command for Rumble -    usage: "/tmbl <subCommand> ..." +    description: Base command for Tumble +    usage: "/tumble <subCommand> ..."      aliases: tmbl  permissions: @@ -22,23 +22,33 @@ permissions:      description: Allows you to leave a Tumble match.      default: true    tumble.forcestart: +    description: Allows you to forcibly start a Tumble match.      default: op    tumble.forcestop: +    description: Allows you to forcibly stop a Tumble match.      default: op    tumble.reload: +    description: Allows you to reload the Tumble configuration.      default: op    tumble.create: +    description: Allows you to create Tumble arenas.      default: op    tumble.remove: +    description: Allows you to remove Tumble arenas.      default: op    tumble.setgamespawn: +    description: Allows you to set the game spawn location for Tumble arenas.      default: op    tumble.setkillylevel: +    description: Allows you to set the kill Y-level for Tumble arenas.      default: op    tumble.setlobby: +    description: Allows you to set the lobby location for Tumble arenas.      default: op    tumble.setwaitarea: +    description: Allows you to set the wait area location for Tumble arenas.      default: op    tumble.setwinnerlobby: +    description: Allows you to set the winner lobby location for Tumble arenas.      default: op | 
