From 38fd4f57406c428b5feb343edfb41945774b4cf4 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 12 Apr 2022 15:11:49 -0400 Subject: added custom leaderboard, bug fixes --- .../net/tylermurphy/hideAndSeek/game/Board.java | 118 ++++++++++++--------- .../hideAndSeek/game/EventListener.java | 8 ++ .../net/tylermurphy/hideAndSeek/game/Game.java | 34 ++---- 3 files changed, 87 insertions(+), 73 deletions(-) (limited to 'src/main/java/net/tylermurphy/hideAndSeek/game') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 71060b9..fd75040 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -21,10 +21,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import net.tylermurphy.hideAndSeek.util.Status; @@ -151,19 +148,28 @@ public class Board { 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(); - if(lobbyCountdownEnabled){ - if(Game.countdownTime == -1){ - board.setLine("waiting", "Waiting for players..."); + int i=0; + for(String line : LOBBY_CONTENTS){ + if(line.equalsIgnoreCase("")){ + board.addBlank(); + } else if(line.contains("{COUNTDOWN}")){ + if(!lobbyCountdownEnabled){ + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_ADMINSTART)); + } else if(Game.countdownTime == -1){ + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_WAITING)); + } else { + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_COUNTING.replace("{AMOUNT}",Game.countdownTime+""))); + } + } else if(line.contains("{COUNT}")){ + board.setLine(String.valueOf(i), line.replace("{COUNT}", getPlayers().size()+"")); + } else if(line.contains("{SEEKER%}")){ + board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+"")); + } else if(line.contains("{HIDER%}")){ + board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+"")); } else { - board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s"); + board.setLine(String.valueOf(i), line); } - } else { - board.setLine("waiting", "Waiting for gamemaster..."); + i++; } board.display(); customBoards.put(player.getName(), board); @@ -176,42 +182,58 @@ public class Board { private static void createGameBoard(Player player, boolean recreate){ CustomBoard board = customBoards.get(player.getName()); if(recreate) { - board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board = new CustomBoard(player, GAME_TITLE); board.updateTeams(); } - 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(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) - board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); - else - board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); - } - if(tauntEnabled && tauntCountdown){ - if(Game.taunt == null || Game.status == Status.STARTING) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); - else if(!tauntLast && Hider.size() == 1){ - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); - } else if(!Game.taunt.isRunning()) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s"); - else - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); - } - if(worldborderEnabled){ - if(Game.worldBorder == null || Game.status == Status.STARTING){ - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); - } else if(!Game.worldBorder.isRunning()) { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + Game.worldBorder.getDelay()%60 + "s"); + + int i = 0; + for(String line : GAME_CONTENTS){ + if(line.equalsIgnoreCase("")){ + board.addBlank(); } else { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + if(line.contains("{TIME}")) { + String value = Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"; + board.setLine(String.valueOf(i), line.replace("{TIME}", value)); + } else if(line.contains("{TEAM}")) { + String value = getTeam(player); + board.setLine(String.valueOf(i), line.replace("{TEAM}", value)); + } else if(line.contains("{BORDER}")) { + if(!worldborderEnabled) continue; + if(Game.worldBorder == null || Game.status == Status.STARTING){ + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0"))); + } else if(!Game.worldBorder.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()%60+""))); + } else { + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_DECREASING)); + } + } else if(line.contains("{TAUNT}")){ + if(!tauntEnabled) continue; + if(Game.taunt == null || Game.status == Status.STARTING) { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0"))); + } else if(!tauntLast && Hider.size() == 1){ + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED)); + } else if(!Game.taunt.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() % 60 + ""))); + } else { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_ACTIVE)); + } + } else if(line.contains("{GLOW}")){ + if(!glowEnabled) return; + if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_INACTIVE)); + } else { + board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_ACTIVE)); + } + } else if(line.contains("{#SEEKER}")) { + board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+"")); + } else if(line.contains("{#HIDER}")) { + board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+"")); + } else { + board.setLine(String.valueOf(i), line); + } } + i++; } - if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) - board.addBlank(); - board.setLine("time", "Time Left: " + ChatColor.GREEN + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"); - board.addBlank(); - board.setLine("team", "Team: " + getTeam(player)); board.display(); customBoards.put(player.getName(), board); } @@ -332,9 +354,9 @@ class CustomBoard { public void setLine(String key, String message){ Line line = LINES.get(key); if(line == null) - addLine(key, message); + addLine(key, ChatColor.translateAlternateColorCodes('&',message)); else - updateLine(key, message); + updateLine(key, ChatColor.translateAlternateColorCodes('&',message)); } private void addLine(String key, String message){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 9271e5c..698d650 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -271,5 +271,13 @@ public class EventListener implements Listener { } } } + for(String handle : blockedCommands){ + System.out.println(handle); + if(array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && Game.status != Status.STANDBY){ + player.sendMessage(errorPrefix + message("BLOCKED_COMMAND")); + event.setCancelled(true); + break; + } + } } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 3b1a0dd..a016a4e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -96,6 +96,7 @@ public class Game { for(Player player : Board.getSeekers()) { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,1000000,128,false,false)); Titles.sendTitle(player, 10, 70, 20, ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString()); } for(Player player : Board.getHiders()) { @@ -273,8 +274,10 @@ public class Game { countdownTime = countdown; if(Board.size() >= changeCountdown) countdownTime = Math.min(countdownTime, 10); - if(tick % 20 == 0) + if(tick % 20 == 0) { countdownTime--; + Board.reloadLobbyBoards(); + } if(countdownTime == 0){ Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); if(!rand.isPresent()){ @@ -308,22 +311,6 @@ public class Game { distance = temp; } } -// if(seekerPing) switch(tick%10) { -// case 0: -// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .5f, 1f); -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 3: -// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .3f, 1f); -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 6: -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 9: -// if(distance < seekerPingLevel2) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// } if(seekerPing) switch(tick%10) { case 0: if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f); @@ -390,21 +377,18 @@ class Glow { public void onProjectile() { if(glowStackable) glowTime += glowLength; else glowTime = glowLength; - if(!running) - startGlow(); + running = true; } - private void startGlow() { - running = true; - for(Player hider : Board.getHiders()) { - for(Player seeker : Board.getSeekers()) { + private void sendPackets(){ + for(Player hider : Board.getHiders()) + for(Player seeker : Board.getSeekers()) Packet.setGlow(hider, seeker, true); - } - } } protected void update() { if(running) { + sendPackets(); glowTime--; glowTime = Math.max(glowTime, 0); if (glowTime == 0) { -- cgit v1.2.3-freya