Teleport async on Paper.

This commit is contained in:
wizjany 2019-09-13 16:42:35 -04:00
parent cb2c0870ec
commit 056eaa6587
6 changed files with 34 additions and 7 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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> {

View File

@ -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);

View File

@ -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));
}
}