From fe547e5b0767616d7ea1b4f94c57566589dbf4c3 Mon Sep 17 00:00:00 2001 From: Myles <43725835+MylesAndMore@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:48:04 +0000 Subject: allow players to specify args for winLoc --- .../MylesAndMore/tumble/commands/SetWinnerLoc.java | 60 +++++++++++++++++----- src/main/resources/plugin.yml | 2 +- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java b/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java index 88c4b74..ec145d1 100644 --- a/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java +++ b/src/main/java/com/MylesAndMore/tumble/commands/SetWinnerLoc.java @@ -18,20 +18,54 @@ public class SetWinnerLoc implements CommandExecutor { 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 (!((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."); + // 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 { - sender.sendMessage(ChatColor.RED + "Your coordinates cannot be zero!"); - sender.sendMessage(ChatColor.RED + "Use something like 0.5 (the middle of the block) instead."); + return false; } } // Check if the sender is the console @@ -47,10 +81,8 @@ public class SetWinnerLoc implements CommandExecutor { 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))) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 315797f..7066a27 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -24,7 +24,7 @@ commands: permission: start winlocation: description: Links the location to teleport the winning player of a game. - usage: '§cUsage: /tumble:winlocation ' + usage: '§cUsage: /tumble:winlocation [x] [y] [z]' permission: winlocation aliases: [win-location, winloc, win-loc] permissions: -- cgit v1.2.3