TeleportResult refactor, use record and bundle resolved information, separate TeleportState enum, deprecate relevant API

This commit is contained in:
William committed 2022-10-19 01:12:19 +01:00
1 parent 82d47f0878
commit 4164f07841
12 files changed
+285 -151

No files matched your search

@@ -86,7 +86,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
teleportFuture.thenAccept(teleport -> teleport.execute()
.thenAccept(result -> {
if (isExecutorTeleporting &&
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
result.successful() && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
plugin.getDatabase().updateUserData(new UserData(onlineUser,
userData.get().homeSlots(), userData.get().ignoringTeleports(),
Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES)));
@@ -118,7 +118,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
.setTarget(position.get())
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful) {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Teleported " + foundUser.get().username + " to a random position.");
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().username + " to a random position.");
@@ -69,9 +69,10 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
.setTarget(targetPlayer.playerName)
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful) {
plugin.getLocales().getLocale("teleporting_other_complete",
playerToTeleport, targetPlayer.playerName)
if (result.successful()) {
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete",
teleporter.username, targetPlayer.playerName))
.ifPresent(onlineUser::sendMessage);
} else {
plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName)
@@ -91,14 +92,16 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
.setTarget(targetPosition.position)
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (!result.successful || playerToTeleport.equalsIgnoreCase(onlineUser.username)) {
if (!result.successful() || playerToTeleport.equalsIgnoreCase(onlineUser.username) || result.getDestination().isEmpty()) {
return;
}
plugin.getLocales().getLocale("teleporting_other_complete_position",
playerToTeleport,
Integer.toString((int) targetPosition.position.x),
Integer.toString((int) targetPosition.position.y),
Integer.toString((int) targetPosition.position.z))
final Position destination = result.getDestination().get();
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales()
.getLocale("teleporting_other_complete", teleporter.username,
Integer.toString((int) destination.x),
Integer.toString((int) destination.y),
Integer.toString((int) destination.z)))
.ifPresent(onlineUser::sendMessage);
}));
}
@@ -187,7 +190,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
builder.setTarget(((TargetPosition) teleportTarget).position);
}
builder.toTeleport().thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful) {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.username + " to " + teleportTarget);
@@ -32,9 +32,10 @@ public class TpHereCommand extends CommandBase implements TabCompletable {
.setTarget(onlineUser.getPosition())
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful) {
plugin.getLocales().getLocale("teleporting_other_complete",
targetPlayerName, onlineUser.username)
if (result.successful()) {
result.getTeleporter()
.flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete",
teleporter.username, onlineUser.username))
.ifPresent(onlineUser::sendMessage);
}
}));
@@ -43,7 +43,7 @@ public class TpOfflineCommand extends CommandBase implements TabCompletable {
.setTarget(offlinePosition.get())
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful) {
if (result.successful()) {
plugin.getLocales().getLocale("teleporting_offline_complete", targetUser)
.ifPresent(onlineUser::sendMessage);
}