Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.mvplugins.multiverse.inventories.destination;

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.units.qual.N;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.destination.Destination;
import org.mvplugins.multiverse.core.destination.DestinationSuggestionPacket;
Expand Down Expand Up @@ -47,7 +45,12 @@ public final class LastLocationDestination implements Destination<LastLocationDe
if (!worldManager.isLoadedWorld(destinationParams)) {
return Attempt.failure(InstanceFailureReason.WORLD_NOT_FOUND);
}
return Attempt.success(new LastLocationDestinationInstance(this, worldGroupManager, profileContainerStoreProvider, destinationParams));
return Attempt.success(new LastLocationDestinationInstance(
this,
worldManager,
worldGroupManager,
profileContainerStoreProvider,
destinationParams));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.vavr.control.Option;
import org.mvplugins.multiverse.inventories.profile.key.ContainerType;
Expand All @@ -15,48 +17,53 @@

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

private final WorldManager worldManager;
private final WorldGroupManager worldGroupManager;
private final ProfileContainerStoreProvider profileContainerStoreProvider;
private final String worldName;

LastLocationDestinationInstance(
@NotNull LastLocationDestination destination,
@NotNull WorldManager worldManager,
@NotNull WorldGroupManager worldGroupManager,
@NotNull ProfileContainerStoreProvider profileContainerStoreProvider,
@NotNull String worldName) {
super(destination);
this.worldManager = worldManager;
this.worldGroupManager = worldGroupManager;
this.profileContainerStoreProvider = profileContainerStoreProvider;
this.worldName = worldName;
}

@Override
public @NotNull Option<Location> getLocation(@NotNull Entity teleportee) {
Logging.warning("LastLocationDestination: teleportee: " + teleportee);
Logging.finer("LastLocationDestination: teleportee: " + teleportee);
if (!(teleportee instanceof Player player)) {
return Option.none();
return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation);
}

var playerWorld = player.getWorld().getName();
if (playerWorld.equals(worldName)) {
return Option.none();
return worldManager.getLoadedWorld(worldName).map(MultiverseWorld::getSpawnLocation);
}

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

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

@Override
Expand Down
Loading