Skip to content

Commit

Permalink
Add protection against being teleported into bad location.
Browse files Browse the repository at this point in the history
Suggested by Tasty :)
  • Loading branch information
BONNe committed Jun 19, 2020
1 parent 4c58322 commit 7010072
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main/java/world/bentobox/visit/managers/VisitAddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.eclipse.jdt.annotation.NonNull;
import java.util.*;
Expand All @@ -11,6 +12,7 @@
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
import world.bentobox.visit.VisitAddon;
import world.bentobox.visit.database.object.IslandVisitSettings;
import world.bentobox.visit.events.VisitEvent;
Expand Down Expand Up @@ -413,9 +415,23 @@ else if (settings.getPayment() > 0 && !this.depositCredits(User.getInstance(isla
// If event is not cancelled, then teleport player.
if (!event.isCancelled())
{
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(),
Objects.requireNonNull(island.getSpawnPoint(World.Environment.NORMAL)));
Location location = island.getSpawnPoint(World.Environment.NORMAL);

if (location == null || !this.addon.getIslands().isSafeLocation(location))
{
// Use SafeSpotTeleport builder to avoid issues with players spawning in
// bad spot.
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
entity(user.getPlayer()).
location(location == null ? island.getCenter() : location).
failureMessage(user.getTranslation("general.errors.no-safe-location-found")).
build();
}
else
{
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(), location);
}
}
}
}
Expand Down

0 comments on commit 7010072

Please sign in to comment.