From fc87556d8c0cc92b856ad682e4b3cbc964514eee Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 20 Oct 2021 20:14:01 -0400 Subject: [PATCH] teams reference rewrite --- .../hideAndSeek/{Store.java => Config.java} | 36 +-- .../net/tylermurphy/hideAndSeek/Main.java | 24 +- .../hideAndSeek/bukkit/CommandHandler.java | 9 +- .../hideAndSeek/bukkit/EventListener.java | 68 +++--- .../tylermurphy/hideAndSeek/bukkit/Tick.java | 59 ++--- .../hideAndSeek/command/About.java | 2 - .../tylermurphy/hideAndSeek/command/Help.java | 1 - .../{util => command}/ICommand.java | 2 +- .../tylermurphy/hideAndSeek/command/Join.java | 22 +- .../hideAndSeek/command/Leave.java | 22 +- .../hideAndSeek/command/Reload.java | 20 +- .../hideAndSeek/command/SaveMap.java | 7 +- .../hideAndSeek/command/SetBorder.java | 12 +- .../hideAndSeek/command/SetExitLocation.java | 6 +- .../hideAndSeek/command/SetLobbyLocation.java | 6 +- .../hideAndSeek/command/SetSpawnLocation.java | 6 +- .../hideAndSeek/command/Setup.java | 3 +- .../hideAndSeek/command/Start.java | 216 ++++++++++-------- .../tylermurphy/hideAndSeek/command/Stop.java | 30 +-- .../tylermurphy/hideAndSeek/events/Glow.java | 20 +- .../tylermurphy/hideAndSeek/events/Taunt.java | 20 +- .../hideAndSeek/events/Worldborder.java | 23 +- .../tylermurphy/hideAndSeek/util/Board.java | 178 +++++++++++++++ .../hideAndSeek/util/Functions.java | 184 --------------- .../tylermurphy/hideAndSeek/util/Util.java | 57 +++++ 25 files changed, 531 insertions(+), 502 deletions(-) rename src/main/java/net/tylermurphy/hideAndSeek/{Store.java => Config.java} (87%) rename src/main/java/net/tylermurphy/hideAndSeek/{util => command}/ICommand.java (83%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Board.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Util.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Config.java similarity index 87% rename from src/main/java/net/tylermurphy/hideAndSeek/Store.java rename to src/main/java/net/tylermurphy/hideAndSeek/Config.java index 537ad7b..fe83dd1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Config.java @@ -1,36 +1,13 @@ package net.tylermurphy.hideAndSeek; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; -public class Store { - - public static Map - playerList = new HashMap(); - - public static List - Hider = new ArrayList(), - Seeker = new ArrayList(), - Spectator = new ArrayList(), - Deaths = new ArrayList(); - - public static Scoreboard - board; - - public static Team - HiderTeam, - SeekerTeam, - SpectatorTeam; +public class Config { public static String messagePrefix, @@ -42,8 +19,7 @@ public class Store { warningPrefix, spawnWorld, exitWorld, - lobbyWorld, - status = "Standby"; + lobbyWorld; public static Vector spawnPosition, @@ -55,18 +31,14 @@ public class Store { nametagsVisible, permissionsRequired, announceMessagesToNonPlayers, - lobbyStarted = false, - worldborderEnabled = false, - runningBackup = false; + worldborderEnabled; public static int minPlayers, - gameId = 0, worldborderSize, worldborderDelay, currentWorldborderSize, - gameLength, - timeLeft = 0; + gameLength; public static FileConfiguration getConfig() { return Main.plugin.getConfig(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 67c9d16..648df25 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,12 +1,15 @@ package net.tylermurphy.hideAndSeek; import java.io.File; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; @@ -18,15 +21,24 @@ import net.tylermurphy.hideAndSeek.bukkit.Tick; import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.events.Taunt; import net.tylermurphy.hideAndSeek.events.Worldborder; +import net.tylermurphy.hideAndSeek.util.Board; public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root; - public static Taunt taunt; - public static Glow glow; - public static Worldborder worldborder; + public Taunt taunt; + public Glow glow; + public Worldborder worldborder; + + public Board board; + + public Map playerList = new HashMap(); + + public String status = "Standby"; + + public int timeLeft = 0, gameId = 0;; private BukkitTask onTickTask; @@ -38,13 +50,17 @@ public class Main extends JavaPlugin implements Listener { getServer().getPluginManager().registerEvents(new EventListener(), this); // Init Configuration - Store.loadConfig(); + Config.loadConfig(); // Register Commands CommandHandler.registerCommands(); // Get Data Folder root = this.getServer().getWorldContainer(); + + //Board + board = new Board(); + board.init(); // Start Tick Timer onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java index f15e68b..23a37a1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.bukkit; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.Arrays; import java.util.LinkedHashMap; @@ -10,8 +10,8 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.util.ICommand; public class CommandHandler { @@ -40,6 +40,9 @@ public class CommandHandler { } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!Main.plugin.board.isReady()) { + Main.plugin.board.reload(); + } if(sender instanceof Player == false) { sender.sendMessage(errorPrefix + "This command can only be run as a player."); } else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { @@ -49,7 +52,7 @@ public class CommandHandler { COMMAND_REGISTER.get("about").execute(sender, null); } } else { - if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && runningBackup) { + if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && SaveMap.runningBackup) { sender.sendMessage(errorPrefix + "Map save is currently in progress. Try again later."); } else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { sender.sendMessage(errorPrefix + "You are not allowed to run this command."); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 8823e89..393be5b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.bukkit; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -24,19 +24,22 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Functions; import net.tylermurphy.hideAndSeek.util.Packet; +import net.tylermurphy.hideAndSeek.util.Util; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.Start; public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { event.getPlayer().setLevel(0); - HiderTeam.removeEntry(event.getPlayer().getName()); - SeekerTeam.removeEntry(event.getPlayer().getName()); - SpectatorTeam.removeEntry(event.getPlayer().getName()); - if(!Functions.setup()) return; + if(Main.plugin.board.isReady()) { + Main.plugin.board.remove(event.getPlayer()); + } else { + Main.plugin.board.init(); + } + if(!Util.isSetup()) return; if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)){ event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); event.getPlayer().setGameMode(GameMode.ADVENTURE); @@ -45,34 +48,20 @@ public class EventListener implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { - if(!playerList.containsKey(event.getPlayer().getName())) return; - playerList.remove(event.getPlayer().getName()); - Hider.remove(event.getPlayer().getName()); - HiderTeam.removeEntry(event.getPlayer().getName()); - Seeker.remove(event.getPlayer().getName()); - SeekerTeam.removeEntry(event.getPlayer().getName()); - Spectator.remove(event.getPlayer().getName()); - SpectatorTeam.removeEntry(event.getPlayer().getName()); + Main.plugin.board.remove(event.getPlayer()); } @EventHandler public void onKick(PlayerKickEvent event) { - if(!playerList.containsKey(event.getPlayer().getName())) return; - playerList.remove(event.getPlayer().getName()); - Hider.remove(event.getPlayer().getName()); - HiderTeam.removeEntry(event.getPlayer().getName()); - Seeker.remove(event.getPlayer().getName()); - SeekerTeam.removeEntry(event.getPlayer().getName()); - Spectator.remove(event.getPlayer().getName()); - SpectatorTeam.removeEntry(event.getPlayer().getName()); + Main.plugin.board.remove(event.getPlayer()); } @EventHandler public void onEntityDamage(EntityDamageEvent event) { if(event.getEntity() instanceof Player) { Player p = (Player) event.getEntity(); - if(!playerList.containsKey(p.getName())) return; - if(!status.equals("Playing")) { + if(!Main.plugin.board.isPlayer(p)) return; + if(!Main.plugin.status.equals("Playing")) { event.setCancelled(true); return; } @@ -81,9 +70,8 @@ public class EventListener implements Listener { Entity damager = ((EntityDamageByEntityEvent)event).getDamager(); if(damager instanceof Player) { attacker = (Player) damager; - if(Hider.contains(attacker.getName()) && Hider.contains(p.getName())) event.setCancelled(true); - if(Seeker.contains(attacker.getName()) && Seeker.contains(p.getName())) event.setCancelled(true); - if(Spectator.contains(attacker.getName())) event.setCancelled(true); + if(Main.plugin.board.onSameTeam(p, p)) event.setCancelled(true); + if(Main.plugin.board.isSpectator(p)) event.setCancelled(true); } } Player player = (Player) event.getEntity(); @@ -93,33 +81,31 @@ public class EventListener implements Listener { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); - if(Seeker.contains(event.getEntity().getName())) { + if(Main.plugin.board.isSeeker(player)) { Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s was killed", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE)); } - if(Hider.contains(event.getEntity().getName())) { + if(Main.plugin.board.isHider(player)) { if(attacker == null) { - Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); + Util.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); } else { - Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found by %s%s%s and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE, ChatColor.RED, attacker.getName(), ChatColor.WHITE)); + Util.broadcastMessage(String.format(messagePrefix + "%s%s%s was found by %s%s%s and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE, ChatColor.RED, attacker.getName(), ChatColor.WHITE)); } - Hider.remove(player.getName()); - Seeker.add(player.getName()); - SeekerTeam.addEntry(player.getName()); + Main.plugin.board.addSeeker(player); } - Functions.resetPlayer(player); + Start.resetPlayer(player); } } } @EventHandler public void onProjectile(ProjectileLaunchEvent event) { - if(!status.equals("Playing")) return; + if(Main.plugin.status.equals("Playing")) return; if(event.getEntity() instanceof Snowball) { Snowball snowball = (Snowball) event.getEntity(); if(snowball.getShooter() instanceof Player) { Player player = (Player) snowball.getShooter(); - if(Hider.contains(player.getName())) { - Main.glow.onProjectilve(); + if(Main.plugin.board.isHider(player)) { + Main.plugin.glow.onProjectilve(); snowball.remove(); player.getInventory().remove(Material.SNOWBALL); } @@ -130,7 +116,7 @@ public class EventListener implements Listener { @EventHandler public void onFoodLevelChange(FoodLevelChangeEvent event) { if(event.getEntity() instanceof Player) { - if(!playerList.containsKey(event.getEntity().getName())) return; + if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; event.setCancelled(true); } } @@ -139,7 +125,7 @@ public class EventListener implements Listener { public void onPlayerRegainHealth(EntityRegainHealthEvent event) { if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { if(event.getEntity() instanceof Player) { - if(!playerList.containsKey(event.getEntity().getName())) return; + if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; event.setCancelled(true); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java index 7224210..3fb48d6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java @@ -1,41 +1,33 @@ package net.tylermurphy.hideAndSeek.bukkit; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.entity.Player; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.Stop; -import net.tylermurphy.hideAndSeek.util.Functions; import net.tylermurphy.hideAndSeek.util.Packet; +import net.tylermurphy.hideAndSeek.util.Util; public class Tick { static int tick = 0; public static void onTick() { - - if(board == null) { - Functions.loadScoreboard(); - } - if(status.equals("Standby")) { - tick = 0; - } - - if(status.equals("Playing")) { - onPlaying(); - } + if(Main.plugin.status.equals("Standby")) tick = 0; + else if(Main.plugin.status.equals("Playing")) onPlaying(); - if(( status.equals("Starting") || status.equals("Playing") ) && Hider.size() < 1) { + if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeHider() < 1) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "All hiders have been found."); - else Functions.broadcastMessage(gameoverPrefix + "All hiders have been found."); + else Util.broadcastMessage(gameoverPrefix + "All hiders have been found."); Stop.onStop(); } - if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.size() < 1) { + if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeSeeker() < 1) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "All seekers have quit."); - else Functions.broadcastMessage(abortPrefix + "All seekers have quit."); + else Util.broadcastMessage(abortPrefix + "All seekers have quit."); Stop.onStop(); } @@ -43,32 +35,31 @@ public class Tick { private static void onPlaying() { - tick ++; + if(tick<1000000) tick++; + else tick = 1; - for(String playerName : Hider) { - Player player = playerList.get(playerName); + for(Player hider : Main.plugin.board.getHiders()) { int distance = 100; - for(String seekerName : Seeker) { - Player seeker = playerList.get(seekerName); - int temp = (int) player.getLocation().distance(seeker.getLocation()); + for(Player seeker : Main.plugin.board.getSeekers()) { + int temp = (int) hider.getLocation().distance(seeker.getLocation()); if(distance > temp) { distance = temp; } } switch(tick%10) { case 0: - if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); - if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 3: - if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); - if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 6: - if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 9: - if(distance < 20) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; } @@ -76,13 +67,13 @@ public class Tick { if(tick%20 == 0) { if(gameLength > 0) { - timeLeft--; - for(Player player : playerList.values()) { - player.setLevel(timeLeft); + Main.plugin.timeLeft--; + for(Player player : Main.plugin.board.getPlayers()) { + player.setLevel(Main.plugin.timeLeft); } - if(timeLeft < 1) { + if(Main.plugin.timeLeft < 1) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!"); - else Functions.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!"); + else Util.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!"); Stop.onStop(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 3c4a8f0..4b207fb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -3,8 +3,6 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import net.tylermurphy.hideAndSeek.util.ICommand; - public class About implements ICommand { public void execute(CommandSender sender, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index f33717e..e38c19a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -4,7 +4,6 @@ import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; -import net.tylermurphy.hideAndSeek.util.ICommand; public class Help implements ICommand { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java similarity index 83% rename from src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index 373096f..928787e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.util; +package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 5168e25..e70411e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -7,15 +7,15 @@ import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Functions.setup()) { + if(!Util.isSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } @@ -24,21 +24,19 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + "An internal error has occured"); return; } - if(playerList.containsKey(player.getName())){ + if(Main.plugin.board.isPlayer(player)){ sender.sendMessage(errorPrefix + "You are already in the lobby/game"); return; } - playerList.put(player.getName(), player); - if(status.equals("Standby")) { - Hider.add(player.getName()); - HiderTeam.addEntry(player.getName()); + + if(Main.plugin.status.equals("Standby")) { + Main.plugin.board.addHider(player); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); - else Functions.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); + else Util.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.setGameMode(GameMode.ADVENTURE); } else { - Spectator.add(player.getName()); - SpectatorTeam.addEntry(player.getName()); + Main.plugin.board.addSeeker(player); player.sendMessage(messagePrefix + "You have joined mid game and became a spectator"); player.setGameMode(GameMode.SPECTATOR); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 4dec452..d79d019 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -5,15 +5,15 @@ import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; public class Leave implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Functions.setup()) { + if(!Util.isSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } @@ -22,19 +22,13 @@ public class Leave implements ICommand { sender.sendMessage(errorPrefix + "An internal error has occured"); return; } - if(!playerList.containsKey(player.getName())) { + if(!Main.plugin.board.isPlayer(player)) { sender.sendMessage(errorPrefix + "You are currently not in the lobby"); return; } - if(!Seeker.contains(player.getName())) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); - else Functions.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); - } - playerList.remove(player.getName()); - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - HiderTeam.removeEntry(player.getName()); - SeekerTeam.removeEntry(player.getName()); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); + else Util.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); + Main.plugin.board.remove(player); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 438ab26..e7ab942 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,29 +1,23 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Store; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.Config; -import static net.tylermurphy.hideAndSeek.Store.*; - -import java.util.HashMap; +import static net.tylermurphy.hideAndSeek.Config.*; public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!status.equals("Standby")) { + + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } - Store.loadConfig(); - try { - Functions.loadScoreboard(); - } catch(Exception e) {} + Config.loadConfig(); + Main.plugin.board.reload(); sender.sendMessage(messagePrefix + "Reloaded the config"); - playerList = new HashMap(); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 2c7e75a..f6fe228 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.io.File; import java.io.FileInputStream; @@ -16,12 +16,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.ICommand; public class SaveMap implements ICommand { + public static boolean runningBackup = false; + public void execute(CommandSender sender, String[] args) { - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index e8ad2c9..d453871 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.HashMap; import java.util.Map; @@ -9,13 +9,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.events.Worldborder; public class SetBorder implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } @@ -30,7 +30,7 @@ public class SetBorder implements ICommand { addToSection("worldBorder",temp); saveConfig(); sender.sendMessage(messagePrefix + "Disabled worldborder."); - Functions.resetWorldborder(spawnWorld); + Worldborder.resetWorldborder(spawnWorld); return; } int num,delay; @@ -68,7 +68,7 @@ public class SetBorder implements ICommand { addToSection("worldBorder",temp); sender.sendMessage(messagePrefix + "Set border center to current location, size to "+num+", and delay to "+delay); saveConfig(); - Functions.resetWorldborder(spawnWorld); + Worldborder.resetWorldborder(spawnWorld); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 3f872a1..2808948 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.HashMap; import java.util.Map; @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; public class SetExitLocation implements ICommand { @@ -19,7 +19,7 @@ public class SetExitLocation implements ICommand { newExitPosition.setX(player.getLocation().getBlockX()); newExitPosition.setY(player.getLocation().getBlockY()); newExitPosition.setZ(player.getLocation().getBlockZ()); - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 7cb13fc..75de0e5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.HashMap; import java.util.Map; @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; public class SetLobbyLocation implements ICommand { @@ -19,7 +19,7 @@ public class SetLobbyLocation implements ICommand { newLobbyPosition.setX(player.getLocation().getBlockX()); newLobbyPosition.setY(player.getLocation().getBlockY()); newLobbyPosition.setZ(player.getLocation().getBlockZ()); - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index 0114e21..a940ac3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.HashMap; import java.util.Map; @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; public class SetSpawnLocation implements ICommand { @@ -19,7 +19,7 @@ public class SetSpawnLocation implements ICommand { newSpawnPosition.setX(player.getLocation().getBlockX()); newSpawnPosition.setY(player.getLocation().getBlockY()); newSpawnPosition.setZ(player.getLocation().getBlockZ()); - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is currently in session"); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index f071bee..1580f3f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -4,9 +4,8 @@ import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.ICommand; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.io.File; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index cd0c956..7d5242f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -3,73 +3,75 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.command.CommandSender; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.events.Taunt; import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import java.util.ArrayList; +import java.util.List; import java.util.Random; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Functions.setup()) { + if(!Util.isSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if(!status.equals("Standby")) { + if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is already in session"); return; } - if(!playerList.containsKey(sender.getName())) { + if(!Main.plugin.board.isPlayer(sender)) { sender.sendMessage(errorPrefix + "You are not in the lobby"); return; } - if(playerList.size() < minPlayers) { + if(Main.plugin.board.size() < minPlayers) { sender.sendMessage(errorPrefix + "You must have at least "+minPlayers+" players to start"); return; } if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Functions.rollback("hideandseek_"+spawnWorld); + Util.rollback("hideandseek_"+spawnWorld); } else { - Functions.loadMap("hideandseek_"+spawnWorld); + Util.loadMap("hideandseek_"+spawnWorld); } String seekerName; if(args.length < 1) { - seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName(); + seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); } else { seekerName = args[0]; } - Player seeker = playerList.get(seekerName); + Player seeker = Main.plugin.board.getPlayer(seekerName); if(seeker == null) { sender.sendMessage(errorPrefix + "Invalid player: " + seekerName); return; } - Hider = new ArrayList(); - Seeker = new ArrayList(); - Spectator = new ArrayList(); - Deaths = new ArrayList(); - for(Player temp : playerList.values()) { + Main.plugin.board.init(); + for(Player temp : Main.plugin.board.getPlayers()) { if(temp.getName().equals(seeker.getName())) continue; - Hider.add(temp.getName()); - HiderTeam.addEntry(temp.getName()); + Main.plugin.board.addHider(temp); } - Seeker.add(seeker.getName()); - SeekerTeam.addEntry(seeker.getName()); + Main.plugin.board.addSeeker(seeker); currentWorldborderSize = worldborderSize; - for(Player player : playerList.values()) { + for(Player player : Main.plugin.board.getPlayers()) { player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); @@ -77,94 +79,51 @@ public class Start implements ICommand { player.removePotionEffect(effect.getType()); } } - for(String playerName : Seeker) { - Player player = playerList.get(playerName); - if(player != null) { - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); - player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + "Eliminate all hiders", 10, 70, 20); - } + for(Player player : Main.plugin.board.getSeekers()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + "Eliminate all hiders", 10, 70, 20); } - for(String playerName : Hider) { - Player player = playerList.get(playerName); - if(player != null) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); - player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + "Hide away from the seekers", 10, 70, 20); - } + for(Player player : Main.plugin.board.getHiders()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); + player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + "Hide away from the seekers", 10, 70, 20); } - Functions.resetWorldborder("hideandseek_"+spawnWorld); - status = "Starting"; - int temp = gameId; - Functions.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); - + Worldborder.resetWorldborder("hideandseek_"+spawnWorld); + Main.plugin.status = "Starting"; + int temp = Main.plugin.gameId; + Util.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); + Util.sendDelayedMessage(messagePrefix + "Hiders have 20 seconds to hide!", Main.plugin.gameId, 20 * 10); + Util.sendDelayedMessage(messagePrefix + "Hiders have 10 seconds to hide!", Main.plugin.gameId, 20 * 20); + Util.sendDelayedMessage(messagePrefix + "Hiders have 5 seconds to hide!", Main.plugin.gameId, 20 * 25); + Util.sendDelayedMessage(messagePrefix + "Hiders have 3 seconds to hide!", Main.plugin.gameId, 20 * 27); + Util.sendDelayedMessage(messagePrefix + "Hiders have 2 seconds to hide!", Main.plugin.gameId, 20 * 28); + Util.sendDelayedMessage(messagePrefix + "Hiders have 1 seconds to hide!", Main.plugin.gameId, 20 * 29); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); - } - }, 20 * 10); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); - } - }, 20 * 20); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); - } - }, 20 * 25); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); - } - }, 20 * 27); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); - } - }, 20 * 28); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); - } - }, 20 * 29); - - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != gameId) return; - Functions.broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); - status = "Playing"; - for(Player player : playerList.values()) { - Functions.resetPlayer(player); + if(temp != Main.plugin.gameId) return; + Util.broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); + Main.plugin.status = "Playing"; + for(Player player : Main.plugin.board.getPlayers()) { + resetPlayer(player); } - Main.worldborder = null; - Main.taunt = null; - Main.glow = null; + Main.plugin.worldborder = null; + Main.plugin.taunt = null; + Main.plugin.glow = null; if(worldborderEnabled) { - Main.worldborder = new Worldborder(gameId); - Main.worldborder.schedule(); + Main.plugin.worldborder = new Worldborder(Main.plugin.gameId); + Main.plugin.worldborder.schedule(); } - Main.taunt = new Taunt(gameId); - Main.taunt.schedule(); + Main.plugin.taunt = new Taunt(Main.plugin.gameId); + Main.plugin.taunt.schedule(); - Main.glow = new Glow(gameId); + Main.plugin.glow = new Glow(Main.plugin.gameId); if(gameLength > 0) { - timeLeft = gameLength; - for(Player player : playerList.values()) { - player.setLevel(timeLeft); + Main.plugin.timeLeft = gameLength; + for(Player player : Main.plugin.board.getPlayers()) { + player.setLevel(gameLength); } } } @@ -172,6 +131,69 @@ public class Start implements ICommand { } + public static void resetPlayer(Player player) { + player.getInventory().clear(); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false)); + if(Main.plugin.board.isSeeker(player)){ + ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1); + diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); + ItemMeta diamondSwordMeta = diamondSword.getItemMeta(); + diamondSwordMeta.setDisplayName("Seeker Sword"); + diamondSwordMeta.setUnbreakable(true); + diamondSword.setItemMeta(diamondSwordMeta); + player.getInventory().addItem(diamondSword); + + ItemStack wackyStick = new ItemStack(Material.STICK,1); + wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3); + ItemMeta wackyStickMeta = wackyStick.getItemMeta(); + wackyStickMeta.setDisplayName("Wacky Stick"); + wackyStick.setItemMeta(wackyStickMeta); + player.getInventory().addItem(wackyStick); + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); + } + else if(Main.plugin.board.isHider(player)){ + ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1); + stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2); + ItemMeta stoneSwordMeta = stoneSword.getItemMeta(); + stoneSwordMeta.setDisplayName("Hider Sword"); + stoneSwordMeta.setUnbreakable(true); + stoneSword.setItemMeta(stoneSwordMeta); + player.getInventory().addItem(stoneSword); + + ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1); + PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta(); + splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN)); + splashPotion.setItemMeta(splashPotionMeta); + player.getInventory().addItem(splashPotion); + + ItemStack potion = new ItemStack(Material.POTION,2); + PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); + potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL)); + potion.setItemMeta(potionMeta); + player.getInventory().addItem(potion); + + ItemStack snowball = new ItemStack(Material.SNOWBALL,1); + ItemMeta snowballMeta = snowball.getItemMeta(); + snowballMeta.setDisplayName("Glow Powerup"); + List snowballLore = new ArrayList(); + snowballLore.add("Throw to make all seekers glow"); + snowballLore.add("Last 30s, all hiders can see it"); + snowballLore.add("Time stacks on multi use"); + snowballMeta.setLore(snowballLore); + snowball.setItemMeta(snowballMeta); + player.getInventory().addItem(snowball); + + player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false)); + } + } + public String getLabel() { return "start"; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 9c1e3d7..cacf7cd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -10,20 +10,21 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import net.tylermurphy.hideAndSeek.util.Functions; -import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.events.Worldborder; import net.tylermurphy.hideAndSeek.util.Packet; +import net.tylermurphy.hideAndSeek.util.Util; public class Stop implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Functions.setup()) { + if(!Util.isSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if(status.equals("Starting") || status.equals("Playing")) { + if(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped."); - else Functions.broadcastMessage(abortPrefix + "Game has been force stopped."); + else Util.broadcastMessage(abortPrefix + "Game has been force stopped."); onStop(); } else { @@ -37,26 +38,25 @@ public class Stop implements ICommand { } public static void onStop() { - if(status.equals("Standby")) return; - status = "Standby"; - gameId++; - Functions.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : playerList.values()) { + if(Main.plugin.status.equals("Standby")) return; + Main.plugin.status = "Standby"; + Main.plugin.gameId++; + Worldborder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Main.plugin.board.getPlayers()) { player.setGameMode(GameMode.ADVENTURE); player.setLevel(0); - Hider.add(player.getName()); - HiderTeam.addEntry(player.getName()); + Main.plugin.board.addHider(player); player.getInventory().clear(); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); } player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); - for(Player temp : playerList.values()) { + for(Player temp : Main.plugin.board.getPlayers()) { Packet.setGlow(player, temp, false); } } - Functions.unloadMap("hideandseek_"+spawnWorld); + Util.unloadMap("hideandseek_"+spawnWorld); } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java index ec94803..dec3b0f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java @@ -1,7 +1,5 @@ package net.tylermurphy.hideAndSeek.events; -import static net.tylermurphy.hideAndSeek.Store.*; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -27,12 +25,8 @@ public class Glow { private void startGlow() { running = true; - for(String hiderName : Hider) { - Player hider = playerList.get(hiderName); - if(hider == null) continue; - for(String seekerName : Seeker) { - Player seeker = playerList.get(seekerName); - if(seeker == null) continue; + for(Player hider : Main.plugin.board.getHiders()) { + for(Player seeker : Main.plugin.board.getSeekers()) { Packet.setGlow(hider, seeker, true); } } @@ -42,7 +36,7 @@ public class Glow { private void waitGlow() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { public void run() { - if(temp != gameId) return; + if(temp != Main.plugin.gameId) return; glowTime--; glowTime = Math.max(glowTime, 0); if(glowTime == 0) { @@ -55,12 +49,8 @@ public class Glow { } private void stopGlow() { - for(String hiderName : Hider) { - Player hider = playerList.get(hiderName); - if(hider == null) continue; - for(String seekerName : Seeker) { - Player seeker = playerList.get(seekerName); - if(seeker == null) continue; + for(Player hider : Main.plugin.board.getHiders()) { + for(Player seeker : Main.plugin.board.getSeekers()) { Packet.setGlow(hider, seeker, false); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index 0890832..4ce7dc4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.events; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -12,7 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.meta.FireworkMeta; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.Util; public class Taunt { @@ -40,7 +40,7 @@ public class Taunt { } private void tryTaunt() { - if(temp != gameId) return; + if(temp != Main.plugin.gameId) return; if(Math.random() > .8) { executeTaunt(); } else { @@ -54,9 +54,9 @@ public class Taunt { private void executeTaunt() { Player taunted = null; - int rand = (int) (Math.random()*Hider.size()); - for(Player player : playerList.values()) { - if(Hider.contains(player.getName())) { + int rand = (int) (Math.random()*Main.plugin.board.sizeHider()); + for(Player player : Main.plugin.board.getPlayers()) { + if(Main.plugin.board.isHider(player)) { rand--; if(rand==0) { taunted = player; @@ -66,12 +66,12 @@ public class Taunt { } if(taunted != null) { taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted."); - Functions.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s"); + Util.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s"); tauntPlayer = taunted.getName(); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { public void run() { - if(temp != gameId) return; - Player taunted = playerList.get(tauntPlayer); + if(temp != Main.plugin.gameId) return; + Player taunted = Main.plugin.board.getPlayer(tauntPlayer); if(taunted != null) { Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); @@ -87,7 +87,7 @@ public class Taunt { .withTrail() .build()); fw.setFireworkMeta(fwm); - Functions.broadcastMessage(tauntPrefix + " Taunt has been activated"); + Util.broadcastMessage(tauntPrefix + " Taunt has been activated"); } tauntPlayer = ""; waitTaunt(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java index 04bddfb..70c4986 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java @@ -5,9 +5,9 @@ import org.bukkit.World; import org.bukkit.WorldBorder; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.Store.*; +import static net.tylermurphy.hideAndSeek.Config.*; public class Worldborder { @@ -26,9 +26,9 @@ public class Worldborder { } private void decreaceWorldborder() { - if(temp != gameId) return; + if(temp != Main.plugin.gameId) return; if(currentWorldborderSize-100 > 100) { - Functions.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s"); + Util.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s"); currentWorldborderSize -= 100; World world = Bukkit.getWorld("hideandseek_"+spawnWorld); WorldBorder border = world.getWorldBorder(); @@ -41,4 +41,19 @@ public class Worldborder { } } + public static void resetWorldborder(String worldName) { + if(worldborderEnabled) { + World world = Bukkit.getWorld(worldName); + WorldBorder border = world.getWorldBorder(); + border.setSize(worldborderSize); + border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); + currentWorldborderSize = worldborderSize; + } else { + World world = Bukkit.getWorld(worldName); + WorldBorder border = world.getWorldBorder(); + border.setSize(30000000); + border.setCenter(0, 0); + } + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java new file mode 100644 index 0000000..f1fceba --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -0,0 +1,178 @@ +package net.tylermurphy.hideAndSeek.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.ScoreboardManager; +import org.bukkit.scoreboard.Team; +import org.bukkit.scoreboard.Team.Option; +import org.bukkit.scoreboard.Team.OptionStatus; + +import static net.tylermurphy.hideAndSeek.Config.*; + +public class Board { + + private Team HiderTeam, SeekerTeam, SpectatorTeam; + private List Hider, Seeker, Spectator; + private Map playerList = new HashMap(); + + private boolean setup = false; + + public boolean isReady() { + return setup; + } + + public boolean isPlayer(Player player) { + return playerList.containsKey(player.getName()); + } + + public boolean isPlayer(CommandSender sender) { + return playerList.containsKey(sender.getName()); + } + + public boolean isHider(Player player) { + return Hider.contains(player.getName()); + } + + public boolean isSeeker(Player player) { + return Seeker.contains(player.getName()); + } + + public boolean isSpectator(Player player) { + return Spectator.contains(player.getName()); + } + + public int sizeHider() { + return Hider.size(); + } + + public int sizeSeeker() { + return Seeker.size(); + } + + public int sizeSpectator() { + return Spectator.size(); + } + + public int size() { + return playerList.size(); + } + + public List getHiders(){ + return Hider.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); + } + + public List getSeekers(){ + return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); + } + + public List getSpectators(){ + return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); + } + + public List getPlayers(){ + return new ArrayList(playerList.values()); + } + + public Player getPlayer(String name) { + return playerList.get(name); + } + + public void addHider(Player player) { + Hider.add(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + HiderTeam.addEntry(player.getName()); + if(!playerList.containsKey(player.getName())) + playerList.put(player.getName(), player); + } + + public void addSeeker(Player player) { + Hider.remove(player.getName()); + Seeker.add(player.getName()); + Spectator.remove(player.getName()); + SeekerTeam.addEntry(player.getName()); + if(!playerList.containsKey(player.getName())) + playerList.put(player.getName(), player); + } + + public void addSpectator(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.add(player.getName()); + SpectatorTeam.addEntry(player.getName()); + if(!playerList.containsKey(player.getName())) + playerList.put(player.getName(), player); + } + + public void remove(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + HiderTeam.removeEntry(player.getName()); + SeekerTeam.removeEntry(player.getName()); + SpectatorTeam.removeEntry(player.getName()); + playerList.remove(player.getName()); + } + + public boolean onSameTeam(Player player1, Player player2) { + if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; + else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; + else if(Spectator.contains(player1.getName()) && Spectator.contains(player2.getName())) return true; + else return false; + } + + public void init() { + Hider = new ArrayList(); + Seeker = new ArrayList(); + Spectator = new ArrayList(); + reload(); + } + + public void reload() { + + ScoreboardManager manager = Bukkit.getScoreboardManager(); + if(manager == null) return; + Scoreboard board = manager.getMainScoreboard(); + + try { board.registerNewTeam("Seeker"); } catch(Exception e) {} + SeekerTeam = board.getTeam("Seeker"); + SeekerTeam.setColor(ChatColor.RED); + if(nametagsVisible) SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS); + else SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + + try { board.registerNewTeam("Hider"); } catch(Exception e) {} + HiderTeam = board.getTeam("Hider"); + HiderTeam.setColor(ChatColor.GOLD); + if(nametagsVisible) HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM); + else HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + + try { board.registerNewTeam("Spectator"); } catch(Exception e) {} + SpectatorTeam = board.getTeam("Spectator"); + SpectatorTeam.setColor(ChatColor.GRAY); + SpectatorTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + + setup = true; + } + + public void reset() { + Hider.clear(); + Seeker.clear(); + Spectator.clear(); + for(String entry : HiderTeam.getEntries()) + HiderTeam.removeEntry(entry); + for(String entry : SeekerTeam.getEntries()) + SeekerTeam.removeEntry(entry); + for(String entry : SpectatorTeam.getEntries()) + SpectatorTeam.removeEntry(entry); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java deleted file mode 100644 index cff39a3..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ /dev/null @@ -1,184 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import static net.tylermurphy.hideAndSeek.Store.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldBorder; -import org.bukkit.WorldCreator; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.ScoreboardManager; -import org.bukkit.scoreboard.Team.Option; -import org.bukkit.scoreboard.Team.OptionStatus; - -import net.tylermurphy.hideAndSeek.Main; - -public class Functions { - - public static void resetPlayer(Player player) { - player.getInventory().clear(); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false)); - if(Seeker.contains(player.getName())){ - ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1); - diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); - ItemMeta diamondSwordMeta = diamondSword.getItemMeta(); - diamondSwordMeta.setDisplayName("Seeker Sword"); - diamondSwordMeta.setUnbreakable(true); - diamondSword.setItemMeta(diamondSwordMeta); - player.getInventory().addItem(diamondSword); - - ItemStack wackyStick = new ItemStack(Material.STICK,1); - wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3); - ItemMeta wackyStickMeta = wackyStick.getItemMeta(); - wackyStickMeta.setDisplayName("Wacky Stick"); - wackyStick.setItemMeta(wackyStickMeta); - player.getInventory().addItem(wackyStick); - - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); - } - else if(Hider.contains(player.getName())){ - ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1); - stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2); - ItemMeta stoneSwordMeta = stoneSword.getItemMeta(); - stoneSwordMeta.setDisplayName("Hider Sword"); - stoneSwordMeta.setUnbreakable(true); - stoneSword.setItemMeta(stoneSwordMeta); - player.getInventory().addItem(stoneSword); - - ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1); - PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta(); - splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN)); - splashPotion.setItemMeta(splashPotionMeta); - player.getInventory().addItem(splashPotion); - - ItemStack potion = new ItemStack(Material.POTION,2); - PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); - potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL)); - potion.setItemMeta(potionMeta); - player.getInventory().addItem(potion); - - ItemStack snowball = new ItemStack(Material.SNOWBALL,1); - ItemMeta snowballMeta = snowball.getItemMeta(); - snowballMeta.setDisplayName("Glow Powerup"); - List snowballLore = new ArrayList(); - snowballLore.add("Throw to make all seekers glow"); - snowballLore.add("Last 30s, all hiders can see it"); - snowballLore.add("Time stacks on multi use"); - snowballMeta.setLore(snowballLore); - snowball.setItemMeta(snowballMeta); - player.getInventory().addItem(snowball); - - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false)); - } - } - - public static void resetWorldborder(String worldName) { - if(worldborderEnabled) { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(worldborderSize); - border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); - currentWorldborderSize = worldborderSize; - } else { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(30000000); - border.setCenter(0, 0); - } - } - - public static void unloadMap(String mapname){ - if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){ - Main.plugin.getLogger().info("Successfully unloaded " + mapname); - }else{ - Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname); - } - } - - public static void loadMap(String mapname){ - Bukkit.getServer().createWorld(new WorldCreator(mapname)); - Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false); - } - - public static void rollback(String mapname){ - unloadMap(mapname); - loadMap(mapname); - } - - public static void loadScoreboard() { - - ScoreboardManager manager = Bukkit.getScoreboardManager(); - Scoreboard mainBoard = manager.getMainScoreboard(); - - try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {} - SeekerTeam = mainBoard.getTeam("Seeker"); - SeekerTeam.setColor(ChatColor.RED); - if(nametagsVisible) - SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS); - else - SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - - try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {} - HiderTeam = mainBoard.getTeam("Hider"); - HiderTeam.setColor(ChatColor.GOLD); - if(nametagsVisible) - HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM); - else - HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - - try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {} - SpectatorTeam = mainBoard.getTeam("Spectator"); - SpectatorTeam.setColor(ChatColor.GRAY); - SpectatorTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - - board = mainBoard; - } - - public static void broadcastMessage(String message) { - for(Player player : playerList.values()) { - player.sendMessage(message); - } - } - - public static boolean setup() { - - if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { - return false; - } - if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { - return false; - } - if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { - return false; - } - File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); - if(!destenation.exists()) { - return false; - } - - return true; - - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java new file mode 100644 index 0000000..7c7e230 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -0,0 +1,57 @@ +package net.tylermurphy.hideAndSeek.util; + +import static net.tylermurphy.hideAndSeek.Config.*; + +import java.io.File; + +import org.bukkit.Bukkit; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.Main; + +public class Util { + + public static void broadcastMessage(String message) { + for(Player player : Main.plugin.board.getPlayers()) { + player.sendMessage(message); + } + } + + public static boolean isSetup() { + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return false; + if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return false; + if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return false; + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + if(!destenation.exists()) return false; + return true; + } + + public static void unloadMap(String mapname){ + if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){ + Main.plugin.getLogger().info("Successfully unloaded " + mapname); + }else{ + Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname); + } + } + + public static void loadMap(String mapname){ + Bukkit.getServer().createWorld(new WorldCreator(mapname)); + Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false); + } + + public static void rollback(String mapname){ + unloadMap(mapname); + loadMap(mapname); + } + + public static void sendDelayedMessage(String message, int gameId, int delay) { + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() { + public void run() { + if(gameId == Main.plugin.gameId) + Util.broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); + } + }, delay); + } + +} \ No newline at end of file