diff options
author | MylesAndMore <mylesandmore9@gmail.com> | 2023-06-17 20:46:36 +0200 |
---|---|---|
committer | MylesAndMore <mylesandmore9@gmail.com> | 2023-06-17 20:46:36 +0200 |
commit | 19d8ffbc6659c7de13b81a587dae7081078649c6 (patch) | |
tree | b15435cb788f0a221a7393739908b4c84baa51ad /src/main/java/com/MylesAndMore/tumble/commands | |
parent | 3c48bd3f9587ae9459d789f70ba1ebaaf691209b (diff) | |
download | Tumble-19d8ffbc6659c7de13b81a587dae7081078649c6.tar.gz Tumble-19d8ffbc6659c7de13b81a587dae7081078649c6.tar.bz2 Tumble-19d8ffbc6659c7de13b81a587dae7081078649c6.zip |
refactoring!
it's been a while, I thought I would clean up the code a bit and test to make sure everything works on 1.20 :)
Diffstat (limited to '')
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/commands/SetAutoStart.java (renamed from src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java) | 33 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/commands/SetWinnerLoc.java (renamed from src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java) | 43 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/commands/SetWorldConfig.java (renamed from src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java) | 35 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/commands/StartGame.java (renamed from src/main/java/com/MylesAndMore/tumble/commands/StartGame.java) | 38 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/commands/ReloadCommand.java | 24 |
5 files changed, 62 insertions, 111 deletions
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/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; - } -} |