Teleport async and send message on fail to fix issues with world changes

This commit is contained in:
Phoenix616 2020-07-20 17:35:29 +01:00
parent 0cf2f0a28a
commit 952feb83f9
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 24 additions and 12 deletions

View File

@ -37,6 +37,7 @@ 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 io.papermc.lib.PaperLib;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -374,24 +375,34 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
targetLoc.setX(targetLoc.getBlockX() + 0.5);
targetLoc.setY(targetLoc.getY() + 0.1);
targetLoc.setZ(targetLoc.getBlockZ() + 0.5);
e.teleport(targetLoc);
sendMessage(e, "teleport",
"worldname", targetLoc.getWorld().getName(),
"x", String.valueOf(targetLoc.getBlockX()),
"y", String.valueOf(targetLoc.getBlockY()),
"z", String.valueOf(targetLoc.getBlockZ())
);
if (searcher.getOptions().containsKey("spawnpoint") && e instanceof Player) {
if (((Player) e).getBedSpawnLocation() == null || "force".equalsIgnoreCase(searcher.getOptions().get("spawnpoint"))){
((Player) e).setBedSpawnLocation(targetLoc, true);
sendMessage(e, "setspawnpoint",
PaperLib.teleportAsync(e, targetLoc).thenAccept(success -> {
if (success) {
sendMessage(e, "teleport",
"worldname", targetLoc.getWorld().getName(),
"x", String.valueOf(targetLoc.getBlockX()),
"y", String.valueOf(targetLoc.getBlockY()),
"z", String.valueOf(targetLoc.getBlockZ())
);
if (searcher.getOptions().containsKey("spawnpoint") && e instanceof Player) {
if (((Player) e).getBedSpawnLocation() == null || "force".equalsIgnoreCase(searcher.getOptions().get("spawnpoint"))) {
((Player) e).setBedSpawnLocation(targetLoc, true);
sendMessage(e, "setspawnpoint",
"worldname", targetLoc.getWorld().getName(),
"x", String.valueOf(targetLoc.getBlockX()),
"y", String.valueOf(targetLoc.getBlockY()),
"z", String.valueOf(targetLoc.getBlockZ())
);
}
}
} else {
sendMessage(e, "error.teleport",
"worldname", targetLoc.getWorld().getName(),
"x", String.valueOf(targetLoc.getBlockX()),
"y", String.valueOf(targetLoc.getBlockY()),
"z", String.valueOf(targetLoc.getBlockZ())
);
}
}
});
});
return true;
}).exceptionally(ex -> {

View File

@ -11,6 +11,7 @@ sign:
use: "&cYou don't have permission to use the preset &6{preset}&c! &o({perm})"
error:
location: "&4Error: &cRandomTeleport could not find a safe location!"
teleport: "&4Error: &cRandomTeleport could not teleport you to X: {x} Y: {y} Z: {z}!"
cooldown: "&cYou have to wait {cooldown_text} before using this RandomTeleport again!"
parse-error: "&cError while parsing option &f{option}&c with value &f{value}&c: {error}"
not-found: "&cCould not find &f{what}&c!"