diff options
Diffstat (limited to 'src')
18 files changed, 742 insertions, 990 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/Main.java b/src/main/java/com/MylesAndMore/Tumble/Main.java index 4dd4e25..c4bb4f5 100644 --- a/src/main/java/com/MylesAndMore/tumble/Main.java +++ b/src/main/java/com/MylesAndMore/Tumble/Main.java @@ -1,39 +1,35 @@ -package com.MylesAndMore.tumble; +package com.MylesAndMore.Tumble; -import com.MylesAndMore.tumble.commands.*; -import com.MylesAndMore.tumble.api.Metrics; +import com.MylesAndMore.Tumble.commands.*; +import com.MylesAndMore.Tumble.plugin.Metrics; +import com.MylesAndMore.Tumble.plugin.Constants; +import com.MylesAndMore.Tumble.plugin.EventListener; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin{ @Override public void onEnable() { - // Register our event listener + // Register setup items getServer().getPluginManager().registerEvents(new EventListener(), this); - // Register commands - this.getCommand("reload").setExecutor(new ReloadCommand()); + this.getCommand("reload").setExecutor(new Reload()); this.getCommand("link").setExecutor(new SetWorldConfig()); this.getCommand("start").setExecutor(new StartGame()); this.getCommand("winlocation").setExecutor(new SetWinnerLoc()); this.getCommand("autostart").setExecutor(new SetAutoStart()); - // Save the default config file (packaged in the JAR) - this.saveDefaultConfig(); - - // Register bStats int pluginId = 16940; Metrics metrics = new Metrics(this, 16940); + this.saveDefaultConfig(); // Saves the default config file (packaged in the JAR) if we haven't already\ - // Check if worlds are null in config - if (TumbleManager.getGameWorld() == null) { + // Check if worlds are null in config and throw warnings if so + if (Constants.getGameWorld() == null) { Bukkit.getServer().getLogger().warning("[Tumble] It appears you have not configured a game world for Tumble."); Bukkit.getServer().getLogger().info("[Tumble] If this is your first time running the plugin, you may disregard this message."); } - if (TumbleManager.getLobbyWorld() == null) { + if (Constants.getLobbyWorld() == null) { Bukkit.getServer().getLogger().warning("[Tumble] It appears you have not configured a lobby world for Tumble."); Bukkit.getServer().getLogger().info("[Tumble] If this is your first time running the plugin, you may disregard this message."); } - - // Init message Bukkit.getServer().getLogger().info("[Tumble] Tumble successfully enabled!"); } }
\ No newline at end of file diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java b/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java new file mode 100644 index 0000000..ffc6dd8 --- /dev/null +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Reload.java @@ -0,0 +1,22 @@ +package com.MylesAndMore.Tumble.commands; + +import com.MylesAndMore.Tumble.plugin.Constants; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class Reload implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (sender.hasPermission("tumble.reload")) { + Constants.getPlugin().reloadConfig(); + sender.sendMessage(ChatColor.GREEN + "Tumble configuration reloaded successfully."); + } + else { + sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage()); + } + return true; + } +} diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java b/src/main/java/com/MylesAndMore/Tumble/commands/SetAutoStart.java index b5339b5..b3da74e 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/SetAutoStart.java @@ -1,22 +1,20 @@ -package com.MylesAndMore.tumble.commands; +package com.MylesAndMore.Tumble.commands; -import com.MylesAndMore.tumble.TumbleManager; +import com.MylesAndMore.Tumble.plugin.Constants; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; import java.util.Objects; public class SetAutoStart implements CommandExecutor{ @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if sender has perms to run command + public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (sender.hasPermission("tumble.autostart")) { - // Check if game and lobby worlds are null - if (TumbleManager.getGameWorld() != null) { - if (TumbleManager.getLobbyWorld() != null) { - // Check the amount of args entered + if (Constants.getGameWorld() != null) { + if (Constants.getLobbyWorld() != null) { if (args.length == 2) { // Check the player # argument and parse it into an int int args0; @@ -30,20 +28,19 @@ public class SetAutoStart implements CommandExecutor{ return true; } // PlayerAmount & enable/disable were entered - // Check if a playerAmount between 2-8 was entered if ((args0 >= 2) && (args0 <= 8)) { if (Objects.equals(args[1], "enable")) { // Write values to the config - TumbleManager.getPlugin().getConfig().set("autoStart.players", args0); - TumbleManager.getPlugin().getConfig().set("autoStart.enabled", true); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("autoStart.players", args0); + Constants.getPlugin().getConfig().set("autoStart.enabled", true); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Configuration saved!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } else if (Objects.equals(args[1], "disable")) { - TumbleManager.getPlugin().getConfig().set("autoStart.players", args0); - TumbleManager.getPlugin().getConfig().set("autoStart.enabled", false); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("autoStart.players", args0); + Constants.getPlugin().getConfig().set("autoStart.enabled", false); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Configuration saved!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } @@ -68,8 +65,8 @@ public class SetAutoStart implements CommandExecutor{ return true; } if ((args0 >= 2) && (args0 <= 8)) { - TumbleManager.getPlugin().getConfig().set("autoStart.players", args0); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("autoStart.players", args0); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Configuration saved!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } @@ -90,7 +87,7 @@ public class SetAutoStart implements CommandExecutor{ } } else { - sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage()); + sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage()); } return true; } diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java b/src/main/java/com/MylesAndMore/Tumble/commands/SetWinnerLoc.java index ec145d1..38e6444 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/SetWinnerLoc.java @@ -1,6 +1,6 @@ -package com.MylesAndMore.tumble.commands; +package com.MylesAndMore.Tumble.commands; -import com.MylesAndMore.tumble.TumbleManager; +import com.MylesAndMore.Tumble.plugin.Constants; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; @@ -8,15 +8,13 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class SetWinnerLoc implements CommandExecutor { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if sender has perms to run command + public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (sender.hasPermission("tumble.winlocation")) { - // Check if the lobby world has been configured - if (TumbleManager.getLobbyWorld() != null) { - // Check if the sender is a player + if (Constants.getLobbyWorld() != null) { if (sender instanceof Player) { // Check the sender entered the correct number of args if (args.length == 3) { @@ -32,12 +30,12 @@ public class SetWinnerLoc implements CommandExecutor { } catch (Exception e){ sender.sendMessage(ChatColor.RED + "Invalid input arguments."); } - // Check if any of the args were 0 (this will cause future problems so we prevent it here) + // Check if any of the args were 0 (this will cause future problems, so we prevent it here) if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) { - TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("winnerTeleport.x", args0); + Constants.getPlugin().getConfig().set("winnerTeleport.y", args1); + Constants.getPlugin().getConfig().set("winnerTeleport.z", args2); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Win location successfully set!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } @@ -52,10 +50,10 @@ public class SetWinnerLoc implements CommandExecutor { // if so, check if any of their locations are zero if (!((senderPos.getX() == 0) || (senderPos.getY() == 0) || (senderPos.getZ() == 0))) { // set the config values to their current pos - TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", senderPos.getX()); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", senderPos.getY()); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", senderPos.getZ()); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("winnerTeleport.x", senderPos.getX()); + Constants.getPlugin().getConfig().set("winnerTeleport.y", senderPos.getY()); + Constants.getPlugin().getConfig().set("winnerTeleport.z", senderPos.getZ()); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Win location successfully set!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } @@ -68,9 +66,7 @@ public class SetWinnerLoc implements CommandExecutor { return false; } } - // Check if the sender is the console else if (sender instanceof ConsoleCommandSender) { - // Check if the correct # of args were entered if (args.length == 3) { double args0 = 0; double args1 = 0; @@ -84,12 +80,11 @@ public class SetWinnerLoc implements CommandExecutor { } catch (Exception e){ sender.sendMessage(ChatColor.RED + "Invalid input arguments."); } - // Check if any of the args were 0 (this will cause future problems so we prevent it here) if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) { - TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1); - TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2); - TumbleManager.getPlugin().saveConfig(); + Constants.getPlugin().getConfig().set("winnerTeleport.x", args0); + Constants.getPlugin().getConfig().set("winnerTeleport.y", args1); + Constants.getPlugin().getConfig().set("winnerTeleport.z", args2); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Win location successfully set!"); sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect."); } @@ -108,7 +103,7 @@ public class SetWinnerLoc implements CommandExecutor { } } else { - sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage()); + sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage()); } return true; } diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java b/src/main/java/com/MylesAndMore/Tumble/commands/SetWorldConfig.java index 695c248..90e0a96 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/SetWorldConfig.java @@ -1,58 +1,52 @@ -package com.MylesAndMore.tumble.commands; +package com.MylesAndMore.Tumble.commands; -import com.MylesAndMore.tumble.TumbleManager; +import com.MylesAndMore.Tumble.plugin.Constants; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameRule; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; import java.util.Objects; public class SetWorldConfig implements CommandExecutor { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { // Catch for null arguments if (args.length == 2) { - // Check if sender has perms to run command if (sender.hasPermission("tumble.link")){ // Initialize vars for their respective command arguments String world = args[0]; String worldType = args[1]; - // Check if the world type is lobby if (Objects.equals(worldType, "lobby")) { // Check if the world is actually a world on the server if (Bukkit.getWorld(world) != null) { // Check if the world has already been configured - if (!Objects.equals(TumbleManager.getGameWorld(), world)) { + if (!Objects.equals(Constants.getGameWorld(), world)) { // Set the specified value of the world in the config under lobbyWorld - TumbleManager.getPlugin().getConfig().set("lobbyWorld", world); - // Save said config - TumbleManager.getPlugin().saveConfig(); - // Feedback + Constants.getPlugin().getConfig().set("lobbyWorld", world); + Constants.getPlugin().saveConfig(); sender.sendMessage(ChatColor.GREEN + "Lobby world successfully linked: " + ChatColor.GRAY + world); sender.sendMessage(ChatColor.GREEN + "Please restart your server for the changes to take effect; " + ChatColor.RED + "reloading the plugin is insufficient!"); } - // Feedback for duplicate world configuration else { sender.sendMessage(ChatColor.RED + "That world has already been linked, please choose/create another world!"); } } - // Feedback for if the world doesn't exist else { sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + world); } } - // Check if the world type is game else if (Objects.equals(args[1], "game")) { if (Bukkit.getWorld(world) != null) { - if (!Objects.equals(TumbleManager.getLobbyWorld(), world)) { - TumbleManager.getPlugin().getConfig().set("gameWorld", world); - TumbleManager.getPlugin().saveConfig(); + if (!Objects.equals(Constants.getLobbyWorld(), world)) { + Constants.getPlugin().getConfig().set("gameWorld", world); + Constants.getPlugin().saveConfig(); // Set the gamerule of doImmediateRespawn in the gameWorld for later - Bukkit.getWorld(world).setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true); - Bukkit.getWorld(world).setGameRule(GameRule.KEEP_INVENTORY, true); + Objects.requireNonNull(Bukkit.getWorld(world)).setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true); + Objects.requireNonNull(Bukkit.getWorld(world)).setGameRule(GameRule.KEEP_INVENTORY, true); sender.sendMessage(ChatColor.GREEN + "Game world successfully linked: " + ChatColor.GRAY + world); sender.sendMessage(ChatColor.GREEN + "Please restart your server for the changes to take effect; " + ChatColor.RED + "reloading the plugin is insufficient!"); } @@ -64,17 +58,14 @@ public class SetWorldConfig implements CommandExecutor { sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + world); } } - // Feedback for if lobby or game wasn't entered else { sender.sendMessage(ChatColor.RED + "Allowed world types are " + ChatColor.GRAY + "lobby " + ChatColor.RED + "and " + ChatColor.GRAY + "game" + ChatColor.RED + "."); } } - // Feedback for if sender has no perms else { - sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage()); + sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage()); } } - // Feedback for if no args were entered else { return false; } diff --git a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java b/src/main/java/com/MylesAndMore/Tumble/commands/StartGame.java index c138cda..706b33a 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/StartGame.java @@ -1,35 +1,30 @@ -package com.MylesAndMore.tumble.commands; +package com.MylesAndMore.Tumble.commands; -import com.MylesAndMore.tumble.Game; -import com.MylesAndMore.tumble.TumbleManager; +import com.MylesAndMore.Tumble.game.Game; +import com.MylesAndMore.Tumble.plugin.Constants; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; import java.util.Objects; public class StartGame implements CommandExecutor { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if sender has perms to run command + public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (sender.hasPermission("tumble.start")) { - // Check if there is a lobbyWorld specified in config - if (TumbleManager.getLobbyWorld() != null) { - // Check if there is more than one person in lobby - if (TumbleManager.getPlayersInLobby().size() > 1) { - // Check if there is a gameWorld specified in config - if (TumbleManager.getGameWorld() != null) { - // Check if a game is already pending to start + if (Constants.getLobbyWorld() != null) { + if (Constants.getPlayersInLobby().size() > 1) { + if (Constants.getGameWorld() != null) { if (!Objects.equals(Game.getGame().getGameState(), "waiting")) { sender.sendMessage(ChatColor.BLUE + "Generating layers, please wait."); - // Use multiverse to load game world - // If the load was successful, start game - if (TumbleManager.getMVWorldManager().loadWorld(TumbleManager.getGameWorld())) { + // Use multiverse to load game world--if the load was successful, start game + if (Constants.getMVWorldManager().loadWorld(Constants.getGameWorld())) { // If there is no starting argument, if (args.length == 0) { // pull which gamemode to initiate from the config file - if (!Game.getGame().startGame(TumbleManager.getGameType())) { + if (!Game.getGame().startGame(Constants.getGameType())) { // 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!"); @@ -38,11 +33,11 @@ public class StartGame implements CommandExecutor { 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.RED + "Failed to recognize game of type " + ChatColor.GRAY + Constants.getPlugin().getConfig().getString("gameMode")); } } } - // If there was an argument for gameType, pass that into the startGame method + // If there was an argument for gameType, pass that instead else { if (!Game.getGame().startGame(args[0])) { // Sender feedback for if the game failed to start @@ -62,7 +57,7 @@ public class StartGame implements CommandExecutor { // Note: this should not occur unless the config file was edited externally, // because the plugin prevents adding "worlds" that are not actually present to the config. else { - sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + TumbleManager.getGameWorld()); + sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + Constants.getGameWorld()); sender.sendMessage(ChatColor.RED + "Is the configuration file correct?"); } } @@ -70,12 +65,10 @@ public class StartGame implements CommandExecutor { sender.sendMessage(ChatColor.RED + "A game is already queued to begin!"); } } - // Feedback for if there is no gameWorld in the config else { sender.sendMessage(ChatColor.RED + "Please link a game world first!"); } } - // Feedback for if there is only one person online else { sender.sendMessage(ChatColor.RED + "You can't start a game with yourself!"); } @@ -84,9 +77,8 @@ public class StartGame implements CommandExecutor { sender.sendMessage(ChatColor.RED + "Please link a lobby world first!"); } } - // Feedback for if the sender has no perms else { - sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage()); + sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage()); } return true; } diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/Tumble/game/Game.java index 1400887..0ea74f5 100644 --- a/src/main/java/com/MylesAndMore/tumble/Game.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Game.java @@ -1,8 +1,7 @@ -package com.MylesAndMore.tumble; +package com.MylesAndMore.Tumble.game; -import com.MylesAndMore.tumble.api.Generator; +import com.MylesAndMore.Tumble.plugin.Constants; -import com.MylesAndMore.tumble.api.Layers; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -18,20 +17,15 @@ import javax.annotation.Nullable; import java.util.*; /** - * This class holds all methods relating to the tumble Game in any way! + * Everything relating to the Tumble game */ public class Game { // Singleton class logic - // Define the gameInstance private static Game gameInstance; - - // Private Game() constructor for singleton instance private Game() { - gameWorld = Bukkit.getWorld(TumbleManager.getGameWorld()); - gameSpawn = gameWorld.getSpawnLocation(); + gameWorld = Bukkit.getWorld(Constants.getGameWorld()); + gameSpawn = Objects.requireNonNull(gameWorld).getSpawnLocation(); } - - // ONLY Public method to get the game instance public static Game getGame() { if (gameInstance == null) { gameInstance = new Game(); @@ -39,33 +33,18 @@ public class Game { return gameInstance; } - // Define local game vars - // The gameState keeps the current state of the game (I'm so creative, I know) private String gameState; - // Define a variable for the gameType private String gameType; - // Define a variable for the game ID private int gameID = -1; - // Define a variable for the autostart PID private int autoStartID = -1; - // Define a variable to keep the list of tracks that have already played in the game - List<String> sounds = new ArrayList<>(); - - // Initialize a new instance of the Random class for use later - private final Random Random = new Random(); - // Define the game world and its spawnpoint as a new Location for use later private final World gameWorld; private final Location gameSpawn; - // Make a list of the game's players for later private List<Player> gamePlayers; - // Make a list of the round's players private List<Player> roundPlayers; - // Initialize a list to keep track of wins between rounds private List<Integer> gameWins; - - // BEGIN PUBLIC METHODS + private final Random Random = new Random(); /** * Creates a new Game @@ -73,61 +52,52 @@ public class Game { * @return true if the game succeeds creation, and false if not */ public boolean startGame(@NotNull String type) { - // Check if the game is starting or running, if so, do not start - if (Objects.equals(gameState, "starting")) { - return false; - } - else if (Objects.equals(gameState, "running")) { - return false; - } + // Check if the game is starting or running + if (Objects.equals(gameState, "starting")) { return false; } + else if (Objects.equals(gameState, "running")) { return false; } else { // Define the gameType switch (type) { - case "shovels": - case "snowballs": - case "mixed": + case "shovels", "snowballs", "mixed" -> { gameState = "starting"; // Set the type to gameType since it won't change for this mode gameType = type; // Clear the players' inventories so they can't bring any items into the game - clearInventories(TumbleManager.getPlayersInLobby()); + clearInventories(Constants.getPlayersInLobby()); // Generate the correct layers for a Shovels game // The else statement is just in case the generator fails; this command will fail if (generateLayers(type)) { // Send all players from lobby to the game - scatterPlayers(TumbleManager.getPlayersInLobby()); + scatterPlayers(Constants.getPlayersInLobby()); } else { return false; } - break; - default: - // The game type in the config did not match a specified game type; return false to signify that + } + default -> { + // The game type in the config did not match a specified game type return false; + } } - // If a game creation succeeded, then, - // Update the game's players for later - gamePlayers = new ArrayList<>(TumbleManager.getPlayersInGame()); - // Update the round's players for later - roundPlayers = new ArrayList<>(TumbleManager.getPlayersInGame()); + // Update the game/round players for later + gamePlayers = new ArrayList<>(Constants.getPlayersInGame()); + roundPlayers = new ArrayList<>(Constants.getPlayersInGame()); // Create a list that will later keep track of each player's wins gameWins = new ArrayList<>(); gameWins.addAll(List.of(0,0,0,0,0,0,0,0)); - // Put all players in spectator to prevent them from getting kicked for flying (this needs a delay bc servers are SLOOOWWW) - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - setGamemode(gamePlayers, GameMode.SPECTATOR); - }, 25); + // Put all players in spectator to prevent them from getting kicked for flying (this needs a delay bc servers are slow) + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> setGamemode(gamePlayers, GameMode.SPECTATOR), 25); // Wait 5s (100t) for the clients to load in - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { // Begin the countdown sequence playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_GREEN + "3", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.YELLOW + "2", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_RED + "1", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 2); displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1); setGamemode(gamePlayers, GameMode.SURVIVAL); @@ -145,15 +115,13 @@ public class Game { */ public void autoStart() { // Wait for the player to load in - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { gameState = "waiting"; - displayActionbar(TumbleManager.getPlayersInLobby(), ChatColor.GREEN + "Game will begin in 15 seconds!"); - playSound(TumbleManager.getPlayersInLobby(), Sound.BLOCK_NOTE_BLOCK_CHIME, SoundCategory.BLOCKS, 1, 1); - TumbleManager.getMVWorldManager().loadWorld(TumbleManager.getGameWorld()); + displayActionbar(Constants.getPlayersInLobby(), ChatColor.GREEN + "Game will begin in 15 seconds!"); + playSound(Constants.getPlayersInLobby(), Sound.BLOCK_NOTE_BLOCK_CHIME, SoundCategory.BLOCKS, 1, 1); + Constants.getMVWorldManager().loadWorld(Constants.getGameWorld()); // Schedule a process to start the game in 300t (15s) and save the PID so we can cancel it later if needed - autoStartID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - startGame(TumbleManager.getGameType()); - }, 300); + autoStartID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> startGame(Constants.getGameType()), 300); }, 50); } @@ -162,8 +130,8 @@ public class Game { */ public void cancelStart() { Bukkit.getServer().getScheduler().cancelTask(Game.getGame().getAutoStartID()); - displayActionbar(TumbleManager.getPlayersInLobby(), ChatColor.RED + "Game start cancelled!"); - playSound(TumbleManager.getPlayersInLobby(), Sound.BLOCK_NOTE_BLOCK_BASS, SoundCategory.BLOCKS, 1, 1); + displayActionbar(Constants.getPlayersInLobby(), ChatColor.RED + "Game start cancelled!"); + playSound(Constants.getPlayersInLobby(), Sound.BLOCK_NOTE_BLOCK_BASS, SoundCategory.BLOCKS, 1, 1); gameState = null; autoStartID = -1; } @@ -174,19 +142,16 @@ public class Game { */ public void playerDeath(Player player) { player.setGameMode(GameMode.SPECTATOR); - // Add a delay to tp them to the gameWorld just in case they have a bed in another world - // Delay is needed because instant respawn takes 1t - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + // Add a delay to tp them to the gameWorld just in case they have a bed in another world (yes you Jacob) + // Delay is needed because instant respawn is a lie (it's not actually instant) + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { player.teleport(gameSpawn); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - player.setGameMode(GameMode.SPECTATOR); - }, 5); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> player.setGameMode(GameMode.SPECTATOR), 5); }, 5); // remove that player (who just died) from the roundPlayersArray, effectively eliminating them, roundPlayers.remove(player); // If there are less than 2 players in the game (1 just died), if (roundPlayers.size() < 2) { - // End the game, passing the winner to the gameEnd method roundEnd(roundPlayers.get(0)); } } @@ -201,14 +166,11 @@ public class Game { /** * @return The Bukkit process ID of the autostart process, if applicable - * Can also be null if not initialized, and -1 if the process failed to schedule. + * Can also be null if not initialized, or -1 if the process failed to schedule. */ public int getAutoStartID() { return autoStartID; } - // BEGIN PRIVATE METHODS - - // Initialize Layers class private final Layers layers = new Layers(); /** * Generates the layers in the gameWorld for a certain gameType @@ -252,22 +214,19 @@ public class Game { ItemStack shovel = new ItemStack(Material.IRON_SHOVEL); shovel.addEnchantment(Enchantment.SILK_TOUCH, 1); if (Objects.equals(gameState, "running")) { - giveItems(TumbleManager.getPlayersInGame(), shovel); + giveItems(Constants.getPlayersInGame(), shovel); } else if (Objects.equals(gameState, "starting")) { - giveItems(TumbleManager.getPlayersInLobby(), shovel); + giveItems(Constants.getPlayersInLobby(), 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 - gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + // Schedule a process to give snowballs after 2m30s (so people can't island, the OG game had this); add 160t because of the countdown + gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { clearInventories(gamePlayers); giveItems(gamePlayers, new ItemStack(Material.SNOWBALL)); displayActionbar(gamePlayers, ChatColor.DARK_RED + "Showdown!"); playSound(gamePlayers, Sound.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.HOSTILE, 1, 1); // End the round in another 2m30s - gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - roundEnd(null); - }, 3000); + gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> roundEnd(null), 3000); }, 3160); } else if (Objects.equals(type, "snowballs")) { @@ -346,13 +305,13 @@ public class Game { Generator.generateClumps(Generator.generateCuboid(new Location(layer.getWorld(), layer.getX() - 7, layer.getY(), layer.getZ() - 7), new Location(layer.getWorld(), layer.getX() + 7, layer.getY(), layer.getZ() + 7), Material.LIME_GLAZED_TERRACOTTA), layers.getMaterialList()); } if (Objects.equals(gameState, "running")) { - giveItems(TumbleManager.getPlayersInGame(), new ItemStack(Material.SNOWBALL)); + giveItems(Constants.getPlayersInGame(), new ItemStack(Material.SNOWBALL)); } else if (Objects.equals(gameState, "starting")) { - giveItems(TumbleManager.getPlayersInLobby(), new ItemStack(Material.SNOWBALL)); + giveItems(Constants.getPlayersInLobby(), new ItemStack(Material.SNOWBALL)); } // End the round in 5m - gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> roundEnd(null), 6160); + gameID = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> roundEnd(null), 6160); } else if (Objects.equals(type, "mixed")) { // Randomly select either shovels or snowballs and re-run the method @@ -376,7 +335,6 @@ public class Game { */ private void giveItems(List<Player> players, ItemStack itemStack) { for (Player aPlayer : players) { - // Get a singular player from the player list and give that player the specified item aPlayer.getInventory().addItem(itemStack); } } @@ -398,7 +356,6 @@ public class Game { */ private void setGamemode(List<Player> 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); } } @@ -414,7 +371,6 @@ public class Game { */ private void displayTitles(List<Player> players, String title, @Nullable String subtitle, int fadeIn, int stay, int fadeOut) { for (Player aPlayer : players) { - // Get a singular player from the player list and display them the specified title aPlayer.sendTitle(title, subtitle, fadeIn, stay, fadeOut); } } @@ -449,7 +405,6 @@ public class Game { * @param players a List of Players to teleport */ private void scatterPlayers(List<Player> players) { - // Get the coords of the game's spawn location double x = gameSpawn.getX(); double y = gameSpawn.getY(); double z = gameSpawn.getZ(); @@ -463,14 +418,10 @@ public class Game { new Location(gameWorld, (x - 10.5), y, (z + 11.5), -135, 0), new Location(gameWorld, (x + 11.5), y, (z - 10.5), 45, 0), new Location(gameWorld, (x + 11.5), y, (z + 11.5), 135, 0))); - // Shuffle the list (randomize) Collections.shuffle(scatterLocations); - // While there are still unteleported players from the list, teleport them for (Player aPlayer : players) { - // Select a singular player and singular location from the lists and teleport that player aPlayer.teleport(scatterLocations.get(0)); - // Remove that location so multiple players won't get the same one - scatterLocations.remove(0); + scatterLocations.remove(0); // Remove that location so multiple players won't get the same one } } @@ -495,30 +446,28 @@ public class Game { roundPlayers.addAll(gamePlayers); clearInventories(gamePlayers); displayTitles(gamePlayers, ChatColor.RED + "Round over!", ChatColor.GOLD + winner.getName() + " has won the round!", 5, 60, 5); - // Wait for player to respawn before completely l a g g i n g the server ._. - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - // Re-generate layers + // Wait for the player to respawn before completely lagging the server ._. + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { generateLayers(gameType); // Wait 5s (100t) for tp method - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { // Kill all items (pistons are weird) for (Entity entity : gameWorld.getEntities()) { if (entity instanceof Item) { entity.remove(); } } - // Re-scatter players gameState = "starting"; scatterPlayers(gamePlayers); playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_GREEN + "3", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.YELLOW + "2", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_RED + "1", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 2); displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1); setGamemode(gamePlayers, GameMode.SURVIVAL); @@ -532,34 +481,29 @@ public class Game { } else { setGamemode(gamePlayers, GameMode.SPECTATOR); - roundPlayers.removeAll(roundPlayers); + roundPlayers.clear(); roundPlayers.addAll(gamePlayers); clearInventories(gamePlayers); displayTitles(gamePlayers, ChatColor.RED + "Round over!", ChatColor.GOLD + "Draw!", 5, 60, 5); - // Wait for player to respawn before completely l a g g i n g the server ._. - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - // Re-generate layers + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { generateLayers(gameType); - // Wait 5s (100t) for tp method - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - // Kill all items (pistons are weird) + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { for (Entity entity : gameWorld.getEntities()) { if (entity instanceof Item) { entity.remove(); } } - // Re-scatter players gameState = "starting"; scatterPlayers(gamePlayers); playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_GREEN + "3", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.YELLOW + "2", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 1); displayTitles(gamePlayers, ChatColor.DARK_RED + "1", null, 3, 10, 7); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 5, 2); displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1); setGamemode(gamePlayers, GameMode.SURVIVAL); @@ -575,21 +519,19 @@ public class Game { private void gameEnd(Player winner) { winner.setGameMode(GameMode.SPECTATOR); clearInventories(gamePlayers); - // Announce win displayTitles(gamePlayers, ChatColor.RED + "Game over!", ChatColor.GOLD + winner.getName() + " has won the game!", 5, 60, 5); displayActionbar(gamePlayers, ChatColor.BLUE + "Returning to lobby in ten seconds..."); // Wait 10s (200t), then - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> { // First, check to see if there is a separate location to tp the winner to - if ((TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.x") != 0) && (TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.y") != 0) && (TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.z") != 0)) { - // Tp the winner to that location - winner.teleport(new Location(Bukkit.getWorld(TumbleManager.getLobbyWorld()), TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.x"), TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.y"), TumbleManager.getPlugin().getConfig().getDouble("winnerTeleport.z"))); + if ((Constants.getPlugin().getConfig().getDouble("winnerTeleport.x") != 0) && (Constants.getPlugin().getConfig().getDouble("winnerTeleport.y") != 0) && (Constants.getPlugin().getConfig().getDouble("winnerTeleport.z") != 0)) { + winner.teleport(new Location(Bukkit.getWorld(Constants.getLobbyWorld()), Constants.getPlugin().getConfig().getDouble("winnerTeleport.x"), Constants.getPlugin().getConfig().getDouble("winnerTeleport.y"), Constants.getPlugin().getConfig().getDouble("winnerTeleport.z"))); // Remove the winner from the gamePlayers so they don't get double-tp'd gamePlayers.remove(winner); } // Send all players back to lobby (spawn) for (Player aPlayer : gamePlayers) { - aPlayer.teleport(Bukkit.getWorld(TumbleManager.getLobbyWorld()).getSpawnLocation()); + aPlayer.teleport(Objects.requireNonNull(Bukkit.getWorld(Constants.getLobbyWorld())).getSpawnLocation()); } }, 200); gameState = "complete"; diff --git a/src/main/java/com/MylesAndMore/tumble/api/Generator.java b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java index db8bacc..ecaa1b7 100644 --- a/src/main/java/com/MylesAndMore/tumble/api/Generator.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java @@ -1,4 +1,4 @@ -package com.MylesAndMore.tumble.api; +package com.MylesAndMore.Tumble.game; import org.bukkit.Location; import org.bukkit.Material; @@ -6,24 +6,20 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; +import java.util.*; /** - * This class holds the methods that generate blocks in-game such as cylinders, cubiods, and clump logic. + * Holds the methods that generate blocks in-game such as cylinders, cuboids, and block clumps. */ public class Generator { /** - * Generates a layer (bascally just a cylinder) as best as it can w/ blocks - * - * @return A list of Blocks containing all the blocks it just changed - * + * Generates a layer (basically just a cylinder) as good as possible with blocks * @param center The center of the layer (Location) * @param radius The whole number radius of the circle * @param height The whole number height of the circle (1 for a flat layer) * @param material The Material to use for generation + * + * @return A list of Blocks containing all the blocks it just changed */ public static List<Block> generateLayer(Location center, int radius, int height, Material material) { int Cx = center.getBlockX(); @@ -38,7 +34,7 @@ public class Generator { for (int x = Cx - radius; x <= Cx + radius; x++) { for (int z = Cz - radius; z <= Cz + radius; z++) { if ((Cx - x) * (Cx - x) + (Cz - z) * (Cz - z) <= rSq) { - world.getBlockAt(x, y, z).setType(material); + Objects.requireNonNull(world).getBlockAt(x, y, z).setType(material); blocks.add(world.getBlockAt(x, y, z)); } } @@ -48,7 +44,7 @@ public class Generator { } /** - * Generates a cubiod (literally just a ripoff fill command) + * Generates a cuboid (literally just a ripoff fill command) * @param firstPos The first Location to fill (first three coords in a fill command) * @param secondPos The second Location to fill to (second three coords) * @param material The Material to fill @@ -66,7 +62,7 @@ public class Generator { for (int x = fX; x <= sX; x++) { for (int y = fY; y <= sY; y++) { for (int z = fZ; z <= sZ; z++) { - world.getBlockAt(x, y, z).setType(material); + Objects.requireNonNull(world).getBlockAt(x, y, z).setType(material); blocks.add(world.getBlockAt(x, y, z)); } } @@ -82,22 +78,16 @@ public class Generator { * More Materials = more randomization */ public static void generateClumps(List<Block> blockList, List<Material> materialList) { - // Define random class Random random = new Random(); - // Define new blocks list so we can manipulate it + // Make new lists so we can manipulate them List<Block> blocks = new ArrayList<>(blockList); - // Define new shuffled Materials list List<Material> materials = new ArrayList<>(materialList); Collections.shuffle(materials); - // This loop will run until there are no blocks left to change while (blocks.size() > 0) { - // Get a random Material from the provided materials list Material randomMaterial = materials.get(random.nextInt(materials.size())); - // Gets the first Block from the list, to modify Block aBlock = blocks.get(0); - // Modifies the block aBlock.setType(randomMaterial); - // Get the blocks around that and change it to that same material + // Get the blocks around that and change it to that same material (this is the basis of "clumps") if (blocks.contains(aBlock.getRelative(BlockFace.NORTH))) { aBlock.getRelative(BlockFace.NORTH).setType(randomMaterial); blocks.remove(aBlock.getRelative(BlockFace.NORTH)); diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Layers.java b/src/main/java/com/MylesAndMore/Tumble/game/Layers.java new file mode 100644 index 0000000..ed92dc9 --- /dev/null +++ b/src/main/java/com/MylesAndMore/Tumble/game/Layers.java @@ -0,0 +1,314 @@ +package com.MylesAndMore.Tumble.game; + +import org.bukkit.Material; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * Stores the different types of layers that can be generated + */ +public class Layers { + + public Layers() { + List<Material> gen2 = new ArrayList<>() {{ + add(Material.PINK_TERRACOTTA); + add(Material.PURPLE_TERRACOTTA); + add(Material.GRAY_TERRACOTTA); + add(Material.BLUE_TERRACOTTA); + add(Material.LIGHT_BLUE_TERRACOTTA); + add(Material.WHITE_TERRACOTTA); + add(Material.BROWN_TERRACOTTA); + add(Material.GREEN_TERRACOTTA); + add(Material.YELLOW_TERRACOTTA); + add(Material.PINK_TERRACOTTA); + add(Material.PURPLE_TERRACOTTA); + add(Material.GRAY_TERRACOTTA); + add(Material.BLUE_TERRACOTTA); + add(Material.LIGHT_BLUE_TERRACOTTA); + add(Material.WHITE_TERRACOTTA); + add(Material.BROWN_TERRACOTTA); + add(Material.GREEN_TERRACOTTA); + add(Material.YELLOW_TERRACOTTA); + add(Material.WHITE_STAINED_GLASS); + add(Material.HONEYCOMB_BLOCK); + add(Material.HONEYCOMB_BLOCK); + }}; + List<Material> gen4 = new ArrayList<>() {{ + add(Material.DIAMOND_BLOCK); + add(Material.GOLD_BLOCK); + add(Material.REDSTONE_BLOCK); + add(Material.REDSTONE_BLOCK); + add(Material.LAPIS_BLOCK); + add(Material.LAPIS_BLOCK); + add(Material.IRON_BLOCK); + add(Material.COAL_BLOCK); + add(Material.IRON_BLOCK); + add(Material.COAL_BLOCK); + add(Material.IRON_BLOCK); + add(Material.COAL_BLOCK); + add(Material.COAL_BLOCK); + }}; + List<Material> gen5 = new ArrayList<>() {{ + add(Material.WHITE_TERRACOTTA); + add(Material.BLUE_ICE); + add(Material.SOUL_SAND); + add(Material.STONE_SLAB); + add(Material.WHITE_TERRACOTTA); + add(Material.BLUE_ICE); + add(Material.SOUL_SAND); + add(Material.STONE_SLAB); + add(Material.WHITE_TERRACOTTA); + add(Material.BLUE_ICE); + add(Material.SOUL_SAND); + add(Material.STONE_SLAB); + add(Material.GLOWSTONE); + add(Material.GLOWSTONE); + add(Material.HONEY_BLOCK); + add(Material.SLIME_BLOCK); + }}; + List<Material> gen7 = new ArrayList<>() {{ + add(Material.END_STONE); + add(Material.END_STONE_BRICKS); + add(Material.END_STONE); + add(Material.END_STONE_BRICKS); + add(Material.END_STONE); + add(Material.END_STONE_BRICKS); + add(Material.END_STONE); + add(Material.END_STONE_BRICKS); + add(Material.OBSIDIAN); + add(Material.PURPUR_BLOCK); + add(Material.PURPUR_PILLAR); + add(Material.COBBLESTONE); + }}; + List<Material> gen9 = new ArrayList<>() {{ + add(Material.PRISMARINE); + add(Material.DARK_PRISMARINE); + add(Material.BLUE_STAINED_GLASS); + add(Material.WET_SPONGE); + add(Material.PRISMARINE_BRICKS); + add(Material.PRISMARINE_BRICK_SLAB); + add(Material.DARK_PRISMARINE); + add(Material.SEA_LANTERN); + add(Material.TUBE_CORAL_BLOCK); + add(Material.BRAIN_CORAL_BLOCK); + add(Material.BUBBLE_CORAL_BLOCK); + }}; + List<Material> gen10 = new ArrayList<>() {{ + add(Material.OAK_LOG); + add(Material.SPRUCE_LOG); + add(Material.ACACIA_LOG); + add(Material.STRIPPED_OAK_LOG); + add(Material.STRIPPED_SPRUCE_LOG); + add(Material.STRIPPED_ACACIA_LOG); + add(Material.OAK_WOOD); + add(Material.SPRUCE_WOOD); + add(Material.ACACIA_WOOD); + add(Material.OAK_LEAVES); + add(Material.SPRUCE_LEAVES); + add(Material.ACACIA_LEAVES); + add(Material.OAK_LEAVES); + add(Material.SPRUCE_LEAVES); + add(Material.ACACIA_LEAVES); + }}; + List<Material> gen1 = new ArrayList<>() {{ + add(Material.YELLOW_GLAZED_TERRACOTTA); + add(Material.LIGHT_BLUE_GLAZED_TERRACOTTA); + add(Material.GRAY_GLAZED_TERRACOTTA); + add(Material.PODZOL); + add(Material.PODZOL); + add(Material.PODZOL); + add(Material.ORANGE_GLAZED_TERRACOTTA); + }}; + for (int i = 0; i < 3; i++) { + List<Material> gen0 = new ArrayList<>() {{ + add(Material.COAL_ORE); + add(Material.COAL_ORE); + add(Material.COAL_ORE); + add(Material.COAL_ORE); + add(Material.COAL_ORE); + add(Material.IRON_ORE); + add(Material.REDSTONE_ORE); + add(Material.EMERALD_ORE); + add(Material.GOLD_ORE); + add(Material.LAPIS_ORE); + add(Material.DIAMOND_ORE); + add(Material.GRASS_BLOCK); + add(Material.GRASS_BLOCK); + add(Material.GRASS_BLOCK); + add(Material.GRASS_BLOCK); + add(Material.COBWEB); + }}; + matList.add(gen0); + matList.add(gen1); + matList.add(gen2); + List<Material> gen3 = new ArrayList<>() {{ + add(Material.PACKED_ICE); + add(Material.PACKED_ICE); + add(Material.NOTE_BLOCK); + add(Material.TNT); + add(Material.LIGHT_BLUE_CONCRETE); + add(Material.GLASS); + add(Material.PACKED_ICE); + add(Material.PACKED_ICE); + add(Material.NOTE_BLOCK); + add(Material.TNT); + add(Material.LIGHT_BLUE_CONCRETE); + add(Material.GLASS); + add(Material.SOUL_SAND); + }}; + matList.add(gen3); + matList.add(gen4); + matList.add(gen5); + List<Material> gen6 = new ArrayList<>() {{ + add(Material.NETHERRACK); + add(Material.NETHERRACK); + add(Material.NETHERRACK); + add(Material.NETHER_BRICKS); + add(Material.NETHER_BRICKS); + add(Material.NETHERRACK); + add(Material.NETHERRACK); + add(Material.NETHERRACK); + add(Material.NETHER_BRICKS); + add(Material.NETHER_BRICKS); + add(Material.NETHER_GOLD_ORE); + add(Material.NETHER_GOLD_ORE); + add(Material.CRIMSON_NYLIUM); + add(Material.WARPED_NYLIUM); + add(Material.SOUL_SOIL); + add(Material.CRACKED_NETHER_BRICKS); + add(Material.RED_NETHER_BRICKS); + add(Material.NETHER_WART_BLOCK); + add(Material.CRYING_OBSIDIAN); + add(Material.MAGMA_BLOCK); + }}; + matList.add(gen6); + matList.add(gen7); + List<Material> gen8 = new ArrayList<>() {{ + add(Material.REDSTONE_BLOCK); + add(Material.REDSTONE_BLOCK); + add(Material.REDSTONE_LAMP); + add(Material.TARGET); + add(Material.DAYLIGHT_DETECTOR); + add(Material.PISTON); + add(Material.STICKY_PISTON); + add(Material.SLIME_BLOCK); + add(Material.OBSERVER); + add(Material.HOPPER); + }}; + matList.add(gen8); + matList.add(gen9); + matList.add(gen10); + List<Material> gen12 = new ArrayList<>() {{ + add(Material.DIRT); + add(Material.DIRT_PATH); + add(Material.GRASS_BLOCK); + add(Material.OAK_SLAB); + add(Material.BRICK_WALL); + add(Material.BRICK_STAIRS); + }}; + matList.add(gen12); + List<Material> gen14 = new ArrayList<>() {{ + add(Material.LECTERN); + add(Material.OBSIDIAN); + add(Material.SPONGE); + add(Material.BEEHIVE); + add(Material.DRIED_KELP_BLOCK); + }}; + matList.add(gen14); + List<Material> gen15 = new ArrayList<>() {{ + add(Material.SANDSTONE); + add(Material.SANDSTONE_SLAB); + add(Material.RED_SANDSTONE); + add(Material.RED_SANDSTONE_SLAB); + add(Material.RED_TERRACOTTA); + add(Material.TERRACOTTA); + add(Material.YELLOW_TERRACOTTA); + }}; + matList.add(gen15); + List<Material> gen16 = new ArrayList<>() {{ + add(Material.JUNGLE_LOG); + add(Material.STRIPPED_JUNGLE_LOG); + add(Material.JUNGLE_WOOD); + add(Material.STRIPPED_JUNGLE_WOOD); + add(Material.MOSSY_COBBLESTONE); + add(Material.MOSSY_COBBLESTONE); + add(Material.MOSSY_COBBLESTONE); + add(Material.JUNGLE_LEAVES); + add(Material.JUNGLE_SLAB); + add(Material.JUNGLE_TRAPDOOR); + }}; + matList.add(gen16); + } + List<Material> gen11 = new ArrayList<>() {{ + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.GLASS); + add(Material.WHITE_STAINED_GLASS); + }}; + matList.add(gen11); // Troll glass layer + + for (int i = 0; i < 2; i++) { + safeMatList.add(gen1); + safeMatList.add(gen2); + safeMatList.add(gen4); + safeMatList.add(gen5); + safeMatList.add(gen7); + safeMatList.add(gen9); + safeMatList.add(gen10); + } + safeMatList.add(gen11); // Troll glass layer + } + + // Define Random class + Random random = new Random(); + /** + * @return A random predefined List of Materials that are okay to use in the clump generator + */ + public List<Material> getMaterialList() { + return matList.get(random.nextInt(matList.size())); + } + + /** + * @return A random predefined List of Materials that are okay to spawn players on top of + */ + public List<Material> getSafeMaterialList() { return safeMatList.get(random.nextInt(safeMatList.size())); } + + // Template: + // private final List<Material> gen = new ArrayList<>() {{ + // add(Material. + // }}; + + private final List<List<Material>> matList = new ArrayList<>(); + + private final List<List<Material>> safeMatList = new ArrayList<>(); + +} diff --git a/src/main/java/com/MylesAndMore/Tumble/plugin/Constants.java b/src/main/java/com/MylesAndMore/Tumble/plugin/Constants.java new file mode 100644 index 0000000..118af23 --- /dev/null +++ b/src/main/java/com/MylesAndMore/Tumble/plugin/Constants.java @@ -0,0 +1,25 @@ +package com.MylesAndMore.Tumble.plugin; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MVWorldManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.List; +import java.util.Objects; + +public class Constants { + public static Plugin getPlugin() { + return Bukkit.getServer().getPluginManager().getPlugin("tumble"); + } + public static String getPermissionMessage() { return Constants.getPlugin().getConfig().getString("permissionMessage"); } + public static String getGameWorld() { return Constants.getPlugin().getConfig().getString("gameWorld"); } + public static String getLobbyWorld() { return Constants.getPlugin().getConfig().getString("lobbyWorld"); } + public static String getGameType() { return Constants.getPlugin().getConfig().getString("gameMode"); } + public static List<Player> getPlayersInGame() { return Objects.requireNonNull(Bukkit.getServer().getWorld(Constants.getGameWorld())).getPlayers(); } + public static List<Player> getPlayersInLobby() { return Objects.requireNonNull(Bukkit.getServer().getWorld(Constants.getLobbyWorld())).getPlayers(); } + + public static MultiverseCore getMV() { return (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core"); } + public static MVWorldManager getMVWorldManager() { return getMV().getMVWorldManager(); } +} diff --git a/src/main/java/com/MylesAndMore/Tumble/plugin/EventListener.java b/src/main/java/com/MylesAndMore/Tumble/plugin/EventListener.java new file mode 100644 index 0000000..9a4dd62 --- /dev/null +++ b/src/main/java/com/MylesAndMore/Tumble/plugin/EventListener.java @@ -0,0 +1,222 @@ +package com.MylesAndMore.Tumble.plugin; + +import java.util.Objects; + +import com.MylesAndMore.Tumble.game.Game; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.player.*; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +/** + * Tumble event listener for all plugin and game-related events. + */ +public class EventListener implements Listener { + @EventHandler + public void PlayerJoinEvent(PlayerJoinEvent event) { + // Hide/show join message accordingly + if (Constants.getPlugin().getConfig().getBoolean("hideJoinLeaveMessages")) { + event.setJoinMessage(null); + } + // Check if either of the worlds are not defined in config, if so, end to avoid any NPEs later on + if (Constants.getGameWorld() == null || Constants.getLobbyWorld() == null) { return; } + if (event.getPlayer().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + // Send the player back to the lobby if they try to join in the middle of a game + event.getPlayer().teleport(Objects.requireNonNull(Bukkit.getWorld(Constants.getLobbyWorld())).getSpawnLocation()); + } + if (Constants.getPlugin().getConfig().getBoolean("autoStart.enabled")) { + if (Constants.getPlayersInLobby().size() == Constants.getPlugin().getConfig().getInt("autoStart.players")) { + // The autoStart should begin if it is already enabled and the amount of players is correct; pass this to the Game + Game.getGame().autoStart(); + } + } + } + + @EventHandler + public void PlayerChangedWorldEvent(PlayerChangedWorldEvent event) { + if (Constants.getGameWorld() == null || Constants.getLobbyWorld() == null) { + return; + } + if (event.getPlayer().getWorld() == Bukkit.getWorld(Constants.getLobbyWorld())) { + // Another event on which autostart could be triggered + if (Constants.getPlugin().getConfig().getBoolean("autoStart.enabled")) { + if (Constants.getPlayersInLobby().size() == Constants.getPlugin().getConfig().getInt("autoStart.players")) { + Game.getGame().autoStart(); + } + } + } + // Also check if the player left to another world and cancel autostart + else if (event.getFrom() == Bukkit.getWorld(Constants.getLobbyWorld())) { + if (Objects.equals(Game.getGame().getGameState(), "waiting")) { + Game.getGame().cancelStart(); + } + } + } + + @EventHandler + public void PlayerQuitEvent(PlayerQuitEvent event) { + // Hide/show leave message accordingly + if (Constants.getPlugin().getConfig().getBoolean("hideJoinLeaveMessages")) { + event.setQuitMessage(null); + } + if (Constants.getLobbyWorld() == null) { return; } + if (event.getPlayer().getWorld() == Bukkit.getWorld(Constants.getLobbyWorld())) { + // Check if the game is in the process of autostarting, if so cancel + if (Objects.equals(Game.getGame().getGameState(), "waiting")) { + Game.getGame().cancelStart(); + } + } + } + + @EventHandler + public void PlayerDeathEvent(PlayerDeathEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Pass game deaths to the Game + if (event.getEntity().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + Game.getGame().playerDeath(event.getEntity()); + } + } + + @EventHandler + public void PlayerItemDamageEvent(PlayerItemDamageEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Remove item damage within games + if (event.getPlayer().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + event.setCancelled(true); + } + } + + @EventHandler + public void ProjectileLaunchEvent(ProjectileLaunchEvent event) { + if (Constants.getGameWorld() == null) { + return; + } + if (event.getEntity().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + if (event.getEntity() instanceof Snowball) { + if (event.getEntity().getShooter() instanceof Player player) { + // Prevent projectiles (snowballs) from being thrown before the game starts + if (Objects.equals(Game.getGame().getGameState(), "starting")) { + event.setCancelled(true); + } + else { + // Give players a snowball when they've used one (infinite snowballs) + Bukkit.getServer().getScheduler().runTask(Constants.getPlugin(), () -> player.getInventory().addItem(new ItemStack(Material.SNOWBALL, 1))); + } + } + } + } + } + + @EventHandler + public void ProjectileHitEvent(ProjectileHitEvent event) { + if (Constants.getGameWorld() == null) { return; } + else if (event.getHitBlock() == null) { return; } + // Removes blocks that snowballs thrown by players have hit in the game world + if (event.getHitBlock().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + if (event.getEntity() instanceof Snowball) { + if (event.getEntity().getShooter() instanceof Player) { + if (event.getHitBlock() != null) { + if (event.getHitBlock().getLocation().distanceSquared(Objects.requireNonNull(Bukkit.getWorld(Constants.getGameWorld())).getSpawnLocation()) < 579) { + event.getHitBlock().setType(Material.AIR); + } + } + else if (event.getHitEntity() != null) { + if (event.getHitEntity() instanceof Player hitPlayer) { + // Also cancel any knockback + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Constants.getPlugin(), () -> hitPlayer.setVelocity(new Vector())); + } + } + } + } + } + } + + @EventHandler + public void PlayerDropItemEvent(PlayerDropItemEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Don't allow items to drop in the game world + if (event.getPlayer().getWorld() == Bukkit.getWorld((Constants.getGameWorld()))) { + event.setCancelled(true); + } + } + + @EventHandler + public void PlayerMoveEvent(PlayerMoveEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Cancel movement if the game is starting (so players can't move before the game starts) + if (Objects.equals(Game.getGame().getGameState(), "starting")) { + event.setCancelled(true); + } + } + + @EventHandler + public void BlockDropItemEvent(BlockDropItemEvent event) { + if (Constants.getGameWorld() == null) { return; } + // If a block was going to drop an item (ex. snow dropping snowballs) in the game world, cancel it + if (event.getBlock().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + event.setCancelled(true); + } + } + + @EventHandler + public void PlayerInteractEvent(PlayerInteractEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Remove blocks when clicked in the game world (all gamemodes require this functionality) + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (Objects.requireNonNull(event.getClickedBlock()).getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + event.getClickedBlock().setType(Material.AIR); + } + } + } + + @EventHandler + public void BlockBreakEvent(BlockBreakEvent event) { + if (Constants.getGameWorld() == null) { return; } + // This just doesn't allow blocks to break in the gameWorld; the PlayerInteractEvent will take care of everything + // This prevents any weird client-server desync + if (event.getBlock().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + event.setCancelled(true); + } + } + + @EventHandler + public void FoodLevelChangeEvent(FoodLevelChangeEvent event) { + if (Constants.getGameWorld() == null) { return; } + // INFINITE FOOD (YAY!!!!) + if (event.getEntity().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + event.setCancelled(true); + } + } + + @EventHandler + public void EntityDamageEvent(EntityDamageEvent event) { + if (Constants.getGameWorld() == null) { return; } + // Check to see if a player got damaged by another entity (player, snowball, etc) in the gameWorld, if so, cancel it + if (event.getEntity().getWorld() == Bukkit.getWorld(Constants.getGameWorld())) { + if (event.getEntity() instanceof Player) { + if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK || event.getCause() == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == EntityDamageEvent.DamageCause.FALL) { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void InventoryDragEvent(InventoryDragEvent event) { + if (Constants.getGameWorld() == null) { return; } + if (event.getWhoClicked().getWorld() == Bukkit.getWorld((Constants.getGameWorld()))) { + event.setCancelled(true); + } + } + +} diff --git a/src/main/java/com/MylesAndMore/tumble/api/Metrics.java b/src/main/java/com/MylesAndMore/Tumble/plugin/Metrics.java index 411a918..3432a93 100644 --- a/src/main/java/com/MylesAndMore/tumble/api/Metrics.java +++ b/src/main/java/com/MylesAndMore/Tumble/plugin/Metrics.java @@ -1,4 +1,4 @@ -// Do NOT remove this file! The build will fail--it is to enable bStats. +// Tumble--do not remove or modify this file! /* * This Metrics class was auto-generated and can be copied into your project if you are @@ -14,7 +14,7 @@ * * Violations will result in a ban of your plugin and account from bStats. */ -package com.MylesAndMore.tumble.api; +package com.MylesAndMore.Tumble.plugin; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/com/MylesAndMore/tumble/EventListener.java b/src/main/java/com/MylesAndMore/tumble/EventListener.java deleted file mode 100644 index 63ca9a0..0000000 --- a/src/main/java/com/MylesAndMore/tumble/EventListener.java +++ /dev/null @@ -1,296 +0,0 @@ -package com.MylesAndMore.tumble; - -import java.util.Objects; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.entity.Snowball; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDropItemEvent; -import org.bukkit.event.entity.*; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.player.*; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -/** - * Tumble event listener for all plugin and game-related events. - */ -public class EventListener implements Listener { - @EventHandler - public void PlayerJoinEvent(PlayerJoinEvent event) { - // On a PlayerJoinEvent, check if the config is set to hide the join/leave - // messages - // If true, null out the join message (which just makes it so that there is no - // message) - // If false, nothing will happen, and the default message will display - if (TumbleManager.getPlugin().getConfig().getBoolean("hideJoinLeaveMessages")) { - event.setJoinMessage(null); - } - // Check if either of the worlds are not defined in config, if so, end - // This is to avoid NPEs and such - if (TumbleManager.getGameWorld() == null || TumbleManager.getLobbyWorld() == null) { - return; - } - // Check if the player joining is in the game world, if true then - if (event.getPlayer().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - // send them back to the lobby. - event.getPlayer().teleport(Bukkit.getWorld(TumbleManager.getLobbyWorld()).getSpawnLocation()); - } - // For auto-start function: check if the autoStart is enabled - if (TumbleManager.getPlugin().getConfig().getBoolean("autoStart.enabled")) { - // If so, check if the amount of players has been reached - if (TumbleManager.getPlayersInLobby().size() == TumbleManager.getPlugin().getConfig().getInt("autoStart.players")) { - // The autoStart should begin; pass this to the Game - Game.getGame().autoStart(); - } - } - } - - @EventHandler - public void PlayerChangedWorldEvent(PlayerChangedWorldEvent event) { - if (TumbleManager.getGameWorld() == null || TumbleManager.getLobbyWorld() == null) { - return; - } - // Check if the player changed to the lobbyWorld, then - if (event.getPlayer().getWorld() == Bukkit.getWorld(TumbleManager.getLobbyWorld())) { - // run the autostart checks (commented above) - if (TumbleManager.getPlugin().getConfig().getBoolean("autoStart.enabled")) { - if (TumbleManager.getPlayersInLobby().size() == TumbleManager.getPlugin().getConfig().getInt("autoStart.players")) { - Game.getGame().autoStart(); - } - } - } - // also check if the player left to another world - else if (event.getFrom() == Bukkit.getWorld(TumbleManager.getLobbyWorld())) { - if (Objects.equals(Game.getGame().getGameState(), "waiting")) { - Game.getGame().cancelStart(); - } - } - } - - @EventHandler - public void PlayerQuitEvent(PlayerQuitEvent event) { - // On a PlayerQuitEvent, check if the config is set to hide the join/leave - // messages - // If true, null out the quit message (which just makes it so that there is no - // message) - // If false, nothing will happen, and the default message will display - if (TumbleManager.getPlugin().getConfig().getBoolean("hideJoinLeaveMessages")) { - event.setQuitMessage(null); - } - if (TumbleManager.getLobbyWorld() == null) { - return; - } - if (event.getPlayer().getWorld() == Bukkit.getWorld(TumbleManager.getLobbyWorld())) { - // Check if the game is in the process of autostarting - if (Objects.equals(Game.getGame().getGameState(), "waiting")) { - // Cancel the autostart - Game.getGame().cancelStart(); - } - } - } - - @EventHandler - public void PlayerDeathEvent(PlayerDeathEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // On a PlayerDeathEvent, - // check to see if the player died in the gameWorld, - if (event.getEntity().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - // then pass this off to the Game - Game.getGame().playerDeath(event.getEntity()); - } - } - - @EventHandler - public void PlayerItemDamageEvent(PlayerItemDamageEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // On an ItemDamageEvent - // check to see if the item was damaged in the gameWorld, - if (event.getPlayer().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - event.setCancelled(true); - } - } - - // private long lastTimeP; - @EventHandler - public void ProjectileLaunchEvent(ProjectileLaunchEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // When a projectile is launched, - // check to see if projectile was thrown in the gameWorld. - if (event.getEntity().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - if (event.getEntity() instanceof Snowball) { - if (event.getEntity().getShooter() instanceof Player player) { - // Check to see if the last snowball was thrown less than 200ms ago, if so, don't allow another - // if ((System.currentTimeMillis() - lastTimeP) < 200) { event.setCancelled(true); } - // else { - // // Otherwise, continue with logic - // lastTimeP = System.currentTimeMillis(); - // // This prevents players from shooting snowballs before the game actually begins - if (Objects.equals(Game.getGame().getGameState(), "starting")) { - event.setCancelled(true); - } - else { - // This gives players a snowball when they've used one - Bukkit.getServer().getScheduler().runTask(TumbleManager.getPlugin(), () -> { - player.getInventory().addItem(new ItemStack(Material.SNOWBALL, 1)); - }); - } - // } - } - } - } - } - - @EventHandler - public void ProjectileHitEvent(ProjectileHitEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // Weird stacktrace thing - else if (event.getHitBlock() == null) { - return; - } - // When a projectile hits - // check to see if the projectile hit in the gameWorld, - if (event.getHitBlock().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - // then check if the projectile was a snowball, - if (event.getEntity() instanceof Snowball) { - // then check if a player threw it, - if (event.getEntity().getShooter() instanceof Player shooterPlayer) { - // then check to see if it hit a player or a block - if (event.getHitBlock() != null) { - // if it was a block, check if that block is within the game area, - if (event.getHitBlock().getLocation().distanceSquared(Bukkit.getWorld(TumbleManager.getGameWorld()).getSpawnLocation()) < 579) { - // then remove that block. - event.getHitBlock().setType(Material.AIR); - } - } - else if (event.getHitEntity() != null) { - // if it was an entity, check if it hit a player, - if (event.getHitEntity() instanceof Player hitPlayer) { - // then cancel the knockback (has to be delayed by a tick for some reason) - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - hitPlayer.setVelocity(new Vector()); - }); - } - } - } - } - } - } - - @EventHandler - public void PlayerDropItemEvent(PlayerDropItemEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // When an item is dropped, - // check if the item was dropped in the game world - if (event.getPlayer().getWorld() == Bukkit.getWorld((TumbleManager.getGameWorld()))) { - event.setCancelled(true); - } - } - - @EventHandler - public void PlayerMoveEvent(PlayerMoveEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // On a PlayerMoveEvent, check if the game is starting - if (Objects.equals(Game.getGame().getGameState(), "starting")) { - // Cancel the event if the game is starting (so players can't move before the game starts) - event.setCancelled(true); - } - } - - @EventHandler - public void BlockDropItemEvent(BlockDropItemEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // If a block was going to drop an item (ex. snow dropping snowballs) in the GameWorld, cancel it - if (event.getBlock().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - event.setCancelled(true); - } - } - - // private long lastTimeI; - @EventHandler - public void PlayerInteractEvent(PlayerInteractEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // Check if a player was left clicking a block in the gameWorld - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - if (event.getClickedBlock().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - // Then check to see if the player interacted less than 150ms ago - // if ((System.currentTimeMillis() - lastTimeI) < 150) return; - // If not, set that block to air (break it) - // else { - // lastTimeI = System.currentTimeMillis(); - event.getClickedBlock().setType(Material.AIR); - // } - } - } - } - - @EventHandler - public void BlockBreakEvent(BlockBreakEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // This just doesn't allow blocks to break in the gameWorld; the PlayerInteractEvent will take care of everything - // It just keeps client commonality w/ animations and stuff - if (event.getBlock().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - event.setCancelled(true); - } - } - - @EventHandler - public void FoodLevelChangeEvent(FoodLevelChangeEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // When someone's food level changes, check if that happened in the gameWorld, then cancel it - if (event.getEntity().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - event.setCancelled(true); - } - } - - @EventHandler - public void EntityDamageEvent(EntityDamageEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - // Check to see if a player got damaged by another entity (player, snowball, etc) in the gameWorld, if so, cancel it - if (event.getEntity().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) { - if (event.getEntity() instanceof Player) { - if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK || event.getCause() == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == EntityDamageEvent.DamageCause.FALL) { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void InventoryDragEvent(InventoryDragEvent event) { - if (TumbleManager.getGameWorld() == null) { - return; - } - if (event.getWhoClicked().getWorld() == Bukkit.getWorld((TumbleManager.getGameWorld()))) { - event.setCancelled(true); - } - } - -} diff --git a/src/main/java/com/MylesAndMore/tumble/TumbleManager.java b/src/main/java/com/MylesAndMore/tumble/TumbleManager.java deleted file mode 100644 index 43cc241..0000000 --- a/src/main/java/com/MylesAndMore/tumble/TumbleManager.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.MylesAndMore.tumble; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.List; - -/** - * Class to store long return methods to make writing this plugin slightly less painful. - */ -public class TumbleManager { - // Tumble plugin - public static Plugin getPlugin() { - return Bukkit.getServer().getPluginManager().getPlugin("tumble"); - } - - // Tumble static methods - 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("gameMode"); } - public static List<Player> getPlayersInGame() { return Bukkit.getServer().getWorld(TumbleManager.getGameWorld()).getPlayers(); } - public static List<Player> getPlayersInLobby() { return Bukkit.getServer().getWorld(TumbleManager.getLobbyWorld()).getPlayers(); } - - - // Multiverse plugin - public static MultiverseCore getMV() { return (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core"); } - // Multiverse worldManager - public static MVWorldManager getMVWorldManager() { return getMV().getMVWorldManager(); } -} diff --git a/src/main/java/com/MylesAndMore/tumble/api/Layers.java b/src/main/java/com/MylesAndMore/tumble/api/Layers.java deleted file mode 100644 index d0d5890..0000000 --- a/src/main/java/com/MylesAndMore/tumble/api/Layers.java +++ /dev/null @@ -1,373 +0,0 @@ -package com.MylesAndMore.tumble.api; - -import org.bukkit.Material; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * This class is dedicated to storing the different types of layers that can be generated. - */ -public class Layers { - - public Layers(){ - matList.add(gen0); - matList.add(gen1); - matList.add(gen2); - matList.add(gen3); - matList.add(gen4); - matList.add(gen5); - matList.add(gen6); - matList.add(gen7); - matList.add(gen8); - matList.add(gen9); - matList.add(gen10); - matList.add(gen12); - matList.add(gen14); - matList.add(gen15); - matList.add(gen16); - matList.add(gen0); - matList.add(gen1); - matList.add(gen2); - matList.add(gen3); - matList.add(gen4); - matList.add(gen5); - matList.add(gen6); - matList.add(gen7); - matList.add(gen8); - matList.add(gen9); - matList.add(gen10); - matList.add(gen12); - matList.add(gen14); - matList.add(gen15); - matList.add(gen16); - matList.add(gen0); - matList.add(gen1); - matList.add(gen2); - matList.add(gen3); - matList.add(gen4); - matList.add(gen5); - matList.add(gen6); - matList.add(gen7); - matList.add(gen8); - matList.add(gen9); - matList.add(gen10); - matList.add(gen12); - matList.add(gen14); - matList.add(gen15); - matList.add(gen16); - // Troll glass layer - matList.add(gen11); - - safeMatList.add(gen1); - safeMatList.add(gen2); - safeMatList.add(gen4); - safeMatList.add(gen5); - safeMatList.add(gen7); - safeMatList.add(gen9); - safeMatList.add(gen10); - safeMatList.add(gen1); - safeMatList.add(gen2); - safeMatList.add(gen4); - safeMatList.add(gen5); - safeMatList.add(gen7); - safeMatList.add(gen9); - safeMatList.add(gen10); - safeMatList.add(gen1); - safeMatList.add(gen2); - safeMatList.add(gen4); - safeMatList.add(gen5); - safeMatList.add(gen7); - safeMatList.add(gen9); - safeMatList.add(gen10); - // Troll glass layer - safeMatList.add(gen11); - } - - // Define Random class - Random random = new Random(); - /** - * @return A random predefined List of Materials that are okay to use in the clump generator - */ - public List<Material> getMaterialList() { - return matList.get(random.nextInt(matList.size())); - } - - /** - * @return A random predefined List of Materials that are okay to spawn players on top of - */ - public List<Material> getSafeMaterialList() { return safeMatList.get(random.nextInt(safeMatList.size())); } - - // Begin lists - - // private final List<Material> gen = new ArrayList<>() {{ - // add(Material. - // }}; - - private final List<Material> gen0 = new ArrayList<>() {{ - add(Material.COAL_ORE); - add(Material.COAL_ORE); - add(Material.COAL_ORE); - add(Material.COAL_ORE); - add(Material.COAL_ORE); - add(Material.IRON_ORE); - add(Material.REDSTONE_ORE); - add(Material.EMERALD_ORE); - add(Material.GOLD_ORE); - add(Material.LAPIS_ORE); - add(Material.DIAMOND_ORE); - add(Material.GRASS_BLOCK); - add(Material.GRASS_BLOCK); - add(Material.GRASS_BLOCK); - add(Material.GRASS_BLOCK); - add(Material.COBWEB); - }}; - - private final List<Material> gen1 = new ArrayList<>() {{ - add(Material.YELLOW_GLAZED_TERRACOTTA); - add(Material.LIGHT_BLUE_GLAZED_TERRACOTTA); - add(Material.GRAY_GLAZED_TERRACOTTA); - add(Material.PODZOL); - add(Material.PODZOL); - add(Material.PODZOL); - add(Material.ORANGE_GLAZED_TERRACOTTA); - }}; - - private final List<Material> gen2 = new ArrayList<>() {{ - add(Material.PINK_TERRACOTTA); - add(Material.PURPLE_TERRACOTTA); - add(Material.GRAY_TERRACOTTA); - add(Material.BLUE_TERRACOTTA); - add(Material.LIGHT_BLUE_TERRACOTTA); - add(Material.WHITE_TERRACOTTA); - add(Material.BROWN_TERRACOTTA); - add(Material.GREEN_TERRACOTTA); - add(Material.YELLOW_TERRACOTTA); - add(Material.PINK_TERRACOTTA); - add(Material.PURPLE_TERRACOTTA); - add(Material.GRAY_TERRACOTTA); - add(Material.BLUE_TERRACOTTA); - add(Material.LIGHT_BLUE_TERRACOTTA); - add(Material.WHITE_TERRACOTTA); - add(Material.BROWN_TERRACOTTA); - add(Material.GREEN_TERRACOTTA); - add(Material.YELLOW_TERRACOTTA); - add(Material.WHITE_STAINED_GLASS); - add(Material.HONEYCOMB_BLOCK); - add(Material.HONEYCOMB_BLOCK); - }}; - - private final List<Material> gen3 = new ArrayList<>() {{ - add(Material.PACKED_ICE); - add(Material.PACKED_ICE); - add(Material.NOTE_BLOCK); - add(Material.TNT); - add(Material.LIGHT_BLUE_CONCRETE); - add(Material.GLASS); - add(Material.PACKED_ICE); - add(Material.PACKED_ICE); - add(Material.NOTE_BLOCK); - add(Material.TNT); - add(Material.LIGHT_BLUE_CONCRETE); - add(Material.GLASS); - add(Material.SOUL_SAND); - }}; - - private final List<Material> gen4 = new ArrayList<>() {{ - add(Material.DIAMOND_BLOCK); - add(Material.GOLD_BLOCK); - add(Material.REDSTONE_BLOCK); - add(Material.REDSTONE_BLOCK); - add(Material.LAPIS_BLOCK); - add(Material.LAPIS_BLOCK); - add(Material.IRON_BLOCK); - add(Material.COAL_BLOCK); - add(Material.IRON_BLOCK); - add(Material.COAL_BLOCK); - add(Material.IRON_BLOCK); - add(Material.COAL_BLOCK); - add(Material.COAL_BLOCK); - }}; - - private final List<Material> gen5 = new ArrayList<>() {{ - add(Material.WHITE_TERRACOTTA); - add(Material.BLUE_ICE); - add(Material.SOUL_SAND); - add(Material.STONE_SLAB); - add(Material.WHITE_TERRACOTTA); - add(Material.BLUE_ICE); - add(Material.SOUL_SAND); - add(Material.STONE_SLAB); - add(Material.WHITE_TERRACOTTA); - add(Material.BLUE_ICE); - add(Material.SOUL_SAND); - add(Material.STONE_SLAB); - add(Material.GLOWSTONE); - add(Material.GLOWSTONE); - add(Material.HONEY_BLOCK); - add(Material.SLIME_BLOCK); - }}; - - private final List<Material> gen6 = new ArrayList<>() {{ - add(Material.NETHERRACK); - add(Material.NETHERRACK); - add(Material.NETHERRACK); - add(Material.NETHER_BRICKS); - add(Material.NETHER_BRICKS); - add(Material.NETHERRACK); - add(Material.NETHERRACK); - add(Material.NETHERRACK); - add(Material.NETHER_BRICKS); - add(Material.NETHER_BRICKS); - add(Material.NETHER_GOLD_ORE); - add(Material.NETHER_GOLD_ORE); - add(Material.CRIMSON_NYLIUM); - add(Material.WARPED_NYLIUM); - add(Material.SOUL_SOIL); - add(Material.CRACKED_NETHER_BRICKS); - add(Material.RED_NETHER_BRICKS); - add(Material.NETHER_WART_BLOCK); - add(Material.CRYING_OBSIDIAN); - add(Material.MAGMA_BLOCK); - }}; - - private final List<Material> gen7 = new ArrayList<>() {{ - add(Material.END_STONE); - add(Material.END_STONE_BRICKS); - add(Material.END_STONE); - add(Material.END_STONE_BRICKS); - add(Material.END_STONE); - add(Material.END_STONE_BRICKS); - add(Material.END_STONE); - add(Material.END_STONE_BRICKS); - add(Material.OBSIDIAN); - add(Material.PURPUR_BLOCK); - add(Material.PURPUR_PILLAR); - add(Material.COBBLESTONE); - }}; - - private final List<Material> gen8 = new ArrayList<>() {{ - add(Material.REDSTONE_BLOCK); - add(Material.REDSTONE_BLOCK); - add(Material.REDSTONE_LAMP); - add(Material.TARGET); - add(Material.DAYLIGHT_DETECTOR); - add(Material.PISTON); - add(Material.STICKY_PISTON); - add(Material.SLIME_BLOCK); - add(Material.OBSERVER); - add(Material.HOPPER); - }}; - - private final List<Material> gen9 = new ArrayList<>() {{ - add(Material.PRISMARINE); - add(Material.DARK_PRISMARINE); - add(Material.BLUE_STAINED_GLASS); - add(Material.WET_SPONGE); - add(Material.PRISMARINE_BRICKS); - add(Material.PRISMARINE_BRICK_SLAB); - add(Material.DARK_PRISMARINE); - add(Material.SEA_LANTERN); - add(Material.TUBE_CORAL_BLOCK); - add(Material.BRAIN_CORAL_BLOCK); - add(Material.BUBBLE_CORAL_BLOCK); - }}; - - private final List<Material> gen10 = new ArrayList<>() {{ - add(Material.OAK_LOG); - add(Material.SPRUCE_LOG); - add(Material.ACACIA_LOG); - add(Material.STRIPPED_OAK_LOG); - add(Material.STRIPPED_SPRUCE_LOG); - add(Material.STRIPPED_ACACIA_LOG); - add(Material.OAK_WOOD); - add(Material.SPRUCE_WOOD); - add(Material.ACACIA_WOOD); - add(Material.OAK_LEAVES); - add(Material.SPRUCE_LEAVES); - add(Material.ACACIA_LEAVES); - add(Material.OAK_LEAVES); - add(Material.SPRUCE_LEAVES); - add(Material.ACACIA_LEAVES); - }}; - - private final List<Material> gen11 = new ArrayList<>() {{ - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.GLASS); - add(Material.WHITE_STAINED_GLASS); - }}; - - private final List<Material> gen12 = new ArrayList<>() {{ - add(Material.DIRT); - add(Material.DIRT_PATH); - add(Material.GRASS_BLOCK); - add(Material.OAK_SLAB); - add(Material.BRICK_WALL); - add(Material.BRICK_STAIRS); - }}; - - private final List<Material> gen14 = new ArrayList<>() {{ - add(Material.LECTERN); - add(Material.OBSIDIAN); - add(Material.SPONGE); - add(Material.BEEHIVE); - add(Material.DRIED_KELP_BLOCK); - }}; - - private final List<Material> gen15 = new ArrayList<>() {{ - add(Material.SANDSTONE); - add(Material.SANDSTONE_SLAB); - add(Material.RED_SANDSTONE); - add(Material.RED_SANDSTONE_SLAB); - add(Material.RED_TERRACOTTA); - add(Material.TERRACOTTA); - add(Material.YELLOW_TERRACOTTA); - }}; - - private final List<Material> gen16 = new ArrayList<>() {{ - add(Material.JUNGLE_LOG); - add(Material.STRIPPED_JUNGLE_LOG); - add(Material.JUNGLE_WOOD); - add(Material.STRIPPED_JUNGLE_WOOD); - add(Material.MOSSY_COBBLESTONE); - add(Material.MOSSY_COBBLESTONE); - add(Material.MOSSY_COBBLESTONE); - add(Material.JUNGLE_LEAVES); - add(Material.JUNGLE_SLAB); - add(Material.JUNGLE_TRAPDOOR); - }}; - - private final List<List<Material>> matList = new ArrayList<>(); - - private final List<List<Material>> safeMatList = new ArrayList<>(); - -} diff --git a/src/main/java/com/MylesAndMore/tumble/commands/ReloadCommand.java b/src/main/java/com/MylesAndMore/tumble/commands/ReloadCommand.java deleted file mode 100644 index 4ca26f4..0000000 --- a/src/main/java/com/MylesAndMore/tumble/commands/ReloadCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.MylesAndMore.tumble.commands; - -import com.MylesAndMore.tumble.TumbleManager; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class ReloadCommand implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if the sender has perms to run command - if (sender.hasPermission("tumble.reload")) { - // If sender does have permission, reload the plugin's config and display a confirmation message - TumbleManager.getPlugin().reloadConfig(); - sender.sendMessage(ChatColor.GREEN + "Tumble configuration reloaded successfully."); - } - else { - // If sender does not have permission, display them the permissionMessage from the config - sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage()); - } - return true; - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ee2a2c7..68b4e3d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,32 +1,24 @@ -# Customize the default game mode of Tumble -# Acceptable options include: shovels, snowballs, mixed -# Default is mixed +# Customize the default game mode; options include: shovels, snowballs, mixed gameMode: mixed -# Hides join/leave messages in public chat -# Default is false +# Customize the auto start feature of Tumble; players can be up to 8 +autoStart: + enabled: false + players: 2 + +# Hides player join/leave messages in public chat hideJoinLeaveMessages: false # Customize the message that displays when the player does not have permission to execute a command from this plugin permissionMessage: You do not have permission to perform this command! -# Customize the auto start feature of Tumble -# Defaults are false and two players -# Players can be up to 8 -autoStart: - enabled: false - players: 2 - # Customize the place that the winner is teleported after a game ends -# Keep in mind that these coordinates cannot be zero! The teleport will fail if any of them are; use something like 0.5 instead. -# These are optional values--defaults are nothing +# Keep in mind that these coordinates cannot be zero! The teleport will fail if any of them are; use something like 0.5 instead winnerTeleport: x: y: z: -# This tells the plugin which worlds it should use as the lobby/game worlds -# Do NOT change unless you know what you're doing!! -# Will be blank by default +# The plugin will populate these fields automatically lobbyWorld: -gameWorld:
\ No newline at end of file +gameWorld:
\ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 258ff5a..42c4fc1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ description: 'A Minecraft: Java Edition plugin recreating the Tumble minigame fr api-version: 1.19 load: STARTUP author: MylesAndMore -website: https://github.com/MylesAndMore/tumble +website: https://github.com/MylesAndMore/Tumble depend: - Multiverse-Core commands: |