|
6 | 6 | import org.bukkit.entity.Player; |
7 | 7 | import org.bukkit.util.Vector; |
8 | 8 | import org.mvplugins.multiverse.core.destination.DestinationInstance; |
| 9 | +import org.mvplugins.multiverse.core.world.MultiverseWorld; |
| 10 | +import org.mvplugins.multiverse.core.world.WorldManager; |
9 | 11 | import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; |
10 | 12 | import org.mvplugins.multiverse.external.vavr.control.Option; |
11 | 13 | import org.mvplugins.multiverse.inventories.profile.key.ContainerType; |
|
15 | 17 |
|
16 | 18 | public final class LastLocationDestinationInstance extends DestinationInstance<LastLocationDestinationInstance, LastLocationDestination> { |
17 | 19 |
|
| 20 | + private final WorldManager worldManager; |
18 | 21 | private final WorldGroupManager worldGroupManager; |
19 | 22 | private final ProfileContainerStoreProvider profileContainerStoreProvider; |
20 | 23 | private final String worldName; |
21 | 24 |
|
22 | 25 | LastLocationDestinationInstance( |
23 | 26 | @NotNull LastLocationDestination destination, |
| 27 | + @NotNull WorldManager worldManager, |
24 | 28 | @NotNull WorldGroupManager worldGroupManager, |
25 | 29 | @NotNull ProfileContainerStoreProvider profileContainerStoreProvider, |
26 | 30 | @NotNull String worldName) { |
27 | 31 | super(destination); |
| 32 | + this.worldManager = worldManager; |
28 | 33 | this.worldGroupManager = worldGroupManager; |
29 | 34 | this.profileContainerStoreProvider = profileContainerStoreProvider; |
30 | 35 | this.worldName = worldName; |
31 | 36 | } |
32 | 37 |
|
33 | 38 | @Override |
34 | 39 | public @NotNull Option<Location> getLocation(@NotNull Entity teleportee) { |
35 | | - Logging.warning("LastLocationDestination: teleportee: " + teleportee); |
| 40 | + Logging.finer("LastLocationDestination: teleportee: " + teleportee); |
36 | 41 | if (!(teleportee instanceof Player player)) { |
37 | | - return Option.none(); |
| 42 | + return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation); |
38 | 43 | } |
39 | 44 |
|
40 | 45 | var playerWorld = player.getWorld().getName(); |
41 | 46 | if (playerWorld.equals(worldName)) { |
42 | | - return Option.none(); |
| 47 | + return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation); |
43 | 48 | } |
44 | 49 |
|
45 | 50 | for (var group : worldGroupManager.getGroupsForWorld(worldName)) { |
46 | | - Logging.warning("LastLocationDestination: group: " + group); |
| 51 | + Logging.finer("LastLocationDestination: group: " + group); |
47 | 52 | if (!group.containsWorld(playerWorld) && group.getApplicableShares().contains(Sharables.LAST_LOCATION)) { |
48 | 53 | return Option.of(profileContainerStoreProvider.getStore(ContainerType.GROUP) |
49 | 54 | .getContainer(group.getName()) |
50 | 55 | .getPlayerProfileNow(player) |
51 | | - .get(Sharables.LAST_LOCATION)); |
| 56 | + .get(Sharables.LAST_LOCATION)) |
| 57 | + .orElse(() -> worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation)); |
52 | 58 | } |
53 | 59 | } |
54 | 60 |
|
55 | 61 | // Means last location isn't shared by any group, and will be read directly for world profile |
56 | 62 | return Option.of(profileContainerStoreProvider.getStore(ContainerType.WORLD) |
57 | 63 | .getContainer(worldName) |
58 | 64 | .getPlayerProfileNow(player) |
59 | | - .get(Sharables.LAST_LOCATION)); |
| 65 | + .get(Sharables.LAST_LOCATION)) |
| 66 | + .orElse(() -> worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation)); |
60 | 67 | } |
61 | 68 |
|
62 | 69 | @Override |
|
0 commit comments