mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-25 20:15:55 +01:00
Fix cooldown, y location calculator and teleport target
This commit is contained in:
parent
f0f014cc23
commit
5f73ccc955
@ -308,12 +308,13 @@ public class RandomTeleport extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
if (cooldown > 0) {
|
||||
sendMessage(searcher.getTargets(), "error.cooldown", "cooldown_text", cooldown + "s");
|
||||
if (cooldown > 0 && cooldown < searcher.getCooldown()) {
|
||||
sendMessage(searcher.getTargets(), "error.cooldown", "cooldown_text", (searcher.getCooldown() - cooldown) + "s");
|
||||
return null;
|
||||
}
|
||||
sendMessage(searcher.getTargets(), "search", "worldname", searcher.getCenter().getWorld().getName());
|
||||
searcher.search().thenApply(targetLoc -> {
|
||||
targetLoc.add(0, 1, 0);
|
||||
searcher.getTargets().forEach(e -> {
|
||||
cooldowns.put(searcher.getId(), e.getUniqueId(), new AbstractMap.SimpleImmutableEntry<>(System.currentTimeMillis(), searcher.getCooldown()));
|
||||
e.teleport(targetLoc);
|
||||
|
@ -31,8 +31,14 @@ public class HeightValidator extends LocationValidator {
|
||||
|
||||
@Override
|
||||
public boolean validate(RandomSearcher searcher, Location location) {
|
||||
location.setY(location.getWorld().getHighestBlockYAt(location));
|
||||
Block block = location.getBlock();
|
||||
return !block.isEmpty() && !block.getRelative(BlockFace.UP).getType().isSolid() && !block.getRelative(BlockFace.UP, 2).getType().isSolid();
|
||||
Block block = location.getWorld().getHighestBlockAt(location);
|
||||
while (block.isEmpty()) {
|
||||
block = block.getRelative(BlockFace.DOWN);
|
||||
if (block == null || block.getY() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
location.setY(block.getY());
|
||||
return !block.getRelative(BlockFace.UP).getType().isSolid() && !block.getRelative(BlockFace.UP, 2).getType().isSolid();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user