Skip to content

Commit

Permalink
#patch Fixed multiverse teleportation (#55)
Browse files Browse the repository at this point in the history
* Bump version from 1.3.9-SNAPSHOT0 to 1.3.10

* Fix for multiverse teleportation problems on a multiworld server (also see thread in Discord server) (#53)

* Bump version from 1.3.10 to 1.3.10-SNAPSHOT0

* Adjusted CHANGELOG.md

* Bump version from 1.3.10-SNAPSHOT0 to 1.3.10-SNAPSHOT1

---------

Co-authored-by: version-bump[github-action] <41898282+version-bump[github-action]@users.noreply.github.com>
Co-authored-by: Onno <emailodg@gmail.com>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent d81d753 commit 177d4b4
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.3.10 Release (09.07.2024)
* Fixed multiverse teleportation problems on a multiworld server

### 1.3.9 Release (18.06.2024)
* Major API Revamp for exposing methods that were not exposed previously to external plugins
* Fixed move false not working
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,43 @@ public void joinAttempt(@NotNull Player player, @NotNull IPluginArena 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() == IArenaState.WAITING_FOR_PLAYERS) {
plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.WAITING_FOR_PLAYERS);
} else if(ArenaState.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() == IArenaState.WAITING_FOR_PLAYERS) {
plugin.getSpecialItemManager().addSpecialItemsOfStage(player, SpecialItem.DisplayStage.WAITING_FOR_PLAYERS);
} else if(ArenaState.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 IPluginArena arena) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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
* <p>Created at 01.11.2021
Expand Down Expand Up @@ -71,52 +73,53 @@ public static void hidePlayersOutsideTheGame(Player player, PluginArena arena) {
VersionUtils.hidePlayer(plugin, players, player);
}
}

public static void preparePlayerForGame(
public static CompletableFuture<Void> preparePlayerForGame(
IPluginArena arena, Player player, Location location, boolean spectator) {
IUser 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(IPluginArena.IBarAction.ADD, player);
arena.getScoreboardManager().createScoreboard(user);
return VersionUtils.teleport(player, location).thenAccept(bo -> {
IUser 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(IPluginArena.IBarAction.ADD, player);
arena.getScoreboardManager().createScoreboard(user);
});
}

public static void resetPlayerAfterGame(IPluginArena arena, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean> 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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
group=plugily.projects
version=1.3.10
version=1.3.10-SNAPSHOT1

0 comments on commit 177d4b4

Please sign in to comment.