Fix y height and async chunk load errors
Also use the correct placeholder name for the world
This commit is contained in:
parent
8fe13fa16d
commit
2ae3593687
|
@ -28,6 +28,7 @@ import de.themoep.randomteleport.searcher.options.SimpleOptionParser;
|
|||
import de.themoep.randomteleport.searcher.options.WorldNotFoundException;
|
||||
import de.themoep.randomteleport.searcher.validators.BiomeValidator;
|
||||
import de.themoep.randomteleport.searcher.validators.BlockValidator;
|
||||
import de.themoep.randomteleport.searcher.validators.HeightValidator;
|
||||
import de.themoep.randomteleport.searcher.validators.ProtectionValidator;
|
||||
import de.themoep.randomteleport.searcher.validators.WorldborderValidator;
|
||||
import de.themoep.utils.lang.bukkit.LanguageManager;
|
||||
|
@ -188,6 +189,7 @@ public class RandomTeleport extends JavaPlugin {
|
|||
|
||||
private void initValidators() {
|
||||
locationValidators.add(new WorldborderValidator());
|
||||
locationValidators.add(new HeightValidator());
|
||||
locationValidators.add(new ProtectionValidator());
|
||||
locationValidators.add(new BlockValidator(saveBlocks));
|
||||
}
|
||||
|
@ -259,12 +261,12 @@ public class RandomTeleport extends JavaPlugin {
|
|||
parser.parse(searcher, optionArgs);
|
||||
}
|
||||
|
||||
searcher.getTargets().forEach(e -> sendMessage(e, "search", "world", searcher.getCenter().getWorld().getName()));
|
||||
searcher.getTargets().forEach(e -> sendMessage(e, "search", "worldname", searcher.getCenter().getWorld().getName()));
|
||||
searcher.search().thenApply(targetLoc -> {
|
||||
searcher.getTargets().forEach(e -> {
|
||||
e.teleport(targetLoc);
|
||||
sendMessage(e, "teleport",
|
||||
"world", center.getWorld().getName(),
|
||||
"worldname", center.getWorld().getName(),
|
||||
"x", String.valueOf(center.getBlockX()),
|
||||
"y", String.valueOf(center.getBlockY()),
|
||||
"z", String.valueOf(center.getBlockZ())
|
||||
|
|
|
@ -204,7 +204,7 @@ public class RandomSearcher {
|
|||
*/
|
||||
public CompletableFuture<Location> search() {
|
||||
future = new CompletableFuture<>();
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> checkRandom(future));
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> checkRandom(future));
|
||||
return future;
|
||||
}
|
||||
|
||||
|
@ -218,9 +218,9 @@ public class RandomSearcher {
|
|||
}
|
||||
Location randomLoc = new Location(
|
||||
center.getWorld(),
|
||||
center.getBlockX() + random.nextInt(maxRadius - minRadius),
|
||||
center.getBlockX() + (random.nextBoolean() ? 1 : -1) * (minRadius + random.nextInt(maxRadius - minRadius)),
|
||||
0,
|
||||
center.getBlockX() + random.nextInt(maxRadius - minRadius)
|
||||
center.getBlockX() + (random.nextBoolean() ? 1 : -1) * (minRadius + random.nextInt(maxRadius - minRadius))
|
||||
);
|
||||
PaperLib.getChunkAtAsync(randomLoc, generatedOnly).thenApply(c -> {
|
||||
checks++;
|
||||
|
@ -232,7 +232,7 @@ public class RandomSearcher {
|
|||
}
|
||||
future.complete(randomLoc);
|
||||
return true;
|
||||
});
|
||||
}).exceptionally(future::completeExceptionally);
|
||||
}
|
||||
|
||||
public RandomTeleport getPlugin() {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package de.themoep.randomteleport.searcher.validators;
|
||||
|
||||
/*
|
||||
* RandomTeleport - randomteleport-plugin - $project.description
|
||||
* Copyright (c) 2019 Max Lee aka Phoenix616 (mail@moep.tv)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import de.themoep.randomteleport.searcher.RandomSearcher;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public class HeightValidator extends LocationValidator {
|
||||
|
||||
public HeightValidator() {
|
||||
super("height");
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue