diff options
author | Myles <mylesandmore9@gmail.com> | 2022-12-07 21:13:33 -0600 |
---|---|---|
committer | Myles <mylesandmore9@gmail.com> | 2022-12-07 21:13:33 -0600 |
commit | c7d259a122ebd8300d84914032e247a5cc4a7f01 (patch) | |
tree | 00fa7092bbb4923bc4a570288918d602e09a43a5 | |
parent | 1a8b11f68e1e8089f5c145e4dc7335c296d5e6a4 (diff) | |
download | Tumble-c7d259a122ebd8300d84914032e247a5cc4a7f01.tar.gz Tumble-c7d259a122ebd8300d84914032e247a5cc4a7f01.tar.bz2 Tumble-c7d259a122ebd8300d84914032e247a5cc4a7f01.zip |
add feature: seperate winning player tp
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/Game.java | 9 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/Main.java | 1 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java | 85 | ||||
-rw-r--r-- | src/main/resources/config.yml | 10 | ||||
-rw-r--r-- | src/main/resources/plugin.yml | 8 |
6 files changed, 113 insertions, 4 deletions
@@ -27,8 +27,8 @@ once this list is complete and all bugs are fixed, we *should* be ready for rele - [x] prevent players from joining/autojoining during a game - [x] keep track of when someone wins; start a new round when this happens - [x] keep track of how many wins each player has; end the game when a player reaches 3 - - [ ] add a section in the config for a place to tp the winning player - - [ ] add logic to do this + - [x] add a section in the config for a place to tp the winning player + - [x] add logic to do this ## configuration/customization diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/tumble/Game.java index cb49443..f3c7ef4 100644 --- a/src/main/java/com/MylesAndMore/tumble/Game.java +++ b/src/main/java/com/MylesAndMore/tumble/Game.java @@ -370,8 +370,13 @@ public class Game { displayMessage(gamePlayers, ChatColor.BLUE + "Returning to lobby in ten seconds..."); // Wait 10s (200t), then Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> { - // Set their gamemodes to survival - setGamemode(gamePlayers, GameMode.SURVIVAL); + // 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"))); + // 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()); diff --git a/src/main/java/com/MylesAndMore/tumble/Main.java b/src/main/java/com/MylesAndMore/tumble/Main.java index 5c08907..04c8053 100644 --- a/src/main/java/com/MylesAndMore/tumble/Main.java +++ b/src/main/java/com/MylesAndMore/tumble/Main.java @@ -14,6 +14,7 @@ public class Main extends JavaPlugin{ this.getCommand("reload").setExecutor(new ReloadCommand()); this.getCommand("link").setExecutor(new SetWorldConfig()); this.getCommand("start").setExecutor(new StartGame()); + this.getCommand("winlocation").setExecutor(new SetWinnerLoc()); // Save the default config file (packaged in the JAR) this.saveDefaultConfig(); 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..8a76383 --- /dev/null +++ b/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java @@ -0,0 +1,85 @@ +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; + +import java.util.Objects; + +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) { + Location senderPos = ((Player) sender).getLocation(); + // if so, check if any of their locations are zero + if (!((Objects.equals(senderPos.getX(), "0") || Objects.equals(senderPos.getX(), "-0") || Objects.equals(senderPos.getY(), "0") || Objects.equals(senderPos.getY(), "-0") || Objects.equals(senderPos.getZ(), "0") || Objects.equals(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."); + } + } + // 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."); + return false; + } catch (Exception e){ + sender.sendMessage(ChatColor.RED + "Invalid input arguments."); + return false; + } + // 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/resources/config.yml b/src/main/resources/config.yml index a881556..0f059f2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,6 +10,16 @@ permissionMessage: You do not have permission to perform this command! # Default is mixed gameMode: mixed +# Customize the place that the winner is teleported after a game ends +# This is an optional value +# Default is nothing +winnerTeleport: + # These coordinates cannot be zero! The teleport will fail if any of them are. + # Use something like 0.5 instead. + 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 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dd24bcc..3dc3b90 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -22,6 +22,11 @@ commands: description: Force starts a Tumble match. usage: '§cUsage: /tumble:start' permission: start + winlocation: + description: Links the location to teleport the winning player of a game. + usage: '§cUsage: /tumble:winlocation <x> <y> <z>' + permission: winlocation + aliases: [win-location, winloc, win-loc] permissions: reload: description: Allows you to reload the plugin's config. @@ -32,3 +37,6 @@ permissions: start: description: Allows you to start a Tumble match. default: op + winlocation: + description: Allows you to link a win location. + default: op |