From d4f22de7b05dc0170fac130a13ca5b7ad6683bfb Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 11 May 2022 09:49:36 -0400 Subject: [PATCH] bug fixes + spectator flight + no false scoreboards values --- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../hideAndSeek/database/PlayerInfoTable.java | 10 ++-- .../tylermurphy/hideAndSeek/game/Board.java | 56 +++++++++++++------ .../hideAndSeek/game/EventListener.java | 11 ++-- .../tylermurphy/hideAndSeek/game/Game.java | 36 +++++++----- .../hideAndSeek/util/PAPIExpansion.java | 1 - 6 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 0b53ed6..f87457f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -38,7 +38,7 @@ public class Stop implements ICommand { } if(Game.status == Status.STARTING || Game.status == Status.PLAYING) { Game.broadcastMessage(abortPrefix + message("STOP")); - Game.stop(WinType.NONE); + Game.stop(); } else { sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index 35912fe..aab42b8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -203,7 +203,7 @@ public class PlayerInfoTable { return null; } - public void addWins(List uuids, List winners, Map kills, Map deaths, WinType type){ + public void addWins(List uuids, List winners, Map hider_kills, Map hider_deaths, Map seeker_kills, Map seeker_deaths, WinType type){ for(UUID uuid : uuids){ String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)"; PlayerInfo info = getInfo(uuid); @@ -213,10 +213,10 @@ public class PlayerInfoTable { statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0)); statement.setInt(4, info.hider_games + (Board.isHider(uuid) ? 1 : 0)); statement.setInt(5, info.seeker_games + (Board.isSeeker(uuid) ? 1 : 0)); - statement.setInt(6, info.hider_kills + (Board.isHider(uuid) ? kills.getOrDefault(uuid.toString(), 0) : 0)); - statement.setInt(7, info.seeker_kills + (Board.isSeeker(uuid) ? kills.getOrDefault(uuid.toString(), 0) : 0)); - statement.setInt(8, info.hider_deaths + (Board.isHider(uuid) ? deaths.getOrDefault(uuid.toString(), 0) : 0)); - statement.setInt(9, info.seeker_deaths + (Board.isSeeker(uuid) ? deaths.getOrDefault(uuid.toString(), 0) : 0)); + statement.setInt(6, info.hider_kills + (Board.isHider(uuid) ? hider_kills.getOrDefault(uuid.toString(), 0) : 0)); + statement.setInt(7, info.seeker_kills + (Board.isSeeker(uuid) ? seeker_kills.getOrDefault(uuid.toString(), 0) : 0)); + statement.setInt(8, info.hider_deaths + (Board.isHider(uuid) ? hider_deaths.getOrDefault(uuid.toString(), 0) : 0)); + statement.setInt(9, info.seeker_deaths + (Board.isSeeker(uuid) ? seeker_deaths.getOrDefault(uuid.toString(), 0) : 0)); statement.execute(); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 86711ab..61e77e7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -38,8 +38,7 @@ public class Board { private static final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); private static final Map playerList = new HashMap<>(); private static final Map customBoards = new HashMap<>(); - private static final Map kills = new HashMap<>(); - private static final Map deaths = new HashMap<>(); + private static final Map hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>(); public static boolean isPlayer(Player player) { return playerList.containsKey(player.getUniqueId().toString()); @@ -143,32 +142,55 @@ public class Board { Hider.clear(); Seeker.clear(); Spectator.clear(); - kills.clear(); - deaths.clear(); + hider_kills.clear(); + seeker_kills.clear(); + hider_deaths.clear(); + seeker_deaths.clear(); } public static void addKill(UUID uuid){ - if(kills.containsKey(uuid.toString())){ - kills.put(uuid.toString(), kills.get(uuid.toString())+1); - } else { - kills.put(uuid.toString(), 1); + if(Hider.contains(uuid.toString())){ + if(hider_kills.containsKey(uuid.toString())){ + hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1); + } else { + hider_kills.put(uuid.toString(), 1); + } + } else if(getFirstSeeker().getUniqueId().equals(uuid)){ + if(seeker_kills.containsKey(uuid.toString())){ + seeker_kills.put(uuid.toString(), seeker_kills.get(uuid.toString())+1); + } else { + seeker_kills.put(uuid.toString(), 1); + } } } public static void addDeath(UUID uuid){ - if(deaths.containsKey(uuid.toString())){ - deaths.put(uuid.toString(), deaths.get(uuid.toString())+1); - } else { - deaths.put(uuid.toString(), 1); + if(Hider.contains(uuid.toString())){ + if(hider_deaths.containsKey(uuid.toString())){ + hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1); + } else { + hider_deaths.put(uuid.toString(), 1); + } + } else if(getFirstSeeker().getUniqueId().equals(uuid)){ + if(seeker_deaths.containsKey(uuid.toString())){ + seeker_deaths.put(uuid.toString(), seeker_deaths.get(uuid.toString())+1); + } else { + seeker_deaths.put(uuid.toString(), 1); + } } } - public static Map getKills(){ - return new HashMap<>(kills); + public static Map getHiderKills(){ + return new HashMap<>(hider_kills); } - - public static Map getDeaths(){ - return new HashMap<>(deaths); + public static Map getSeekerKills(){ + return new HashMap<>(seeker_kills); + } + public static Map getHiderDeaths(){ + return new HashMap<>(hider_deaths); + } + public static Map getSeekerDeaths(){ + return new HashMap<>(seeker_deaths); } public static void createLobbyBoard(Player player) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index f8f754f..1c02685 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -215,20 +215,23 @@ public class EventListener implements Listener { // Broadcast player death message if (Board.isSeeker(player)) { Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString()); + if(Board.getFirstSeeker().getName().equals(player.getName())){ + Board.addDeath(player.getUniqueId()); + } } else if (Board.isHider(player)) { if (attacker == null) { Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString()); } else { Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString()); } + Board.addDeath(player.getUniqueId()); Board.addSeeker(player); } - // Add leaderboard stats - Board.addDeath(player.getUniqueId()); - if(attacker != null){ Board.addKill(attacker.getUniqueId()); } + // Add leaderboard kills if attacker + if(attacker != null && ( Board.isHider(player) || Board.getFirstSeeker().getName().equals(player.getName()) ) ) + Board.addKill(attacker.getUniqueId()); Game.resetPlayer(player); Board.reloadBoardTeams(); - } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 76ad068..69153f2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -155,35 +155,35 @@ public class Game { status = Status.ENDING; for(Player player : Board.getPlayers()) { player.getInventory().clear(); - player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); } + player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); if(Version.atLeast("1.9")){ for(Player temp : Board.getPlayers()) { Packet.setGlow(player, temp, false); } } } - Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> stop(type), 5*20); + List players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + if(type == WinType.HIDER_WIN){ + List winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type); + } else if(type == WinType.SEEKER_WIN){ + List winners = new ArrayList<>(); + winners.add(Board.getFirstSeeker().getUniqueId()); + Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type); + } + Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, Game::stop, 5*20); } - public static void stop(WinType type){ + public static void stop(){ if(status == Status.STANDBY) return; tick = 0; countdownTime = -1; status = Status.STANDBY; gameId++; timeLeft = 0; - List players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); - if(type == WinType.HIDER_WIN){ - List winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); - Database.playerInfo.addWins(players, winners, Board.getKills(), Board.getDeaths(), type); - } else if(type == WinType.SEEKER_WIN){ - List winners = new ArrayList<>(); - winners.add(Board.getFirstSeeker().getUniqueId()); - Database.playerInfo.addWins(players, winners, Board.getKills(), Board.getDeaths(), type); - } worldBorder.resetWorldborder(getGameWorld()); for(Player player : Board.getPlayers()) { for(Player player2 : Board.getPlayers()){ @@ -196,6 +196,10 @@ public class Game { Packet.setGlow(player, temp, false); } } + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); if(leaveOnEnd){ Board.removeBoard(player); Board.remove(player); @@ -288,7 +292,7 @@ public class Game { } public static void join(Player player){ - if(Game.status == Status.STANDBY) { + if(Game.status == Status.STANDBY || Game.status == Status.ENDING) { player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.getInventory().clear(); if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start"))) @@ -308,10 +312,11 @@ public class Game { for(Player player2 : Board.getPlayers()){ player2.hidePlayer(player); } - player.setFlying(true); - player.setAllowFlight(true); Board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.setFlying(true); + player.setAllowFlight(true); + player.setFallDistance(0.0F); Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString()); } @@ -327,6 +332,7 @@ public class Game { public static void leave(Player player){ player.setFlying(false); player.setAllowFlight(false); + player.setFallDistance(0.0F); for(Player player2 : Board.getPlayers()){ player2.showPlayer(player); player.showPlayer(player2); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java b/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java index e7bca4a..d1ce898 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java @@ -35,7 +35,6 @@ public class PAPIExpansion extends PlaceholderExpansion { @Override public String onRequest(OfflinePlayer player, @NotNull String params) { String[] args = params.split("_"); - System.out.println(); if(args.length < 1) return null; if(args[0].equals("stats") && args.length == 2){ PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());