mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-01 04:51:27 +01:00
Teleport async on Paper.
This commit is contained in:
parent
cb2c0870ec
commit
056eaa6587
@ -181,9 +181,16 @@ public void resetFallDistance() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location location, String message) {
|
||||
public void teleport(Location location, String successMessage, String failMessage) {
|
||||
PaperLib.teleportAsync(getPlayer(), BukkitAdapter.adapt(location))
|
||||
.thenApply(success -> { if (success) print(message); return success; });
|
||||
.thenApply(success -> {
|
||||
if (success) {
|
||||
print(successMessage);
|
||||
} else {
|
||||
printError(failMessage);
|
||||
}
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -413,9 +413,8 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer).testMoveTo(localPlayer,
|
||||
BukkitAdapter.adapt(event.getTo()),
|
||||
MoveType.TELEPORT)) {
|
||||
if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer)
|
||||
.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.TELEPORT)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -212,4 +212,12 @@ default Association getAssociation(List<ProtectedRegion> regions) {
|
||||
* Clears fall distance.
|
||||
*/
|
||||
void resetFallDistance();
|
||||
|
||||
/**
|
||||
* Teleport the player, potentially async, displaying the message on a success.
|
||||
* @param location location to teleport to
|
||||
* @param successMessage message to display on success
|
||||
* @param failMessage message to display on failure
|
||||
*/
|
||||
void teleport(Location location, String successMessage, String failMessage);
|
||||
}
|
||||
|
@ -1091,8 +1091,9 @@ public void teleport(CommandContext args, Actor sender) throws CommandException
|
||||
}
|
||||
}
|
||||
|
||||
player.setLocation(teleportLocation);
|
||||
sender.print("Teleported you to the region '" + existing.getId() + "'.");
|
||||
player.teleport(teleportLocation,
|
||||
"Teleported you to the region '" + existing.getId() + "'.",
|
||||
"Unable to teleport to region '" + existing.getId() + "'.");
|
||||
}
|
||||
|
||||
private static class FlagListBuilder implements Callable<Component> {
|
||||
|
@ -183,6 +183,11 @@ public void resetFallDistance() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location location, String successMessage, String failMessage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
System.out.println("-> TestPlayer{" + this.name + "}: " + msg);
|
||||
|
@ -638,4 +638,11 @@ public void testGlobalRegionCommandBlacklistWithRegionWhitelist() {
|
||||
assertThat(test.apply("/deny"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionSetReturnsNullForUnsetState() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
mock.add(0);
|
||||
mock.add(1);
|
||||
assertNull(mock.getApplicableSet().queryState(null, Flags.INTERACT));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user