mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-22 02:25:38 +01:00
Teleport async and send message on fail to fix issues with world changes
This commit is contained in:
parent
0cf2f0a28a
commit
952feb83f9
@ -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 -> {
|
||||
|
@ -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!"
|
||||
|
Loading…
Reference in New Issue
Block a user