aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/commands
diff options
context:
space:
mode:
authorMyles <mylesandmore9@gmail.com>2022-12-08 20:04:41 -0600
committerMyles <mylesandmore9@gmail.com>2022-12-08 20:04:41 -0600
commit2d7de58b65fb7ecdd7c784707dbe2a39fa3d6e27 (patch)
tree6dde141c7022be968111dcd4a771d113d03344c1 /src/main/java/com/MylesAndMore/tumble/commands
parent126b83f1ca45457dc1c9e08c1d0fc30b4fc8b88d (diff)
downloadTumble-2d7de58b65fb7ecdd7c784707dbe2a39fa3d6e27.tar.gz
Tumble-2d7de58b65fb7ecdd7c784707dbe2a39fa3d6e27.tar.bz2
Tumble-2d7de58b65fb7ecdd7c784707dbe2a39fa3d6e27.zip
fix (most of) the bugs
Diffstat (limited to 'src/main/java/com/MylesAndMore/tumble/commands')
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java41
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/StartGame.java74
2 files changed, 70 insertions, 45 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java b/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java
index d64573c..0dcb4d9 100644
--- a/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java
+++ b/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java
@@ -1,6 +1,7 @@
package com.MylesAndMore.tumble.commands;
import com.MylesAndMore.tumble.TumbleManager;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -16,30 +17,36 @@ public class SetAutoStart implements CommandExecutor{
// Check if game and lobby worlds are null
if (TumbleManager.getGameWorld() != null) {
if (TumbleManager.getLobbyWorld() != null) {
- // Check the player # argument and parse it into an int
- int args0 = 0;
- try {
- args0 = Integer.parseInt(args[0]);
- } catch (NumberFormatException nfe){
- sender.sendMessage(ChatColor.RED + "Player amount must be a valid number.");
- } catch (Exception e){
- sender.sendMessage(ChatColor.RED + "Invalid player amount.");
- }
// Check the amount of args entered
if (args.length == 2) {
+ // Check the player # argument and parse it into an int
+ int args0;
+ try {
+ args0 = Integer.parseInt(args[0]);
+ } catch (NumberFormatException nfe){
+ sender.sendMessage(ChatColor.RED + "Player amount must be a valid number.");
+ return true;
+ } catch (Exception e){
+ sender.sendMessage(ChatColor.RED + "Invalid player amount.");
+ 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", args[1]);
+ TumbleManager.getPlugin().getConfig().set("autoStart.enabled", true);
TumbleManager.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", args[1]);
+ TumbleManager.getPlugin().getConfig().set("autoStart.enabled", false);
TumbleManager.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 {
return false;
@@ -51,9 +58,21 @@ public class SetAutoStart implements CommandExecutor{
}
else if (args.length == 1) {
// Only PlayerAmount was entered
+ int args0;
+ try {
+ args0 = Integer.parseInt(args[0]);
+ } catch (NumberFormatException nfe){
+ sender.sendMessage(ChatColor.RED + "Player amount must be a valid number.");
+ return true;
+ } catch (Exception e){
+ sender.sendMessage(ChatColor.RED + "Invalid player amount.");
+ return true;
+ }
if ((args0 >= 2) && (args0 <= 8)) {
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.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 {
sender.sendMessage(ChatColor.RED + "Please enter a player amount between two and eight!");
diff --git a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
index 46ca6ce..d488fec 100644
--- a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
+++ b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
@@ -20,48 +20,54 @@ public class StartGame implements CommandExecutor {
if (TumbleManager.getPlayersInLobby().size() > 0) {
// Check if there is a gameWorld specified in config
if (TumbleManager.getGameWorld() != null) {
- sender.sendMessage(ChatColor.BLUE + "Starting game, please wait.");
- // Use multiverse to load game world
- // If the load was successful, start game
- if (TumbleManager.getMVWorldManager().loadWorld(TumbleManager.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())) {
- // 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!");
+ // Check if a game is already pending to start
+ if (!Objects.equals(Game.getGame().getGameState(), "waiting")) {
+ sender.sendMessage(ChatColor.BLUE + "Starting game, please wait.");
+ // Use multiverse to load game world
+ // If the load was successful, start game
+ if (TumbleManager.getMVWorldManager().loadWorld(TumbleManager.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())) {
+ // 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!");
+ }
+ else if (Objects.equals(Game.getGame().getGameState(), "running")) {
+ 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"));
+ }
}
- else if (Objects.equals(Game.getGame().getGameState(), "running")) {
- 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"));
+ }
+ // If there was an argument for gameType, pass that into the startGame method
+ else {
+ if (!Game.getGame().startGame(args[0])) {
+ // 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!");
+ }
+ else if (Objects.equals(Game.getGame().getGameState(), "running")) {
+ sender.sendMessage(ChatColor.RED + "A game is already running!");
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Failed to recognize game of type " + ChatColor.GRAY + args[0]);
+ }
}
}
}
- // If there was an argument for gameType, pass that into the startGame method
+ // If load was unsuccessful, give feedback
+ // 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 {
- if (!Game.getGame().startGame(args[0])) {
- // 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!");
- }
- else if (Objects.equals(Game.getGame().getGameState(), "running")) {
- sender.sendMessage(ChatColor.RED + "A game is already running!");
- }
- else {
- sender.sendMessage(ChatColor.RED + "Failed to recognize game of type " + ChatColor.GRAY + args[0]);
- }
- }
+ sender.sendMessage(ChatColor.RED + "Failed to find a world named " + ChatColor.GRAY + TumbleManager.getGameWorld());
+ sender.sendMessage(ChatColor.RED + "Is the configuration file correct?");
}
}
- // If load was unsuccessful, give feedback
- // 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 + "Is the configuration file correct?");
+ sender.sendMessage(ChatColor.RED + "A game is already queued to begin!");
}
}
// Feedback for if there is no gameWorld in the config