From 1d6a457aa4d2e9492865bb6bfe5be4a28a600eed Mon Sep 17 00:00:00 2001 From: Onno Date: Mon, 17 Jun 2024 17:38:49 +0200 Subject: [PATCH 1/2] Fixed multiverse teleportation problems on multiworld server --- .../classic/arena/PluginArenaManager.java | 59 ++++++------ .../classic/arena/PluginArenaUtils.java | 91 ++++++++++--------- .../arena/states/PluginStartingState.java | 3 +- .../events/spectator/SpectatorEvents.java | 3 +- .../classic/utils/version/VersionUtils.java | 9 +- 5 files changed, 85 insertions(+), 80 deletions(-) diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java index 16b21332..8f181554 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java @@ -78,42 +78,43 @@ public void joinAttempt(@NotNull Player player, @NotNull PluginArena arena) { new MessageBuilder("IN_GAME_SPECTATOR_BLOCKED").asKey().player(player).arena(arena).sendPlayer(); return; } - PluginArenaUtils.preparePlayerForGame(arena, player, arena.getSpectatorLocation(), true); - new MessageBuilder("IN_GAME_SPECTATOR_YOU_ARE_SPECTATOR").asKey().player(player).arena(arena).sendPlayer(); - PluginArenaUtils.hidePlayer(player, arena); - for(Player spectator : arena.getPlayers()) { - if(plugin.getUserManager().getUser(spectator).isSpectator()) { - VersionUtils.hidePlayer(plugin, player, spectator); - } else { - VersionUtils.showPlayer(plugin, player, spectator); + PluginArenaUtils.preparePlayerForGame(arena, player, arena.getSpectatorLocation(), true).thenAccept(act -> { + new MessageBuilder("IN_GAME_SPECTATOR_YOU_ARE_SPECTATOR").asKey().player(player).arena(arena).sendPlayer(); + PluginArenaUtils.hidePlayer(player, arena); + for (Player spectator : arena.getPlayers()) { + if (plugin.getUserManager().getUser(spectator).isSpectator()) { + VersionUtils.hidePlayer(plugin, player, spectator); + } else { + VersionUtils.showPlayer(plugin, player, spectator); + } } - } - additionalSpectatorSettings(player, arena); - plugin.getDebugger().debug("[{0}] Final join attempt as spectator for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start); + additionalSpectatorSettings(player, arena); + plugin.getDebugger().debug("[{0}] Final join attempt as spectator for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start); + }); return; } - PluginArenaUtils.preparePlayerForGame(arena, player, arena.getLobbyLocation(), false); - - new MessageBuilder(MessageBuilder.ActionType.JOIN).arena(arena).player(player).sendArena(); - new TitleBuilder("IN_GAME_JOIN_TITLE").asKey().arena(arena).player(player).sendPlayer(); + PluginArenaUtils.preparePlayerForGame(arena, player, arena.getLobbyLocation(), false).thenAccept(act -> { + new MessageBuilder(MessageBuilder.ActionType.JOIN).arena(arena).player(player).sendArena(); + new TitleBuilder("IN_GAME_JOIN_TITLE").asKey().arena(arena).player(player).sendPlayer(); - if(plugin.getConfigPreferences().getOption("KITS")) { - plugin.getUserManager().getUser(player).setKit(plugin.getKitRegistry().getDefaultKit()); - } - plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.LOBBY); - if(arena.getArenaState() == ArenaState.WAITING_FOR_PLAYERS) { - plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.WAITING_FOR_PLAYERS); - } else if(arena.getArenaState().isStartingStage(arena)) { - plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.ENOUGH_PLAYERS_TO_START); - } + if(plugin.getConfigPreferences().getOption("KITS")) { + plugin.getUserManager().getUser(player).setKit(plugin.getKitRegistry().getDefaultKit()); + } + plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.LOBBY); + if(arena.getArenaState() == ArenaState.WAITING_FOR_PLAYERS) { + plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.WAITING_FOR_PLAYERS); + } else if(arena.getArenaState().isStartingStage(arena)) { + plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.ENOUGH_PLAYERS_TO_START); + } - for(Player arenaPlayer : arena.getPlayers()) { - PluginArenaUtils.showPlayer(arenaPlayer, arena); - } + for(Player arenaPlayer : arena.getPlayers()) { + PluginArenaUtils.showPlayer(arenaPlayer, arena); + } - plugin.getSignManager().updateSigns(); - plugin.getDebugger().debug("[{0}] Final join attempt as player for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start); + plugin.getSignManager().updateSigns(); + plugin.getDebugger().debug("[{0}] Final join attempt as player for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start); + }); } private boolean joinAsParty(@NotNull Player player, @NotNull PluginArena arena) { diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaUtils.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaUtils.java index 27b52fe2..95a8c79c 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaUtils.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaUtils.java @@ -32,6 +32,8 @@ import plugily.projects.minigamesbox.classic.utils.serialization.InventorySerializer; import plugily.projects.minigamesbox.classic.utils.version.VersionUtils; +import java.util.concurrent.CompletableFuture; + /** * @author Tigerpanzer_02 *

Created at 01.11.2021 @@ -69,51 +71,52 @@ public static void hidePlayersOutsideTheGame(Player player, PluginArena arena) { } } - public static void preparePlayerForGame( + public static CompletableFuture preparePlayerForGame( PluginArena arena, Player player, Location location, boolean spectator) { - User user = plugin.getUserManager().getUser(player); - if(plugin.getConfigPreferences().getOption("INVENTORY_MANAGER")) { - InventorySerializer.saveInventoryToFile(plugin, player); - } - VersionUtils.teleport(player, location); - player.getInventory().clear(); - player - .getActivePotionEffects() - .forEach(potionEffect -> player.removePotionEffect(potionEffect.getType())); - VersionUtils.setMaxHealth(player, VersionUtils.getMaxHealth(player)); - player.setHealth(VersionUtils.getMaxHealth(player)); - player.setFoodLevel(20); - player.setGameMode(GameMode.SURVIVAL); - player - .getInventory() - .setArmorContents( - new ItemStack[]{ - new ItemStack(Material.AIR), - new ItemStack(Material.AIR), - new ItemStack(Material.AIR), - new ItemStack(Material.AIR) - }); - player.setExp(1); - player.setLevel(0); - player.setWalkSpeed(0.2f); - player.setFlySpeed(0.1f); - - if(spectator) { - player.setAllowFlight(true); - player.setFlying(true); - user.setSpectator(true); - player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); - plugin - .getSpecialItemManager() - .addSpecialItemsOfStage(player, SpecialItem.DisplayStage.SPECTATOR); - } else { - player.setAllowFlight(false); - player.setFlying(false); - user.setSpectator(false); - } - player.updateInventory(); - arena.getBossbarManager().doBarAction(PluginArena.BarAction.ADD, player); - arena.getScoreboardManager().createScoreboard(user); + return VersionUtils.teleport(player, location).thenAccept(bo -> { + User user = plugin.getUserManager().getUser(player); + if (plugin.getConfigPreferences().getOption("INVENTORY_MANAGER")) { + InventorySerializer.saveInventoryToFile(plugin, player); + } + player.getInventory().clear(); + player + .getActivePotionEffects() + .forEach(potionEffect -> player.removePotionEffect(potionEffect.getType())); + VersionUtils.setMaxHealth(player, VersionUtils.getMaxHealth(player)); + player.setHealth(VersionUtils.getMaxHealth(player)); + player.setFoodLevel(20); + player.setGameMode(GameMode.SURVIVAL); + player + .getInventory() + .setArmorContents( + new ItemStack[]{ + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR) + }); + player.setExp(1); + player.setLevel(0); + player.setWalkSpeed(0.2f); + player.setFlySpeed(0.1f); + + if (spectator) { + player.setAllowFlight(true); + player.setFlying(true); + user.setSpectator(true); + player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); + plugin + .getSpecialItemManager() + .addSpecialItemsOfStage(player, SpecialItem.DisplayStage.SPECTATOR); + } else { + player.setAllowFlight(false); + player.setFlying(false); + user.setSpectator(false); + } + player.updateInventory(); + arena.getBossbarManager().doBarAction(PluginArena.BarAction.ADD, player); + arena.getScoreboardManager().createScoreboard(user); + }); } public static void resetPlayerAfterGame(PluginArena arena, Player player) { diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginStartingState.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginStartingState.java index 07c808c4..cd433d81 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginStartingState.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginStartingState.java @@ -100,7 +100,7 @@ public void handleCall(PluginArena arena) { arena.getBossbarManager().setProgress(1.0); org.bukkit.Location arenaLoc = arena.getStartLocation(); for(Player player : arena.getPlayers()) { - VersionUtils.teleport(player, arenaLoc); + VersionUtils.teleport(player, arenaLoc).thenAccept(bol -> { PluginArenaUtils.hidePlayersOutsideTheGame(player, arena); player.setExp(0); player.setLevel(0); @@ -116,6 +116,7 @@ public void handleCall(PluginArena arena) { plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.IN_GAME); plugin.getRewardsHandler().performReward(player, arena, plugin.getRewardsHandler().getRewardType("START_GAME")); plugin.getUserManager().addStat(user, plugin.getStatsStorage().getStatisticType("GAMES_PLAYED")); + }); } arenaTimer = plugin.getConfig().getInt("Time-Manager.In-Game", 270); plugin.getDebugger().performance("ArenaUpdate", "Arena {0} current timer set to {1}", arena.getId(), arenaTimer); diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/events/spectator/SpectatorEvents.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/events/spectator/SpectatorEvents.java index 6b5c8455..437de7ae 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/events/spectator/SpectatorEvents.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/events/spectator/SpectatorEvents.java @@ -146,8 +146,7 @@ public void onDamage(EntityDamageEvent event) { return; } if(player.getLocation().getY() < VersionUtils.getWorldMinHeight(player.getWorld())) { - VersionUtils.teleport(player, arena.getStartLocation()); - event.setDamage(0); + VersionUtils.teleport(player, arena.getStartLocation()).thenAccept(bol -> event.setDamage(0)); } event.setCancelled(true); } diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/utils/version/VersionUtils.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/utils/version/VersionUtils.java index 203dcedf..b70c84f3 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/utils/version/VersionUtils.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/utils/version/VersionUtils.java @@ -62,6 +62,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -170,20 +171,19 @@ public static SkullMeta setPlayerHead(Player player, SkullMeta meta) { private static JavaPlugin plugin; - public static void teleport(Entity entity, Location location) { + public static CompletableFuture teleport(Entity entity, Location location) { if(isPaper) { // Avoid Future.get() method to be called from the main thread if(Bukkit.isPrimaryThread()) { // Checks if the current thread is not async - PaperLib.teleportAsync(entity, location); - return; + return PaperLib.teleportAsync(entity, location); } if(plugin == null) plugin = JavaPlugin.getPlugin(PluginMain.class); try { - Bukkit.getScheduler().callSyncMethod(plugin, () -> PaperLib.teleportAsync(entity, location)).get(); + return Bukkit.getScheduler().callSyncMethod(plugin, () -> PaperLib.teleportAsync(entity, location)).get(); } catch(InterruptedException | ExecutionException e) { e.printStackTrace(); } catch(CancellationException e) { @@ -192,6 +192,7 @@ public static void teleport(Entity entity, Location location) { } else { entity.teleport(location); } + return new CompletableFuture<>(); } public static void sendParticles(String particleName, Player player, Location location, int count) { From d81d753ad76eb83521cc163b707bb4b6e759282c Mon Sep 17 00:00:00 2001 From: "version-bump[github-action]" <41898282+version-bump[github-action]@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:02:03 +0000 Subject: [PATCH 2/2] Bump version from 1.3.9-SNAPSHOT0 to 1.3.10 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 27ab3c41..06478065 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,4 @@ # along with this program. If not, see . # group=plugily.projects -version=1.3.9-SNAPSHOT0 +version=1.3.10