Skip to content

Commit b1478e6

Browse files
authored
Merge pull request #596 from Multiverse/feat/ll-dest
ll destination defaults to spawn if last location does not exist
2 parents 07d0135 + 195f701 commit b1478e6

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/main/java/org/mvplugins/multiverse/inventories/destination/LastLocationDestination.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.mvplugins.multiverse.inventories.destination;
22

3-
import com.dumptruckman.minecraft.util.Logging;
43
import org.bukkit.command.CommandSender;
5-
import org.checkerframework.checker.units.qual.N;
64
import org.jvnet.hk2.annotations.Service;
75
import org.mvplugins.multiverse.core.destination.Destination;
86
import org.mvplugins.multiverse.core.destination.DestinationSuggestionPacket;
@@ -47,7 +45,12 @@ public final class LastLocationDestination implements Destination<LastLocationDe
4745
if (!worldManager.isLoadedWorld(destinationParams)) {
4846
return Attempt.failure(InstanceFailureReason.WORLD_NOT_FOUND);
4947
}
50-
return Attempt.success(new LastLocationDestinationInstance(this, worldGroupManager, profileContainerStoreProvider, destinationParams));
48+
return Attempt.success(new LastLocationDestinationInstance(
49+
this,
50+
worldManager,
51+
worldGroupManager,
52+
profileContainerStoreProvider,
53+
destinationParams));
5154
}
5255

5356
@Override

src/main/java/org/mvplugins/multiverse/inventories/destination/LastLocationDestinationInstance.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.bukkit.entity.Player;
77
import org.bukkit.util.Vector;
88
import org.mvplugins.multiverse.core.destination.DestinationInstance;
9+
import org.mvplugins.multiverse.core.world.MultiverseWorld;
10+
import org.mvplugins.multiverse.core.world.WorldManager;
911
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1012
import org.mvplugins.multiverse.external.vavr.control.Option;
1113
import org.mvplugins.multiverse.inventories.profile.key.ContainerType;
@@ -15,48 +17,53 @@
1517

1618
public final class LastLocationDestinationInstance extends DestinationInstance<LastLocationDestinationInstance, LastLocationDestination> {
1719

20+
private final WorldManager worldManager;
1821
private final WorldGroupManager worldGroupManager;
1922
private final ProfileContainerStoreProvider profileContainerStoreProvider;
2023
private final String worldName;
2124

2225
LastLocationDestinationInstance(
2326
@NotNull LastLocationDestination destination,
27+
@NotNull WorldManager worldManager,
2428
@NotNull WorldGroupManager worldGroupManager,
2529
@NotNull ProfileContainerStoreProvider profileContainerStoreProvider,
2630
@NotNull String worldName) {
2731
super(destination);
32+
this.worldManager = worldManager;
2833
this.worldGroupManager = worldGroupManager;
2934
this.profileContainerStoreProvider = profileContainerStoreProvider;
3035
this.worldName = worldName;
3136
}
3237

3338
@Override
3439
public @NotNull Option<Location> getLocation(@NotNull Entity teleportee) {
35-
Logging.warning("LastLocationDestination: teleportee: " + teleportee);
40+
Logging.finer("LastLocationDestination: teleportee: " + teleportee);
3641
if (!(teleportee instanceof Player player)) {
37-
return Option.none();
42+
return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation);
3843
}
3944

4045
var playerWorld = player.getWorld().getName();
4146
if (playerWorld.equals(worldName)) {
42-
return Option.none();
47+
return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation);
4348
}
4449

4550
for (var group : worldGroupManager.getGroupsForWorld(worldName)) {
46-
Logging.warning("LastLocationDestination: group: " + group);
51+
Logging.finer("LastLocationDestination: group: " + group);
4752
if (!group.containsWorld(playerWorld) && group.getApplicableShares().contains(Sharables.LAST_LOCATION)) {
4853
return Option.of(profileContainerStoreProvider.getStore(ContainerType.GROUP)
4954
.getContainer(group.getName())
5055
.getPlayerProfileNow(player)
51-
.get(Sharables.LAST_LOCATION));
56+
.get(Sharables.LAST_LOCATION))
57+
.orElse(() -> worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation));
5258
}
5359
}
5460

5561
// Means last location isn't shared by any group, and will be read directly for world profile
5662
return Option.of(profileContainerStoreProvider.getStore(ContainerType.WORLD)
5763
.getContainer(worldName)
5864
.getPlayerProfileNow(player)
59-
.get(Sharables.LAST_LOCATION));
65+
.get(Sharables.LAST_LOCATION))
66+
.orElse(() -> worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation));
6067
}
6168

6269
@Override

0 commit comments

Comments
 (0)