bug fixes + spectator flight + no false scoreboards values

This commit is contained in:
Tyler Murphy 2022-05-11 09:49:36 -04:00
parent 8480324ab7
commit d4f22de7b0
6 changed files with 73 additions and 43 deletions

View file

@ -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"));
}

View file

@ -203,7 +203,7 @@ public class PlayerInfoTable {
return null;
}
public void addWins(List<UUID> uuids, List<UUID> winners, Map<String,Integer> kills, Map<String,Integer> deaths, WinType type){
public void addWins(List<UUID> uuids, List<UUID> winners, Map<String,Integer> hider_kills, Map<String,Integer> hider_deaths, Map<String,Integer> seeker_kills, Map<String,Integer> 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());

View file

@ -38,8 +38,7 @@ public class Board {
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
private static final Map<String, Player> playerList = new HashMap<>();
private static final Map<String, CustomBoard> customBoards = new HashMap<>();
private static final Map<String, Integer> kills = new HashMap<>();
private static final Map<String, Integer> deaths = new HashMap<>();
private static final Map<String, Integer> 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);
if(Hider.contains(uuid.toString())){
if(hider_kills.containsKey(uuid.toString())){
hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1);
} else {
kills.put(uuid.toString(), 1);
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);
if(Hider.contains(uuid.toString())){
if(hider_deaths.containsKey(uuid.toString())){
hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1);
} else {
deaths.put(uuid.toString(), 1);
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<String, Integer> getKills(){
return new HashMap<>(kills);
public static Map<String, Integer> getHiderKills(){
return new HashMap<>(hider_kills);
}
public static Map<String, Integer> getDeaths(){
return new HashMap<>(deaths);
public static Map<String, Integer> getSeekerKills(){
return new HashMap<>(seeker_kills);
}
public static Map<String, Integer> getHiderDeaths(){
return new HashMap<>(hider_deaths);
}
public static Map<String, Integer> getSeekerDeaths(){
return new HashMap<>(seeker_deaths);
}
public static void createLobbyBoard(Player player) {

View file

@ -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)

View file

@ -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<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
if(type == WinType.HIDER_WIN){
List<UUID> 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<UUID> 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<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
if(type == WinType.HIDER_WIN){
List<UUID> 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<UUID> 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);

View file

@ -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());