|
4 | 4 | import com.google.common.collect.Sets; |
5 | 5 | import org.bukkit.GameRule; |
6 | 6 | import org.bukkit.Material; |
| 7 | +import org.bukkit.World; |
7 | 8 | import org.bukkit.advancement.AdvancementProgress; |
8 | 9 | import org.jetbrains.annotations.ApiStatus; |
9 | 10 | import org.mvplugins.multiverse.core.economy.MVEconomist; |
10 | 11 | import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; |
11 | 12 | import org.mvplugins.multiverse.core.utils.ReflectHelper; |
12 | 13 | import org.mvplugins.multiverse.external.vavr.control.Option; |
| 14 | +import org.mvplugins.multiverse.external.vavr.control.Try; |
13 | 15 | import org.mvplugins.multiverse.inventories.MultiverseInventories; |
14 | 16 | import org.mvplugins.multiverse.inventories.config.InventoriesConfig; |
15 | 17 | import org.mvplugins.multiverse.inventories.profile.data.ProfileData; |
@@ -600,26 +602,34 @@ public void updateProfile(ProfileData profile, Player player) { |
600 | 602 | public boolean updatePlayer(Player player, ProfileData profile) { |
601 | 603 | Location loc = profile.get(BED_SPAWN); |
602 | 604 | if (loc == null) { |
603 | | - Logging.finer("No bed location saved"); |
604 | | - ignoreSpawnListener.add(player.getUniqueId()); |
605 | | - player.setBedSpawnLocation(player.getWorld().getSpawnLocation(), true); |
606 | | - ignoreSpawnListener.remove(player.getUniqueId()); |
| 605 | + Logging.finer("No respawn location saved"); |
| 606 | + setSpawnLocation(player, player.getWorld().getSpawnLocation()); |
607 | 607 | return false; |
608 | 608 | } |
609 | | - ignoreSpawnListener.add(player.getUniqueId()); |
610 | | - player.setBedSpawnLocation(loc, true); |
611 | | - ignoreSpawnListener.remove(player.getUniqueId()); |
612 | | - Logging.finer("updating bed: " + player.getBedSpawnLocation()); |
| 609 | + World loclWorld = Try.of(loc::getWorld).getOrNull(); |
| 610 | + if (loclWorld == null) { |
| 611 | + Logging.warning("Respawn location has invalid world!"); |
| 612 | + setSpawnLocation(player, player.getWorld().getSpawnLocation()); |
| 613 | + return false; |
| 614 | + } |
| 615 | + setSpawnLocation(player, loc); |
| 616 | + Logging.finer("updated respawn location: " + player.getBedSpawnLocation()); |
613 | 617 | return true; |
614 | 618 | } |
615 | 619 | }).serializer(new ProfileEntry(false, DataStrings.PLAYER_BED_SPAWN_LOCATION), new LocationSerializer()) |
616 | 620 | .altName("bedspawn").altName("bed").altName("beds").altName("bedspawns").build(); |
617 | 621 |
|
618 | 622 | // todo: handle this somewhere better |
619 | | - private static List<UUID> ignoreSpawnListener = new ArrayList<>(); |
620 | | - private static boolean hasSetSpawnEvent = ReflectHelper.hasClass("org.bukkit.event.player.PlayerSpawnChangeEvent") |
| 623 | + private static final List<UUID> ignoreSpawnListener = new ArrayList<>(); |
| 624 | + private static final boolean hasSetSpawnEvent = ReflectHelper.hasClass("org.bukkit.event.player.PlayerSpawnChangeEvent") |
621 | 625 | || ReflectHelper.hasClass("com.destroystokyo.paper.event.player.PlayerSetSpawnEvent"); |
622 | 626 |
|
| 627 | + private static void setSpawnLocation(Player player, Location loc) { |
| 628 | + ignoreSpawnListener.add(player.getUniqueId()); |
| 629 | + player.setBedSpawnLocation(loc, true); |
| 630 | + ignoreSpawnListener.remove(player.getUniqueId()); |
| 631 | + } |
| 632 | + |
623 | 633 | @ApiStatus.Internal |
624 | 634 | public static boolean isIgnoringSpawnListener(Player player) { |
625 | 635 | return ignoreSpawnListener.contains(player.getUniqueId()); |
|
0 commit comments