Fix cooldown, y location calculator and teleport target

This commit is contained in:
Phoenix616 2019-04-12 22:38:42 +01:00
parent f0f014cc23
commit 5f73ccc955
2 changed files with 12 additions and 5 deletions

View File

@ -308,12 +308,13 @@ public class RandomTeleport extends JavaPlugin {
} }
} }
if (cooldown > 0) { if (cooldown > 0 && cooldown < searcher.getCooldown()) {
sendMessage(searcher.getTargets(), "error.cooldown", "cooldown_text", cooldown + "s"); sendMessage(searcher.getTargets(), "error.cooldown", "cooldown_text", (searcher.getCooldown() - cooldown) + "s");
return null; return null;
} }
sendMessage(searcher.getTargets(), "search", "worldname", searcher.getCenter().getWorld().getName()); sendMessage(searcher.getTargets(), "search", "worldname", searcher.getCenter().getWorld().getName());
searcher.search().thenApply(targetLoc -> { searcher.search().thenApply(targetLoc -> {
targetLoc.add(0, 1, 0);
searcher.getTargets().forEach(e -> { searcher.getTargets().forEach(e -> {
cooldowns.put(searcher.getId(), e.getUniqueId(), new AbstractMap.SimpleImmutableEntry<>(System.currentTimeMillis(), searcher.getCooldown())); cooldowns.put(searcher.getId(), e.getUniqueId(), new AbstractMap.SimpleImmutableEntry<>(System.currentTimeMillis(), searcher.getCooldown()));
e.teleport(targetLoc); e.teleport(targetLoc);

View File

@ -31,8 +31,14 @@ public class HeightValidator extends LocationValidator {
@Override @Override
public boolean validate(RandomSearcher searcher, Location location) { public boolean validate(RandomSearcher searcher, Location location) {
location.setY(location.getWorld().getHighestBlockYAt(location)); Block block = location.getWorld().getHighestBlockAt(location);
Block block = location.getBlock(); while (block.isEmpty()) {
return !block.isEmpty() && !block.getRelative(BlockFace.UP).getType().isSolid() && !block.getRelative(BlockFace.UP, 2).getType().isSolid(); 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();
} }
} }