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

View File

@ -11,6 +11,7 @@ sign:
use: "&cYou don't have permission to use the preset &6{preset}&c! &o({perm})" use: "&cYou don't have permission to use the preset &6{preset}&c! &o({perm})"
error: error:
location: "&4Error: &cRandomTeleport could not find a safe location!" 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!" 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}" parse-error: "&cError while parsing option &f{option}&c with value &f{value}&c: {error}"
not-found: "&cCould not find &f{what}&c!" not-found: "&cCould not find &f{what}&c!"