|
8 | 8 | import org.bukkit.entity.Player; |
9 | 9 |
|
10 | 10 | import java.util.*; |
| 11 | +import java.util.concurrent.CompletableFuture; |
11 | 12 |
|
12 | 13 | public class GameManager { |
13 | 14 |
|
@@ -85,19 +86,118 @@ public static void setGameRunning(Integer gamerunning) { |
85 | 86 | } |
86 | 87 |
|
87 | 88 | public static void teleportToLobby(Player player) { |
| 89 | + if (player == null) { |
| 90 | + // Handle null player |
| 91 | + MessageUtils.sendConsole("error", "Method: teleportToLobby(Player player)"); |
| 92 | + MessageUtils.sendConsole("error", "Player is null!"); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
88 | 96 | Location location = RedLightGreenLight.getPlugin().getConfigManager().getLobbyLocation(); |
89 | | - PaperLib.teleportAsync(player, location); |
90 | | - player.setInvulnerable(RedLightGreenLight.getPlugin().getConfigManager().isLeavePlayerInvulnerable()); |
91 | | - if (!(player.hasPermission("redlight.bypass.gamemode") || player.hasPermission("redlight.*") || player.isOp())) { |
92 | | - player.setGameMode(GameMode.SURVIVAL); |
| 97 | + if (location == null) { |
| 98 | + // Handle null location |
| 99 | + MessageUtils.sendConsole("error", "Method: teleportToLobby(Player player)"); |
| 100 | + MessageUtils.sendConsole("error", "Lobby location is null!"); |
| 101 | + return; |
93 | 102 | } |
| 103 | + |
| 104 | + CompletableFuture<Boolean> future = PaperLib.teleportAsync(player, location); |
| 105 | + future.thenAccept(result -> { |
| 106 | + if (result) { |
| 107 | + player.setInvulnerable(RedLightGreenLight.getPlugin().getConfigManager().isLeavePlayerInvulnerable()); |
| 108 | + if (!(player.hasPermission("redlight.bypass.gamemode") || player.hasPermission("redlight.*") || player.isOp())) { |
| 109 | + player.setGameMode(GameMode.SURVIVAL); |
| 110 | + MessageUtils.sendDebugConsole("info", "Player " + player.getName() + " did not have bypass permission."); |
| 111 | + } |
| 112 | + MessageUtils.sendDebugConsole("info", "Player " + player.getName() + " teleported to lobby location."); |
| 113 | + } else { |
| 114 | + // Handle teleportation failure |
| 115 | + MessageUtils.sendConsole("error", "Method: teleportToLobby(Player player)"); |
| 116 | + MessageUtils.sendConsole("error", "Failed to teleport player to lobby location!"); |
| 117 | + MessageUtils.sendConsole("error", "Using PaperLib teleportAsync method."); |
| 118 | + MessageUtils.sendConsole("info", "Trying alternate FoliaLib AsyncTeleport method."); |
| 119 | + CompletableFuture<Boolean> foliaLibFuture = RedLightGreenLight.getPlugin().getFoliaLib().getScheduler().teleportAsync(player, location); |
| 120 | + foliaLibFuture.thenAccept(foliaLibResult -> { |
| 121 | + if (foliaLibResult) { |
| 122 | + player.setInvulnerable(RedLightGreenLight.getPlugin().getConfigManager().isLeavePlayerInvulnerable()); |
| 123 | + if (!(player.hasPermission("redlight.bypass.gamemode") || player.hasPermission("redlight.*") || player.isOp())) { |
| 124 | + player.setGameMode(GameMode.SURVIVAL); |
| 125 | + } |
| 126 | + MessageUtils.sendDebugConsole("info", "Player " + player.getName() + " teleported to lobby location."); |
| 127 | + } else { |
| 128 | + // Handle fallback teleportation failure |
| 129 | + MessageUtils.sendConsole("error", "Method: teleportToLobby(Player player)"); |
| 130 | + MessageUtils.sendConsole("error", "Failed to teleport player to lobby location!"); |
| 131 | + MessageUtils.sendConsole("error", "Using FoliaLib AsyncTeleport method."); |
| 132 | + MessageUtils.sendConsole("severe", "<=============================================>"); |
| 133 | + MessageUtils.sendConsole("severe", "Failed to teleport player to lobby location!"); |
| 134 | + MessageUtils.sendConsole("severe", "Player: " + player.getName()); |
| 135 | + MessageUtils.sendConsole("severe", "Location: " + location); |
| 136 | + MessageUtils.sendConsole("severe", "Attempted using PaperLib teleportAsync method."); |
| 137 | + MessageUtils.sendConsole("severe", "Attempted using backup FoliaLib AsyncTeleport method."); |
| 138 | + MessageUtils.sendConsole("severe", "Please check your lobby location in the config."); |
| 139 | + MessageUtils.sendConsole("severe", "Please check your server console for more information."); |
| 140 | + MessageUtils.sendConsole("severe", "Please send your server console log to the plugin developer."); |
| 141 | + MessageUtils.sendConsole("severe", "Discord: https://discord.gg/crapticraft"); |
| 142 | + MessageUtils.sendConsole("severe", "<=============================================>"); |
| 143 | + } |
| 144 | + }); |
| 145 | + } |
| 146 | + }); |
94 | 147 | } |
95 | 148 |
|
96 | 149 | public static void spectatorTeleportToArena(Player player) { |
| 150 | + if (player == null) { |
| 151 | + // Handle null player |
| 152 | + MessageUtils.sendConsole("error", "Method: spectatorTeleportToArena(Player player)"); |
| 153 | + MessageUtils.sendConsole("error", "Player is null!"); |
| 154 | + return; |
| 155 | + } |
| 156 | + |
97 | 157 | Location location = RedLightGreenLight.getPlugin().getConfigManager().getSpectateLocation(); |
98 | | - PaperLib.teleportAsync(player, location); |
99 | | - player.setGameMode(GameMode.SPECTATOR); |
100 | | - GameManager.addToSpectating(player); |
| 158 | + if (location == null) { |
| 159 | + // Handle null location |
| 160 | + MessageUtils.sendConsole("error", "Method: spectatorTeleportToArena(Player player)"); |
| 161 | + MessageUtils.sendConsole("error", "Spectate location is null!"); |
| 162 | + return; |
| 163 | + } |
| 164 | + |
| 165 | + CompletableFuture<Boolean> future = PaperLib.teleportAsync(player, location); |
| 166 | + future.thenAccept(result -> { |
| 167 | + if (result) { |
| 168 | + player.setGameMode(GameMode.SPECTATOR); |
| 169 | + MessageUtils.sendDebugConsole("info", "Player " + player.getName() + " teleported to spectate location."); |
| 170 | + } else { |
| 171 | + // Handle teleportation failure |
| 172 | + MessageUtils.sendConsole("error", "Method: spectatorTeleportToArena(Player player)"); |
| 173 | + MessageUtils.sendConsole("error", "Failed to teleport player to spectate location!"); |
| 174 | + MessageUtils.sendConsole("error", "Using PaperLib teleportAsync method."); |
| 175 | + MessageUtils.sendConsole("info", "Trying alternate FoliaLib AsyncTeleport method."); |
| 176 | + CompletableFuture<Boolean> foliaLibFuture = RedLightGreenLight.getPlugin().getFoliaLib().getScheduler().teleportAsync(player, location); |
| 177 | + foliaLibFuture.thenAccept(foliaLibResult -> { |
| 178 | + if (foliaLibResult) { |
| 179 | + player.setGameMode(GameMode.SPECTATOR); |
| 180 | + MessageUtils.sendDebugConsole("info", "Player " + player.getName() + " teleported to spectate location."); |
| 181 | + } else { |
| 182 | + // Handle fallback teleportation failure |
| 183 | + MessageUtils.sendConsole("error", "Method: spectatorTeleportToArena(Player player)"); |
| 184 | + MessageUtils.sendConsole("error", "Failed to teleport player to spectate location!"); |
| 185 | + MessageUtils.sendConsole("error", "Using FoliaLib AsyncTeleport method."); |
| 186 | + MessageUtils.sendConsole("severe", "<=============================================>"); |
| 187 | + MessageUtils.sendConsole("severe", "Failed to teleport player to spectate location!"); |
| 188 | + MessageUtils.sendConsole("severe", "Player: " + player.getName()); |
| 189 | + MessageUtils.sendConsole("severe", "Location: " + location); |
| 190 | + MessageUtils.sendConsole("severe", "Attempted using PaperLib teleportAsync method."); |
| 191 | + MessageUtils.sendConsole("severe", "Attempted using backup FoliaLib AsyncTeleport method."); |
| 192 | + MessageUtils.sendConsole("severe", "Please check your spectate location in the config."); |
| 193 | + MessageUtils.sendConsole("severe", "Please check your server console for more information."); |
| 194 | + MessageUtils.sendConsole("severe", "Please send your server console log to the plugin developer."); |
| 195 | + MessageUtils.sendConsole("severe", "Discord: https://discord.gg/crapticraft"); |
| 196 | + MessageUtils.sendConsole("severe", "<=============================================>"); |
| 197 | + } |
| 198 | + }); |
| 199 | + } |
| 200 | + }); |
101 | 201 | } |
102 | 202 |
|
103 | 203 | public static void startGameArena1(Player player) { |
|
0 commit comments