From 93dd4cfcc4e89448eb69d00b9a55145121467aa5 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 23 Aug 2021 13:57:50 -0400 Subject: [PATCH] refactoring, command restructure, bug fixes, glow rewrite --- pom.xml | 2 +- ...ommandManager.java => CommandHandler.java} | 18 +-- .../hideAndSeek/CommandTabCompleter.java | 36 ++++++ .../net/tylermurphy/hideAndSeek/Main.java | 20 ++-- .../hideAndSeek/commands/About.java | 4 +- .../hideAndSeek/commands/EnableBorder.java | 49 -------- .../hideAndSeek/commands/Help.java | 6 +- .../hideAndSeek/commands/SetBorder.java | 16 ++- .../hideAndSeek/commands/SetSeeker.java | 47 -------- .../commands/SetSpawnLocation.java | 2 +- .../hideAndSeek/commands/Start.java | 36 ++++-- .../hideAndSeek/commands/Stop.java | 9 +- .../EventListener.java} | 4 +- .../EventTick.java} | 14 +-- .../hideAndSeek/manager/TauntManager.java | 52 --------- .../manager/WorldborderManager.java | 50 -------- .../hideAndSeek/util/Functions.java | 108 ++++++++++++++++++ .../hideAndSeek/{ => util}/ICommand.java | 2 +- src/main/resources/plugin.yml | 2 +- 19 files changed, 225 insertions(+), 252 deletions(-) rename src/main/java/net/tylermurphy/hideAndSeek/{manager/CommandManager.java => CommandHandler.java} (76%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/CommandTabCompleter.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/commands/EnableBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/commands/SetSeeker.java rename src/main/java/net/tylermurphy/hideAndSeek/{manager/EventManager.java => events/EventListener.java} (97%) rename src/main/java/net/tylermurphy/hideAndSeek/{manager/TickManager.java => events/EventTick.java} (94%) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/manager/TauntManager.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java rename src/main/java/net/tylermurphy/hideAndSeek/{ => util}/ICommand.java (84%) diff --git a/pom.xml b/pom.xml index d245fcc..93b6b6a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy HideAndSeek - 1.1.2 + 1.2.0 Hide and Seek Plugin diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/CommandManager.java b/src/main/java/net/tylermurphy/hideAndSeek/CommandHandler.java similarity index 76% rename from src/main/java/net/tylermurphy/hideAndSeek/manager/CommandManager.java rename to src/main/java/net/tylermurphy/hideAndSeek/CommandHandler.java index b50247a..2703145 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/CommandManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/CommandHandler.java @@ -1,20 +1,24 @@ -package net.tylermurphy.hideAndSeek.manager; +package net.tylermurphy.hideAndSeek; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.ICommand; -import net.tylermurphy.hideAndSeek.commands.*; +import net.tylermurphy.hideAndSeek.commands.About; +import net.tylermurphy.hideAndSeek.commands.Help; +import net.tylermurphy.hideAndSeek.commands.SetBorder; +import net.tylermurphy.hideAndSeek.commands.SetSpawnLocation; +import net.tylermurphy.hideAndSeek.commands.Start; +import net.tylermurphy.hideAndSeek.commands.Stop; +import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; -public class CommandManager implements CommandExecutor { +public class CommandHandler { public static Map COMMAND_REGISTER = new LinkedHashMap(); @@ -29,10 +33,8 @@ public class CommandManager implements CommandExecutor { registerCommand(new Help()); registerCommand(new Start()); registerCommand(new Stop()); - registerCommand(new SetSeeker()); registerCommand(new SetSpawnLocation()); registerCommand(new SetBorder()); - registerCommand(new EnableBorder()); } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { @@ -54,7 +56,7 @@ public class CommandManager implements CommandExecutor { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return CommandManager.handleCommand(sender, command, label, args); + return CommandHandler.handleCommand(sender, command, label, args); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/CommandTabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/CommandTabCompleter.java new file mode 100644 index 0000000..778850f --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/CommandTabCompleter.java @@ -0,0 +1,36 @@ +package net.tylermurphy.hideAndSeek; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +public class CommandTabCompleter{ + + public static List handleTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(args.length == 1) { + return new ArrayList(CommandHandler.COMMAND_REGISTER.keySet()); + } else if(args.length > 1) { + if(!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) { + return null; + } else { + String[] usage = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()).getUsage().split(" "); + if(args.length - 2 < usage.length) { + String parameter = usage[args.length-2]; + if(parameter.equals("")) { + return null;//playerList.values().stream().map(p -> p.getName()).collect(Collectors.toList()); + } else { + List temp = new ArrayList(); + temp.add(parameter.replace("<", "").replace(">", "")); + return temp; + } + } else { + return null; + } + } + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index c96ee5f..508f4d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -2,6 +2,8 @@ package net.tylermurphy.hideAndSeek; import static net.tylermurphy.hideAndSeek.Store.*; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -11,10 +13,8 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.manager.CommandManager; -import net.tylermurphy.hideAndSeek.manager.EventManager; -import net.tylermurphy.hideAndSeek.manager.TickManager; -import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.events.EventListener; +import net.tylermurphy.hideAndSeek.events.EventTick; public class Main extends JavaPlugin implements Listener { @@ -25,7 +25,7 @@ public class Main extends JavaPlugin implements Listener { plugin = this; // Setup Initial Player Count - getServer().getPluginManager().registerEvents(new EventManager(), this); + getServer().getPluginManager().registerEvents(new EventListener(), this); for (Player player : Bukkit.getServer().getOnlinePlayers()) { playerList.put(player.getName(), player); } @@ -45,13 +45,13 @@ public class Main extends JavaPlugin implements Listener { worldborderEnabled = getConfig().getBoolean("borderEnabled"); // Register Commands - CommandManager.registerCommands(); + CommandHandler.registerCommands(); // Start Tick Timer Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){ public void run(){ try{ - TickManager.onTick(); + EventTick.onTick(); } catch (Exception e) { e.printStackTrace(); } @@ -65,7 +65,11 @@ public class Main extends JavaPlugin implements Listener { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - return CommandManager.handleCommand(sender, cmd, label, args); + return CommandHandler.handleCommand(sender, cmd, label, args); + } + + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return CommandTabCompleter.handleTabComplete(sender, command, label, args); } } 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() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java b/src/main/java/net/tylermurphy/hideAndSeek/events/EventListener.java similarity index 97% rename from src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java rename to src/main/java/net/tylermurphy/hideAndSeek/events/EventListener.java index 26a41f1..7c095b1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/EventListener.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.manager; +package net.tylermurphy.hideAndSeek.events; import static net.tylermurphy.hideAndSeek.Store.*; @@ -25,7 +25,7 @@ import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Functions; -public class EventManager implements Listener { +public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java b/src/main/java/net/tylermurphy/hideAndSeek/events/EventTick.java similarity index 94% rename from src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java rename to src/main/java/net/tylermurphy/hideAndSeek/events/EventTick.java index 9172b0b..a0bf36a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/EventTick.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.manager; +package net.tylermurphy.hideAndSeek.events; import static net.tylermurphy.hideAndSeek.Store.*; @@ -20,7 +20,7 @@ import org.bukkit.potion.PotionEffectType; import net.tylermurphy.hideAndSeek.commands.Stop; import net.tylermurphy.hideAndSeek.util.Functions; -public class TickManager { +public class EventTick { static int tick = 0; @@ -98,11 +98,6 @@ public class TickManager { player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); } - if(glowTime > 0) { - player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 1000000, 1, false, false)); - } else { - player.removePotionEffect(PotionEffectType.GLOWING); - } } for(String playerName : Hider.getEntries()) { Player player = playerList.get(playerName); @@ -116,6 +111,11 @@ public class TickManager { if(distance > temp) { distance = temp; } + if(glowTime > 0) { + Functions.setGlow(player, seeker, true); + } else { + Functions.setGlow(player, seeker, false); + } } switch(tick%10) { case 0: diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/TauntManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/TauntManager.java deleted file mode 100644 index 6465e44..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/TauntManager.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.tylermurphy.hideAndSeek.manager; - -import static net.tylermurphy.hideAndSeek.Store.*; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; - -public class TauntManager { - -public static void schedule() { - - Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){ - - public void run() { - int temp = gameId; - while(true) { - if(tauntPlayer != null && !tauntPlayer.equals("")) { - try { Thread.sleep(1000); } catch (InterruptedException e) {} - if(gameId != temp) break; - continue; - } - try { Thread.sleep(1000*60); } catch (InterruptedException e) {} - if(gameId != temp) break; - if(Math.random() > .9) { - Player taunted = null; - int rand = (int) (Math.random()*Hider.getEntries().size()); - for(Player player : playerList.values()) { - if(Hider.hasEntry(player.getName())) { - rand--; - if(rand==0) { - taunted = player; - break; - } - } - } - if(taunted != null) { - taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted."); - Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " A random hider will be taunted in the next 30s"); - try { Thread.sleep(1000*30); } catch (InterruptedException e) {} - if(gameId != temp) break; - tauntPlayer = taunted.getName(); - } - } - } - } - }); - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java deleted file mode 100644 index c695d1d..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.tylermurphy.hideAndSeek.manager; - -import static net.tylermurphy.hideAndSeek.Store.*; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldBorder; - -import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.Main; - -public class WorldborderManager { - - public static void schedule() { - - Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){ - - public void run() { - int temp = gameId; - while(true) { - try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {} - if(gameId != temp) break; - if(currentWorldborderSize-100 > 100) { - Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border> " + ChatColor.WHITE + "Worldborder decreacing by 100 blocks over the next 30s"); - currentWorldborderSize -= 100; - decreaseBorder = true; - } else { - break; - } - } - } - }); - } - - public static void reset() { - if(worldborderEnabled) { - World world = Bukkit.getWorld("world"); - WorldBorder border = world.getWorldBorder(); - border.setSize(worldborderSize); - border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); - currentWorldborderSize = worldborderSize; - } else { - World world = Bukkit.getWorld("world"); - WorldBorder border = world.getWorldBorder(); - border.setSize(30000000); - border.setCenter(0, 0); - } - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java index 73e0fb0..73d6e94 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java @@ -4,7 +4,15 @@ import static net.tylermurphy.hideAndSeek.Store.Hider; import static net.tylermurphy.hideAndSeek.Store.Seeker; import static net.tylermurphy.hideAndSeek.Store.Spectator; import static net.tylermurphy.hideAndSeek.Store.board; +import static net.tylermurphy.hideAndSeek.Store.currentWorldborderSize; +import static net.tylermurphy.hideAndSeek.Store.decreaseBorder; +import static net.tylermurphy.hideAndSeek.Store.gameId; import static net.tylermurphy.hideAndSeek.Store.playerList; +import static net.tylermurphy.hideAndSeek.Store.tauntPlayer; +import static net.tylermurphy.hideAndSeek.Store.worldborderDelay; +import static net.tylermurphy.hideAndSeek.Store.worldborderEnabled; +import static net.tylermurphy.hideAndSeek.Store.worldborderPosition; +import static net.tylermurphy.hideAndSeek.Store.worldborderSize; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -14,6 +22,8 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.WorldBorder; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -32,6 +42,11 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; +import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; + +import net.tylermurphy.hideAndSeek.Main; public class Functions { @@ -154,4 +169,97 @@ public class Functions { } } + public static void setGlow(Player player, Player target, boolean glowing) { + PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA); + packet.getIntegers().write(0, target.getEntityId()); + WrappedDataWatcher watcher = new WrappedDataWatcher(); + Serializer serializer = Registry.get(Byte.class); + watcher.setEntity(target); + if(glowing) { + watcher.setObject(0, serializer, (byte) (0x40)); + } else { + watcher.setObject(0, serializer, (byte) (0x0)); + } + packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); + try { + protocolManager.sendServerPacket(player, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + public static void scheduleTaunt() { + Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){ + + public void run() { + int temp = gameId; + while(true) { + if(tauntPlayer != null && !tauntPlayer.equals("")) { + try { Thread.sleep(1000); } catch (InterruptedException e) {} + if(gameId != temp) break; + continue; + } + try { Thread.sleep(1000*60); } catch (InterruptedException e) {} + if(gameId != temp) break; + if(Math.random() > .8) { + Player taunted = null; + int rand = (int) (Math.random()*Hider.getEntries().size()); + for(Player player : playerList.values()) { + if(Hider.hasEntry(player.getName())) { + rand--; + if(rand==0) { + taunted = player; + break; + } + } + } + if(taunted != null) { + taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted."); + Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " A random hider will be taunted in the next 30s"); + try { Thread.sleep(1000*30); } catch (InterruptedException e) {} + if(gameId != temp) break; + tauntPlayer = taunted.getName(); + } + } + } + } + }); + } + + public static void scheduleWorldborder() { + + Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){ + + public void run() { + int temp = gameId; + while(true) { + try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {} + if(gameId != temp) break; + if(currentWorldborderSize-100 > 100) { + Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border> " + ChatColor.WHITE + "Worldborder decreacing by 100 blocks over the next 30s"); + currentWorldborderSize -= 100; + decreaseBorder = true; + } else { + break; + } + } + } + }); + } + + public static void resetWorldborder() { + if(worldborderEnabled) { + World world = Bukkit.getWorld("world"); + WorldBorder border = world.getWorldBorder(); + border.setSize(worldborderSize); + border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); + currentWorldborderSize = worldborderSize; + } else { + World world = Bukkit.getWorld("world"); + WorldBorder border = world.getWorldBorder(); + border.setSize(30000000); + border.setCenter(0, 0); + } + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java similarity index 84% rename from src/main/java/net/tylermurphy/hideAndSeek/ICommand.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java index 304384f..373096f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek; +package net.tylermurphy.hideAndSeek.util; import org.bukkit.command.CommandSender; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c14937a..4250258 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.1.2 +version: 1.2.0 author: KenshinEto load: STARTUP api-version: 1.17