diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/util')
3 files changed, 243 insertions, 66 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 17a60b1..9d856b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -26,7 +26,8 @@ public class Board { private List<String> Hider, Seeker, Spectator; private Map<String, Player> playerList = new HashMap<String,Player>(); - + private Map<String, CustomBoard> customBoards = new HashMap<String, CustomBoard>(); + public boolean isPlayer(Player player) { return playerList.containsKey(player.getName()); } @@ -145,64 +146,91 @@ public class Board { seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); } } - - private void createLobbyBoard(Player player) { - - Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); - Objective obj = board.registerNewObjective("LobbyScoreboard", "dummy", - ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK")); - createTeamsForBoard(board); - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - Score waiting = obj.getScore("Waiting to start..."); - waiting.setScore(6); - Score blank1 = obj.getScore(ChatColor.RESET.toString()); - blank1.setScore(5); - Score players = obj.getScore("Players: "+playerList.values().size()); - players.setScore(4); - Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()); - blank2.setScore(3); - Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); - seeker.setScore(2); - Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDER%" + ChatColor.WHITE + getHiderPercent()); - hider.setScore(1); - player.setScoreboard(board); + + public void createLobbyBoard(Player player) { + createLobbyBoard(player, true); } - - private void createGameBoard(Player player) { - Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); - Objective obj = board.registerNewObjective("GameScoreboard", "dummy", - ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK")); - createTeamsForBoard(board); - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - Score team = obj.getScore("Team: " + getTeam(player)); - team.setScore(6); - Score blank1 = obj.getScore(ChatColor.RESET.toString()); - blank1.setScore(5); - if(gameLength > 0) { - Score waiting = obj.getScore(ChatColor.GREEN + "Time Left: " + ChatColor.WHITE + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); - waiting.setScore(4); - Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()); - blank2.setScore(3); + + private void createLobbyBoard(Player player, boolean recreate) { + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); + } + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); + board.addBlank(); + board.setLine("players", "Players: " + playerList.values().size()); + board.addBlank(); + board.setLine("waiting", "Waiting to start..."); + board.display(); + customBoards.put(player.getName(), board); + } + + public void createGameBoard(Player player){ + createGameBoard(player, true); + } + + private void createGameBoard(Player player, boolean recreate){ + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + } + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); + board.addBlank(); + if(glowEnabled){ + if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning()) + board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); + else + board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); } - Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); - seeker.setScore(2); - Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); - hider.setScore(1); - player.setScoreboard(board); + if(tauntEnabled && tauntCountdown){ + if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting")) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); + else if(!tauntLast && Hider.size() == 1){ + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); + } else if(!Main.plugin.taunt.isRunning()) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s"); + else + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); + } + if(worldborderEnabled){ + if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){ + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); + } else if(!Main.plugin.worldborder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s"); + } else { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + } + } + if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) + board.addBlank(); + board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); + board.addBlank(); + board.setLine("team", "Team: " + getTeam(player)); + board.display(); + customBoards.put(player.getName(), board); } public void removeBoard(Player player) { player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + customBoards.remove(player.getName()); } public void reloadLobbyBoards() { for(Player player : playerList.values()) - createLobbyBoard(player); + createLobbyBoard(player, false); } public void reloadGameBoards() { for(Player player : playerList.values()) - createGameBoard(player); + createGameBoard(player, false); + } + + public void reloadBoardTeams() { + for(CustomBoard board : customBoards.values()) + board.updateTeams(); } private String getSeekerPercent() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java new file mode 100644 index 0000000..69d865a --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java @@ -0,0 +1,121 @@ +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.*; + +import java.util.HashMap; +import java.util.Map; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class CustomBoard { + + private final Scoreboard board; + private final Objective obj; + private final Player player; + private final Map<String,Line> LINES; + private int blanks; + private boolean displayed; + + public CustomBoard(Player player, String title){ + this.board = Bukkit.getScoreboardManager().getNewScoreboard(); + this.LINES = new HashMap<String,Line>(); + this.player = player; + this.obj = board.registerNewObjective( + "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + this.blanks = 0; + this.displayed = false; + this.updateTeams(); + } + + public void updateTeams() { + try{ board.registerNewTeam("Hider"); } catch (Exception e){} + try{ board.registerNewTeam("Seeker"); } catch (Exception e){} + Team hiderTeam = board.getTeam("Hider"); + for(String entry : hiderTeam.getEntries()) + hiderTeam.removeEntry(entry); + for(Player player : Main.plugin.board.getHiders()) + hiderTeam.addEntry(player.getName()); + Team seekerTeam = board.getTeam("Seeker"); + for(String entry : seekerTeam.getEntries()) + seekerTeam.removeEntry(entry); + for(Player player : Main.plugin.board.getSeekers()) + seekerTeam.addEntry(player.getName()); + if(nametagsVisible) { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + } else { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } + hiderTeam.setColor(ChatColor.GOLD); + seekerTeam.setColor(ChatColor.RED); + } + + public void setLine(String key, String message){ + Line line = LINES.get(key); + if(line == null) + addLine(key, message); + else + updateLine(key, message); + } + + private void addLine(String key, String message){ + Score score = obj.getScore(message); + score.setScore(LINES.values().size()+1); + Line line = new Line(LINES.values().size()+1, message); + LINES.put(key, line); + } + + public void addBlank(){ + if(displayed) return; + String temp = ""; + for(int i = 0; i <= blanks; i ++) + temp += ChatColor.RESET; + blanks++; + addLine("blank"+blanks, temp); + } + + private void updateLine(String key, String message){ + Line line = LINES.get(key); + board.resetScores(line.getMessage()); + line.setMessage(message); + Score newScore = obj.getScore(message); + + newScore.setScore(line.getScore()); + } + + public void display() { + displayed = true; + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + player.setScoreboard(board); + } + +} + +class Line { + + private int score; + private String message; + + public Line(int score, String message){ + this.score = score; + this.message = message; + } + + public int getScore() { + return score; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 028b217..c24936b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -2,13 +2,27 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.io.File; +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.configuration.Items; +import net.tylermurphy.hideAndSeek.configuration.LocalizationString; import org.bukkit.Bukkit; -import org.bukkit.WorldCreator; +import org.bukkit.Material; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; +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; public class Util { @@ -24,27 +38,10 @@ public class Util { 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; + if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) 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() { @@ -53,5 +50,36 @@ public class Util { } }, delay); } - + + public static void resetPlayer(Player player) { + player.getInventory().clear(); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + if (Main.plugin.board.isSeeker(player)) { + if(pvpEnabled) + for(ItemStack item : Items.SEEKER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.SEEKER_EFFECTS) + player.addPotionEffect(effect); + } else if (Main.plugin.board.isHider(player)) { + if(pvpEnabled) + for(ItemStack item : Items.HIDER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.HIDER_EFFECTS) + player.addPotionEffect(effect); + if(glowEnabled) { + ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); + ItemMeta snowballMeta = snowball.getItemMeta(); + snowballMeta.setDisplayName("Glow Powerup"); + List<String> snowballLore = new ArrayList<String>(); + 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); + } + } + } }
\ No newline at end of file |