Skip to content

Commit

Permalink
Faster teleports (#2267)
Browse files Browse the repository at this point in the history
* Fixed bug with teleporting where home name would not be used.

* Remove debug
  • Loading branch information
tastybento authored Jan 11, 2024
1 parent 26e5d75 commit be9b429
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;

/**
* @author tastybento
Expand Down Expand Up @@ -76,23 +75,14 @@ public boolean execute(User user, String label, List<String> args) {
} else {
IslandInfo info = names.get(name);
getIslands().setPrimaryIsland(user.getUniqueId(), info.island);
if (info.islandName) {
this.delayCommand(user, () -> new SafeSpotTeleport.Builder(getPlugin())
.entity(user.getPlayer())
.location(getIslands().getHomeLocation(info.island))
.thenRun(() -> user.sendMessage("general.success"))
.build());
} else {
this.delayCommand(user, () -> new SafeSpotTeleport.Builder(getPlugin())
.entity(user.getPlayer())
.location(getIslands().getHomeLocation(info.island, name))
.thenRun(() -> user.sendMessage("general.success"))
.build());
if (!info.islandName) {
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer(), name)
.thenAccept((r) -> getIslands().setPrimaryIsland(user.getUniqueId(), info.island)));
return true;
}
}
} else {
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer()));
}
this.delayCommand(user, () -> getIslands().homeTeleportAsync(getWorld(), user.getPlayer()));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1721,9 +1721,10 @@ public Map<String, Location> getHomes() {
* @since 1.16.0
*/
@NonNull
public Location getHome(String name) {
Location l = getHomes().get(name.toLowerCase());
return l == null ? getProtectionCenter() : l;
public Location getHome(final String nameToLookFor) {
return getHomes().entrySet().stream().filter(en -> en.getKey().equalsIgnoreCase(nameToLookFor))
.map(Entry::getValue)
.findFirst().orElse(getProtectionCenter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ private CompletableFuture<Location> getAsyncSafeHomeLocation(@NonNull World worl
this.setPrimaryIsland(user.getUniqueId(), island);
return "";
}).orElse(homeName);

// Try the home location first
Location defaultHome = getHomeLocation(world, user);
Location namedHome = homeName.isBlank() ? null : getHomeLocation(world, user, name);
Expand Down Expand Up @@ -899,7 +898,8 @@ public Location getHomeLocation(@NonNull World world, @NonNull User user, String
*/
@Nullable
public Location getHomeLocation(@NonNull World world, @NonNull UUID uuid, String name) {
return getIslands(world, uuid).stream().map(is -> is.getHome(name)).filter(Objects::nonNull).findFirst()
return getIslands(world, uuid).stream().filter(is -> is.getHomes().containsKey(name))
.map(is -> is.getHome(name)).findFirst()
.orElse(null);
}

Expand Down

0 comments on commit be9b429

Please sign in to comment.