Skip to content

Commit

Permalink
Add a check if location is not outside protected area.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Feb 20, 2021
1 parent ebc6a3e commit 7d44bdf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/main/java/world/bentobox/visit/managers/VisitAddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import org.bukkit.util.Vector;
import java.util.*;

import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.metadata.MetaDataValue;
Expand Down Expand Up @@ -319,20 +317,24 @@ else if (earnedMoney > 0 &&
{
Location location = island.getSpawnPoint(World.Environment.NORMAL);

if (location == null || !this.addon.getIslands().isSafeLocation(location))
// There is a possibility that location may be out of protected area. These locations should
// not be valid for teleporting.
if (location != null &&
island.getProtectionBoundingBox().contains(location.toVector()) &&
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.getProtectionCenter() : location).
failureMessage(user.getTranslation("general.errors.no-safe-location-found")).
build();
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(), location);
}
else
{
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(), 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.getProtectionCenter() : location).
failureMessage(user.getTranslation("general.errors.no-safe-location-found")).
build();
}
}
}
Expand Down

0 comments on commit 7d44bdf

Please sign in to comment.