Returns CompletableFuture<Location> instead of location, teleport when finished

This commit is contained in:
Yannick Lamprecht 2019-04-26 23:27:10 +02:00
parent 1c61ed2db7
commit 7de260d667
2 changed files with 15 additions and 20 deletions

View File

@ -37,15 +37,6 @@ import de.themoep.randomteleport.searcher.validators.LocationValidator;
import de.themoep.randomteleport.searcher.validators.ProtectionValidator;
import de.themoep.randomteleport.searcher.validators.WorldborderValidator;
import de.themoep.utils.lang.bukkit.LanguageManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
@ -57,9 +48,17 @@ import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
@ -369,13 +368,13 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
}
@Override
public Location getRandomLocation(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) throws ExecutionException, InterruptedException {
return getRandomSearcher(player, origin, minRange, maxRange, validators).search().get();
public CompletableFuture<Location> getRandomLocation(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) {
return getRandomSearcher(player, origin, minRange, maxRange, validators).search();
}
@Override
public void teleportToRandomLocation(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) throws ExecutionException, InterruptedException {
player.teleport(getRandomLocation(player, origin, minRange, maxRange, validators));
public void teleportToRandomLocation(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) {
getRandomLocation(player, origin, minRange, maxRange, validators).thenApply(player::teleport);
}
@Override

View File

@ -35,11 +35,9 @@ public interface RandomTeleportAPI {
* @param minRange the minimum distance a found location has to the center location
* @param maxRange the maximum distance a found location has to the center location
* @param validators additional LocationValidators to customize validity check of a location
* @return a random Location
* @throws ExecutionException see {@link CompletableFuture#get()}
* @throws InterruptedException see {@link CompletableFuture#get()}
* @return a random CompletableFuture<Location>
*/
Location getRandomLocation(Player player, Location center, int minRange, int maxRange, LocationValidator... validators) throws ExecutionException, InterruptedException;
CompletableFuture<Location> getRandomLocation(Player player, Location center, int minRange, int maxRange, LocationValidator... validators);
/**
* Teleports the passed Player to a random Location
@ -49,8 +47,6 @@ public interface RandomTeleportAPI {
* @param minRange the minimum distance a found location has to the center location
* @param maxRange the maximum distance a found location has to the center location
* @param validators additional LocationValidators to customize validity check of a location
* @throws ExecutionException see {@link CompletableFuture#get()}
* @throws InterruptedException see {@link CompletableFuture#get()}
*/
void teleportToRandomLocation(Player player, Location center, int minRange, int maxRange, LocationValidator... validators) throws ExecutionException, InterruptedException;