aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/commands
diff options
context:
space:
mode:
authorMyles <43725835+MylesAndMore@users.noreply.github.com>2022-12-13 14:16:59 -0600
committerGitHub <noreply@github.com>2022-12-13 14:16:59 -0600
commit6739bbb14d03bd215f8c7d72dc14d961b6bc175e (patch)
treee2c680914445931fdfad35169eb17dd0404301f5 /src/main/java/com/MylesAndMore/tumble/commands
parentcea002dc786f7826a1a3faef26fb659e3d8e908e (diff)
parentcbafd10bc90273a263d019faeccb356ead442eb1 (diff)
downloadTumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.tar.gz
Tumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.tar.bz2
Tumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.zip
Merge pull request #1 from MylesAndMore/beta
merge beta to main for release
Diffstat (limited to 'src/main/java/com/MylesAndMore/tumble/commands')
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java97
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java115
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java4
-rw-r--r--src/main/java/com/MylesAndMore/tumble/commands/StartGame.java93
4 files changed, 263 insertions, 46 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java b/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java
new file mode 100644
index 0000000..4b97d9a
--- /dev/null
+++ b/src/main/java/com/MylesAndMore/tumble/commands/SetAutoStart.java
@@ -0,0 +1,97 @@
+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;
+
+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
+ if (sender.hasPermission("autostart")) {
+ // Check if game and lobby worlds are null
+ if (TumbleManager.getGameWorld() != null) {
+ if (TumbleManager.getLobbyWorld() != null) {
+ // 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", 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", 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;
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Please enter a player amount between two and eight!");
+ }
+ }
+ 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!");
+ }
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Please link a lobby world first!");
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Please link a game world first!");
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + TumbleManager.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
new file mode 100644
index 0000000..ec145d1
--- /dev/null
+++ b/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java
@@ -0,0 +1,115 @@
+package com.MylesAndMore.tumble.commands;
+
+import com.MylesAndMore.tumble.TumbleManager;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+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
+ 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 (sender instanceof Player) {
+ // Check the sender entered the correct number of args
+ if (args.length == 3) {
+ double args0 = 0;
+ double args1 = 0;
+ double args2 = 0;
+ try {
+ args0 = Double.parseDouble(args[0]);
+ args1 = Double.parseDouble(args[1]);
+ args2 = Double.parseDouble(args[2]);
+ } catch (NumberFormatException nfe){
+ sender.sendMessage(ChatColor.RED + "Input arguments must be valid numbers.");
+ } 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();
+ sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
+ sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
+ sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
+ }
+ }
+ // If the sender entered no args, use their current location
+ else if (args.length == 0) {
+ Location senderPos = ((Player) sender).getLocation();
+ // 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();
+ sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
+ sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
+ sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
+ }
+ }
+ else {
+ 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;
+ double args2 = 0;
+ try {
+ args0 = Double.parseDouble(args[0]);
+ args1 = Double.parseDouble(args[1]);
+ args2 = Double.parseDouble(args[2]);
+ } catch (NumberFormatException nfe){
+ sender.sendMessage(ChatColor.RED + "Input arguments must be valid numbers.");
+ } 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();
+ sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
+ sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!");
+ sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead.");
+ }
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + "Please link a lobby world first!");
+ }
+ }
+ else {
+ sender.sendMessage(ChatColor.RED + TumbleManager.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 d27a5a8..695c248 100644
--- a/src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java
+++ b/src/main/java/com/MylesAndMore/tumble/commands/SetWorldConfig.java
@@ -3,6 +3,7 @@ package com.MylesAndMore.tumble.commands;
import com.MylesAndMore.tumble.TumbleManager;
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;
@@ -49,6 +50,9 @@ public class SetWorldConfig implements CommandExecutor {
if (!Objects.equals(TumbleManager.getLobbyWorld(), world)) {
TumbleManager.getPlugin().getConfig().set("gameWorld", world);
TumbleManager.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);
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!");
}
diff --git a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
index 9daa959..c138cda 100644
--- a/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
+++ b/src/main/java/com/MylesAndMore/tumble/commands/StartGame.java
@@ -1,19 +1,17 @@
package com.MylesAndMore.tumble.commands;
-import com.MylesAndMore.tumble.GameManager;
+import com.MylesAndMore.tumble.Game;
import com.MylesAndMore.tumble.TumbleManager;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import java.util.List;
+import java.util.Objects;
public class StartGame implements CommandExecutor {
- // Define the startGame method so that other classes can refrence it
- public void startGame(CommandSender sender, String[] args) {
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Check if sender has perms to run command
if (sender.hasPermission("tumble.start")) {
// Check if there is a lobbyWorld specified in config
@@ -22,28 +20,54 @@ public class StartGame implements CommandExecutor {
if (TumbleManager.getPlayersInLobby().size() > 1) {
// Check if there is a gameWorld specified in config
if (TumbleManager.getGameWorld() != null) {
- sender.sendMessage("Checking world, this could take a few moments...");
- // Use multiverse to load game world
- // If the load was successful, start game
- if (TumbleManager.getMVWorldManager().loadWorld(TumbleManager.getGameWorld())) {
- sender.sendMessage("Generating layers...");
- // Check which gamemode to initiate from the config file
- if (GameManager.createGame(TumbleManager.getPlugin().getConfig().getString("gameMode"))) {
- // If game type exists, send players to the world
- // At this point, layers have been generated, and items have been allotted from the createGame method
- sendWorld();
+ // Check if a game is already pending to start
+ 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())) {
+ // 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"));
+ }
+ }
+ }
+ // 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 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 type does not exist, give sender feedback
- sender.sendMessage(ChatColor.RED + "Failed to recognize game of type " + ChatColor.GRAY + TumbleManager.getPlugin().getConfig().getString("gameMode"));
+ 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
@@ -64,29 +88,6 @@ public class StartGame implements CommandExecutor {
else {
sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage());
}
- }
-
- public void sendWorld() {
- // Create Locations to scatter players around the first layer
-
- // While there are still players in the lobby, send them to the gameWorld
- // This is just a way of sending everybody in the lobby to the game
- for (List<Player> playersInLobby = TumbleManager.getPlayersInLobby(); playersInLobby.size() > 0; playersInLobby = TumbleManager.getPlayersInLobby()) {
- // Get a singular player from the player list
- Player aPlayer = playersInLobby.get(0);
- // Teleport that player to the spawn of the gameWorld
- aPlayer.teleport(Bukkit.getWorld(TumbleManager.getGameWorld()).getSpawnLocation());
- }
-
- // Add a little break because it can take the clients a bit to load into the new world
- // Then, transition to another method because this one is getting really long
- // In that method: set a flag to monitor the playerDeathEvent so we know when all the players have died
- // Also start music
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- startGame(sender, args);
return true;
}
}