Skip to content
Permalink
Browse files

Teleport async on Paper.

  • Loading branch information...
wizjany committed Sep 13, 2019
1 parent cb2c087 commit 056eaa65870e208e2f868492eff4a67ec251df30
@@ -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));
}
}

0 comments on commit 056eaa6

Please sign in to comment.
You can’t perform that action at this time.