From 93dd4cfcc4e89448eb69d00b9a55145121467aa5 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 23 Aug 2021 13:57:50 -0400 Subject: refactoring, command restructure, bug fixes, glow rewrite --- .../tylermurphy/hideAndSeek/commands/About.java | 4 +- .../hideAndSeek/commands/EnableBorder.java | 49 ---------------------- .../net/tylermurphy/hideAndSeek/commands/Help.java | 6 +-- .../hideAndSeek/commands/SetBorder.java | 16 ++++--- .../hideAndSeek/commands/SetSeeker.java | 47 --------------------- .../hideAndSeek/commands/SetSpawnLocation.java | 2 +- .../tylermurphy/hideAndSeek/commands/Start.java | 36 ++++++++++------ .../net/tylermurphy/hideAndSeek/commands/Stop.java | 9 ++-- 8 files changed, 47 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/commands/EnableBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/commands/SetSeeker.java (limited to 'src/main/java/net/tylermurphy/hideAndSeek/commands') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java index 051732c..c500dd6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java @@ -3,13 +3,13 @@ package net.tylermurphy.hideAndSeek.commands; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import net.tylermurphy.hideAndSeek.ICommand; +import net.tylermurphy.hideAndSeek.util.ICommand; public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(1.1.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(1.2.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/EnableBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/EnableBorder.java deleted file mode 100644 index 6c925e2..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/EnableBorder.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.tylermurphy.hideAndSeek.commands; - -import org.bukkit.command.CommandSender; - -import net.tylermurphy.hideAndSeek.ICommand; -import net.tylermurphy.hideAndSeek.manager.WorldborderManager; - -import static net.tylermurphy.hideAndSeek.Store.*; - -public class EnableBorder implements ICommand { - - public void execute(CommandSender sender, String[] args) { - if(!status.equals("Standby") && !status.equals("Setup")) { - sender.sendMessage(errorPrefix + "Game is currently in session"); - return; - } - if(worldborderPosition == null) { - sender.sendMessage(errorPrefix + "Please setup worldborder info before enabling"); - return; - } - boolean bool; - try { bool = Boolean.parseBoolean(args[0]); } catch (Exception e) { - sender.sendMessage(errorPrefix + "Please enter true or false"); - return; - } - if(spawnPosition != null && worldborderPosition != null && spawnPosition.distance(worldborderPosition) > 100) { - sender.sendMessage(errorPrefix + "Cannot enable worldborder, spawn position is outside 100 blocks from worldborder"); - return; - } - sender.sendMessage(messagePrefix + "Set worldborder to "+args[0]); - getConfig().set("borderEnabled", bool); - worldborderEnabled = bool; - saveConfig(); - WorldborderManager.reset(); - } - - public String getLabel() { - return "enableBorder"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Enables or disables worldborder"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/Help.java index 1839e41..a74464e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/Help.java @@ -3,14 +3,14 @@ package net.tylermurphy.hideAndSeek.commands; import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.ICommand; -import net.tylermurphy.hideAndSeek.manager.CommandManager; +import net.tylermurphy.hideAndSeek.CommandHandler; +import net.tylermurphy.hideAndSeek.util.ICommand; public class Help implements ICommand { public void execute(CommandSender sender, String[] args) { String message = ""; - for(ICommand command : CommandManager.COMMAND_REGISTER.values()) { + for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { message += String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription()+"\n"); } message = message.substring(0, message.length()-2); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetBorder.java index 6482c45..a485c91 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetBorder.java @@ -4,8 +4,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.ICommand; -import net.tylermurphy.hideAndSeek.manager.WorldborderManager; +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; @@ -21,7 +21,11 @@ public class SetBorder implements ICommand { return; } if(args.length < 2) { - sender.sendMessage(errorPrefix + "Please enter worldborder size and delay"); + getConfig().set("borderEnabled", false); + worldborderEnabled = false; + saveConfig(); + sender.sendMessage(messagePrefix + "Disabled worldborder."); + Functions.resetWorldborder(); return; } int num,delay; @@ -53,8 +57,10 @@ public class SetBorder implements ICommand { getConfig().set("borderPosition", newWorldborderPosition); getConfig().set("borderSize", num); getConfig().set("borderDelay", delay); + getConfig().set("borderEnabled", false); + worldborderEnabled = true; saveConfig(); - WorldborderManager.reset(); + Functions.resetWorldborder(); } public String getLabel() { @@ -66,7 +72,7 @@ public class SetBorder implements ICommand { } public String getDescription() { - return "Sets worldboarder's center location, size in blocks, and delay in minutes"; + return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSeeker.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSeeker.java deleted file mode 100644 index 5a2fc4b..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSeeker.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.tylermurphy.hideAndSeek.commands; - -import static net.tylermurphy.hideAndSeek.Store.*; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.ICommand; - -public class SetSeeker implements ICommand { - - public void execute(CommandSender sender, String[] args) { - if(!status.equals("Standby") && !status.equals("Setup")) { - sender.sendMessage(errorPrefix + "Game is currently in session"); - return; - } - String playerName; - if(args.length < 1) { - playerName = sender.getName(); - } else { - playerName = args[0]; - } - Player player = playerList.get(playerName); - if(player == null) { - sender.sendMessage(errorPrefix + "Invalid player: " + playerName); - return; - } - for(Player temp : playerList.values()) { - Hider.addEntry(temp.getName()); - } - Seeker.addEntry(player.getName()); - sender.sendMessage(String.format("%s Set %s as the seaker.", messagePrefix, playerName)); - } - - public String getLabel() { - return "setSeeker"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets the current or select player as the seeker"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java index b341584..48a8d60 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java @@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.ICommand; +import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java index d087839..45797b8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java @@ -9,14 +9,14 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.manager.TauntManager; -import net.tylermurphy.hideAndSeek.manager.WorldborderManager; import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; +import java.util.Random; + public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { @@ -28,14 +28,26 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + "Game is already in session"); return; } - if(Hider.getSize() < 1) { - sender.sendMessage(errorPrefix + "No Hiders were found"); + if(playerList.size() < 2) { + sender.sendMessage(errorPrefix + "You must have at least 2 players to start"); return; } - if(Seeker.getSize() < 1) { - sender.sendMessage(errorPrefix + "No Seekers were found"); + + String seekerName; + if(args.length < 1) { + seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName(); + } else { + seekerName = args[0]; + } + Player seeker = playerList.get(seekerName); + if(seeker == null) { + sender.sendMessage(errorPrefix + "Invalid player: " + seekerName); return; } + for(Player temp : playerList.values()) { + Hider.addEntry(temp.getName()); + } + Seeker.addEntry(seeker.getName()); for(Player player : playerList.values()) { player.getInventory().clear(); @@ -59,7 +71,7 @@ public class Start implements ICommand { player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); } } - WorldborderManager.reset(); + Functions.resetWorldborder(); status = "Starting"; int temp = gameId; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); @@ -118,9 +130,9 @@ public class Start implements ICommand { }, 20 * 30); if(worldborderEnabled) { - WorldborderManager.schedule(); + Functions.scheduleWorldborder(); } - TauntManager.schedule(); + Functions.scheduleTaunt(); } public String getLabel() { @@ -128,11 +140,11 @@ public class Start implements ICommand { } public String getUsage() { - return ""; + return ""; } public String getDescription() { - return "Starts the game"; + return "Starts the game either with a random seeker or chosen one"; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java index 87abf49..1c31ccd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java @@ -10,8 +10,8 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import net.tylermurphy.hideAndSeek.ICommand; -import net.tylermurphy.hideAndSeek.manager.WorldborderManager; +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; public class Stop implements ICommand { @@ -43,8 +43,11 @@ public class Stop implements ICommand { player.removePotionEffect(effect.getType()); } player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); + for(Player temp : playerList.values()) { + Functions.setGlow(player, temp, false); + } } - WorldborderManager.reset(); + Functions.resetWorldborder(); } public String getUsage() { -- cgit v1.2.3-freya