bug fixes + spectator flight + no false scoreboards values
This commit is contained in:
parent
8480324ab7
commit
d4f22de7b0
6 changed files with 73 additions and 43 deletions
|
@ -38,7 +38,7 @@ public class Stop implements ICommand {
|
||||||
}
|
}
|
||||||
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
||||||
Game.broadcastMessage(abortPrefix + message("STOP"));
|
Game.broadcastMessage(abortPrefix + message("STOP"));
|
||||||
Game.stop(WinType.NONE);
|
Game.stop();
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ public class PlayerInfoTable {
|
||||||
return null;
|
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){
|
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 (?,?,?,?,?,?,?,?,?)";
|
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);
|
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(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(4, info.hider_games + (Board.isHider(uuid) ? 1 : 0));
|
||||||
statement.setInt(5, info.seeker_games + (Board.isSeeker(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(6, info.hider_kills + (Board.isHider(uuid) ? hider_kills.getOrDefault(uuid.toString(), 0) : 0));
|
||||||
statement.setInt(7, info.seeker_kills + (Board.isSeeker(uuid) ? 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) ? deaths.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) ? deaths.getOrDefault(uuid.toString(), 0) : 0));
|
statement.setInt(9, info.seeker_deaths + (Board.isSeeker(uuid) ? seeker_deaths.getOrDefault(uuid.toString(), 0) : 0));
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException e){
|
} catch (SQLException e){
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
|
|
|
@ -38,8 +38,7 @@ public class Board {
|
||||||
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
|
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, Player> playerList = new HashMap<>();
|
||||||
private static final Map<String, CustomBoard> customBoards = 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> hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>();
|
||||||
private static final Map<String, Integer> deaths = new HashMap<>();
|
|
||||||
|
|
||||||
public static boolean isPlayer(Player player) {
|
public static boolean isPlayer(Player player) {
|
||||||
return playerList.containsKey(player.getUniqueId().toString());
|
return playerList.containsKey(player.getUniqueId().toString());
|
||||||
|
@ -143,32 +142,55 @@ public class Board {
|
||||||
Hider.clear();
|
Hider.clear();
|
||||||
Seeker.clear();
|
Seeker.clear();
|
||||||
Spectator.clear();
|
Spectator.clear();
|
||||||
kills.clear();
|
hider_kills.clear();
|
||||||
deaths.clear();
|
seeker_kills.clear();
|
||||||
|
hider_deaths.clear();
|
||||||
|
seeker_deaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addKill(UUID uuid){
|
public static void addKill(UUID uuid){
|
||||||
if(kills.containsKey(uuid.toString())){
|
if(Hider.contains(uuid.toString())){
|
||||||
kills.put(uuid.toString(), kills.get(uuid.toString())+1);
|
if(hider_kills.containsKey(uuid.toString())){
|
||||||
} else {
|
hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1);
|
||||||
kills.put(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){
|
public static void addDeath(UUID uuid){
|
||||||
if(deaths.containsKey(uuid.toString())){
|
if(Hider.contains(uuid.toString())){
|
||||||
deaths.put(uuid.toString(), deaths.get(uuid.toString())+1);
|
if(hider_deaths.containsKey(uuid.toString())){
|
||||||
} else {
|
hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1);
|
||||||
deaths.put(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<String, Integer> getKills(){
|
public static Map<String, Integer> getHiderKills(){
|
||||||
return new HashMap<>(kills);
|
return new HashMap<>(hider_kills);
|
||||||
}
|
}
|
||||||
|
public static Map<String, Integer> getSeekerKills(){
|
||||||
public static Map<String, Integer> getDeaths(){
|
return new HashMap<>(seeker_kills);
|
||||||
return new HashMap<>(deaths);
|
}
|
||||||
|
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) {
|
public static void createLobbyBoard(Player player) {
|
||||||
|
|
|
@ -215,20 +215,23 @@ public class EventListener implements Listener {
|
||||||
// Broadcast player death message
|
// Broadcast player death message
|
||||||
if (Board.isSeeker(player)) {
|
if (Board.isSeeker(player)) {
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
|
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)) {
|
} else if (Board.isHider(player)) {
|
||||||
if (attacker == null) {
|
if (attacker == null) {
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString());
|
Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString());
|
||||||
} else {
|
} else {
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString());
|
Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString());
|
||||||
}
|
}
|
||||||
|
Board.addDeath(player.getUniqueId());
|
||||||
Board.addSeeker(player);
|
Board.addSeeker(player);
|
||||||
}
|
}
|
||||||
// Add leaderboard stats
|
// Add leaderboard kills if attacker
|
||||||
Board.addDeath(player.getUniqueId());
|
if(attacker != null && ( Board.isHider(player) || Board.getFirstSeeker().getName().equals(player.getName()) ) )
|
||||||
if(attacker != null){ Board.addKill(attacker.getUniqueId()); }
|
Board.addKill(attacker.getUniqueId());
|
||||||
Game.resetPlayer(player);
|
Game.resetPlayer(player);
|
||||||
Board.reloadBoardTeams();
|
Board.reloadBoardTeams();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
|
|
@ -155,35 +155,35 @@ public class Game {
|
||||||
status = Status.ENDING;
|
status = Status.ENDING;
|
||||||
for(Player player : Board.getPlayers()) {
|
for(Player player : Board.getPlayers()) {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()){
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
||||||
if(Version.atLeast("1.9")){
|
if(Version.atLeast("1.9")){
|
||||||
for(Player temp : Board.getPlayers()) {
|
for(Player temp : Board.getPlayers()) {
|
||||||
Packet.setGlow(player, temp, false);
|
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;
|
if(status == Status.STANDBY) return;
|
||||||
tick = 0;
|
tick = 0;
|
||||||
countdownTime = -1;
|
countdownTime = -1;
|
||||||
status = Status.STANDBY;
|
status = Status.STANDBY;
|
||||||
gameId++;
|
gameId++;
|
||||||
timeLeft = 0;
|
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());
|
worldBorder.resetWorldborder(getGameWorld());
|
||||||
for(Player player : Board.getPlayers()) {
|
for(Player player : Board.getPlayers()) {
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()){
|
||||||
|
@ -196,6 +196,10 @@ public class Game {
|
||||||
Packet.setGlow(player, temp, false);
|
Packet.setGlow(player, temp, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(PotionEffect effect : player.getActivePotionEffects()){
|
||||||
|
player.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
||||||
if(leaveOnEnd){
|
if(leaveOnEnd){
|
||||||
Board.removeBoard(player);
|
Board.removeBoard(player);
|
||||||
Board.remove(player);
|
Board.remove(player);
|
||||||
|
@ -288,7 +292,7 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void join(Player player){
|
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.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
|
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
|
||||||
|
@ -308,10 +312,11 @@ public class Game {
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()){
|
||||||
player2.hidePlayer(player);
|
player2.hidePlayer(player);
|
||||||
}
|
}
|
||||||
player.setFlying(true);
|
|
||||||
player.setAllowFlight(true);
|
|
||||||
Board.createGameBoard(player);
|
Board.createGameBoard(player);
|
||||||
player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
|
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());
|
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){
|
public static void leave(Player player){
|
||||||
player.setFlying(false);
|
player.setFlying(false);
|
||||||
player.setAllowFlight(false);
|
player.setAllowFlight(false);
|
||||||
|
player.setFallDistance(0.0F);
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()){
|
||||||
player2.showPlayer(player);
|
player2.showPlayer(player);
|
||||||
player.showPlayer(player2);
|
player.showPlayer(player2);
|
||||||
|
|
|
@ -35,7 +35,6 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||||
String[] args = params.split("_");
|
String[] args = params.split("_");
|
||||||
System.out.println();
|
|
||||||
if(args.length < 1) return null;
|
if(args.length < 1) return null;
|
||||||
if(args[0].equals("stats") && args.length == 2){
|
if(args[0].equals("stats") && args.length == 2){
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
||||||
|
|
Loading…
Reference in a new issue