From 3d0947b13484ed16798489b9c459b7b63a323b35 Mon Sep 17 00:00:00 2001 From: Onno Date: Sun, 25 Jul 2021 13:16:10 +0200 Subject: [PATCH 1/3] Fixed bug where Players were able to move from Spawn platforms before the game start by breaking blocks and Jumping before joining via Signs. --- .../java/tk/shanebee/hg/game/GamePlayerData.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java index 31074664..76457161 100644 --- a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java +++ b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java @@ -138,7 +138,7 @@ void heal(Player player) { * @param player Player to freeze */ public void freeze(Player player) { - player.setGameMode(GameMode.SURVIVAL); + player.setGameMode(GameMode.ADVENTURE); //Change to Adventure mode instead of Survival, to prevent moving by breaking blocks which get cancelled breaking before the game starts. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 23423525, -10, false, false)); player.setWalkSpeed(0.0001F); player.setFoodLevel(1); @@ -153,6 +153,7 @@ public void freeze(Player player) { * @param player Player to unfreeze */ public void unFreeze(Player player) { + player.setGameMode(GameMode.SURVIVAL); //Change back to Survival Mode. player.removePotionEffect(PotionEffectType.JUMP); player.setWalkSpeed(0.2F); } @@ -305,6 +306,16 @@ public void join(Player player, boolean command) { freeze(player); kills.put(player, 0); + // Sometimes, when joining from a different world or unloaded chunks using e.g. Multiverse plugins, + // after the first teleportation you are still able to make 1 last jump at the spawnpoint when joining via + // a Sign, from the velocity you have at the moment just before joining. This can happen because of server lag for example. + // You are then able to get closer to the middle while the game did not yet start and you are not placed + // properly on the spawn point. Therefore, I included an extra teleport to make sure everyone for sure is at the beginning before game start. + // I could not think of a smarter way to resolve this issue and I really needed it to be able to player HungerGames + // without any problems. There must however be smarter ways to resolve this issue. (Resetting player velocity did not work :c.) + // I might as well not fully understand the issue, I only know it occurs and how to reproduce it. + PaperLib.teleportAsync(player, loc); + if (players.size() == 1 && status == Status.READY) gameArenaData.setStatus(Status.WAITING); if (players.size() >= game.gameArenaData.minPlayers && (status == Status.WAITING || status == Status.READY)) { From 2c385bcfe8457db9212c811acca13ab6f829658d Mon Sep 17 00:00:00 2001 From: Onno Date: Sun, 25 Jul 2021 13:43:20 +0200 Subject: [PATCH 2/3] Fixed small bug where Gamemode change did not always work with teleportation to different world of Multiverse. --- src/main/java/tk/shanebee/hg/game/GamePlayerData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java index 76457161..228e6fd5 100644 --- a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java +++ b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java @@ -138,7 +138,9 @@ void heal(Player player) { * @param player Player to freeze */ public void freeze(Player player) { - player.setGameMode(GameMode.ADVENTURE); //Change to Adventure mode instead of Survival, to prevent moving by breaking blocks which get cancelled breaking before the game starts. + // Change to Adventure mode instead of Survival, to prevent moving by breaking blocks which get cancelled breaking before the game starts. + // In order to make the gamemode switch work with Multiverse as well, only change it 2 ticks later. + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> player.setGameMode(GameMode.ADVENTURE), 2l); player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 23423525, -10, false, false)); player.setWalkSpeed(0.0001F); player.setFoodLevel(1); From 0f36821203304ba82f0ae1582d81562507e00f0d Mon Sep 17 00:00:00 2001 From: Onno Date: Thu, 5 Aug 2021 12:42:26 +0200 Subject: [PATCH 3/3] Fixed a bug when invalid arena name was given on spectate command. Made spectators join in the air, flying directly. --- .../tk/shanebee/hg/commands/SpectateCmd.java | 16 +++++++++------- .../java/tk/shanebee/hg/game/GamePlayerData.java | 6 +++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/tk/shanebee/hg/commands/SpectateCmd.java b/src/main/java/tk/shanebee/hg/commands/SpectateCmd.java index 3bf6701f..9f66382a 100644 --- a/src/main/java/tk/shanebee/hg/commands/SpectateCmd.java +++ b/src/main/java/tk/shanebee/hg/commands/SpectateCmd.java @@ -22,13 +22,15 @@ public boolean run() { Util.scm(player, lang.cmd_join_in_game); } else { Game game = gameManager.getGame(args[1]); - GamePlayerData gamePlayerData = game.getGamePlayerData(); - if (game != null && !gamePlayerData.getPlayers().contains(player.getUniqueId()) && !gamePlayerData.getSpectators().contains(player.getUniqueId())) { - Status status = game.getGameArenaData().getStatus(); - if (status == Status.RUNNING || status == Status.BEGINNING) { - gamePlayerData.spectate(player); - } else { - Util.scm(player, "This game is not running, status: " + status); + if (game != null) { + GamePlayerData gamePlayerData = game.getGamePlayerData(); + if (!gamePlayerData.getPlayers().contains(player.getUniqueId()) && !gamePlayerData.getSpectators().contains(player.getUniqueId())) { + Status status = game.getGameArenaData().getStatus(); + if (status == Status.RUNNING || status == Status.BEGINNING) { + gamePlayerData.spectate(player); + } else { + Util.scm(player, "This game is not running, status: " + status); + } } } else { Util.scm(player, lang.cmd_delete_noexist); diff --git a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java index 228e6fd5..38dc347f 100644 --- a/src/main/java/tk/shanebee/hg/game/GamePlayerData.java +++ b/src/main/java/tk/shanebee/hg/game/GamePlayerData.java @@ -407,7 +407,11 @@ void exit(Player player, @Nullable Location exitLocation) { */ public void spectate(Player spectator) { UUID uuid = spectator.getUniqueId(); - spectator.teleport(game.gameArenaData.getSpawns().get(0)); + Location spectatorSpawn = game.gameArenaData.getSpawns().get(0); + //Make players join as flying in spectator mode, such that they directly see they can fly. + Location newSpectatorSpawn = spectatorSpawn.clone().add(0, 5, 0); + spectator.teleport(newSpectatorSpawn); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> spectator.setFlying(true), 5l); if (playerManager.hasPlayerData(uuid)) { playerManager.transferPlayerDataToSpectator(uuid); } else {