diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java index 8e51c1bd..38c5894a 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java @@ -21,6 +21,7 @@ public enum BukkitCommandType { DEL_WARP_COMMAND(new DelWarpCommand(BukkitHuskHomes.getInstance())), EDIT_WARP_COMMAND(new EditWarpCommand(BukkitHuskHomes.getInstance())), TP_COMMAND(new TpCommand(BukkitHuskHomes.getInstance())), + TP_HERE_COMMAND(new TpHereCommand(BukkitHuskHomes.getInstance())), BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance())); public final CommandBase commandBase; diff --git a/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java b/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java index 8ea8a09d..cc828413 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java +++ b/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java @@ -106,13 +106,13 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi } @Override - protected CompletableFuture sendReply(@NotNull OnlineUser replier, @NotNull Message reply) { - return sendPluginMessage((BukkitPlayer) replier, reply); + protected void sendReply(@NotNull OnlineUser replier, @NotNull Message reply) { + sendPluginMessage((BukkitPlayer) replier, reply); } @SuppressWarnings("UnstableApiUsage") - private CompletableFuture sendPluginMessage(@NotNull BukkitPlayer player, @NotNull Message message) { - return CompletableFuture.runAsync(() -> { + private void sendPluginMessage(@NotNull BukkitPlayer player, @NotNull Message message) { + CompletableFuture.runAsync(() -> { final ByteArrayDataOutput messageWriter = ByteStreams.newDataOutput(); messageWriter.writeUTF("ForwardToPlayer"); messageWriter.writeUTF(message.targetPlayer); diff --git a/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java b/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java index f6a7e746..51dc99f1 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java +++ b/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java @@ -61,8 +61,8 @@ public class RedisMessenger extends PluginMessenger { } @Override - protected CompletableFuture sendReply(@NotNull OnlineUser replier, @NotNull Message reply) { - return redisWorker.sendMessage(reply); + protected void sendReply(@NotNull OnlineUser replier, @NotNull Message reply) { + redisWorker.sendMessage(reply); } @Override diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 9905e1b4..b318c28c 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -40,7 +40,10 @@ commands: editwarp: usage: /editwarp [rename|description|relocate] [args] tp: - usage: /tp + usage: /tp [destination] aliases: [tpo] + tphere: + usage: /tphere + aliases: [tpohere] back: usage: /back \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/command/BackCommand.java b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java index 684515b7..9e9f6d9a 100644 --- a/common/src/main/java/net/william278/huskhomes/command/BackCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java @@ -2,7 +2,6 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.OnlineUser; -import net.william278.huskhomes.player.User; import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; @@ -15,7 +14,7 @@ public class BackCommand extends CommandBase { @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { plugin.getDatabase().getLastPosition(onlineUser).thenAccept(lastPosition -> - lastPosition.ifPresentOrElse(position -> plugin.getTeleportManager().teleport(onlineUser, position) + lastPosition.ifPresentOrElse(position -> plugin.getTeleportManager().timedTeleport(onlineUser, position) .thenAccept(result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)), () -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(onlineUser::sendMessage))); } diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java index 73af4148..cd692c94 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java @@ -23,7 +23,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE // Send the home list if they have homes set. If they have just one home set, teleport the player switch (homes.size()) { case 0 -> plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage); - case 1 -> plugin.getTeleportManager().teleport(onlineUser, homes.get(0)).thenAccept(result -> + case 1 -> plugin.getTeleportManager().timedTeleport(onlineUser, homes.get(0)).thenAccept(result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)).join(); default -> onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, onlineUser, plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage,1)); @@ -35,10 +35,10 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse( homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()) .thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse( - userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), homeIdentifier.homeName()), + userData -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, userData.user(), homeIdentifier.homeName()), () -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()) .ifPresent(onlineUser::sendMessage))), - () -> plugin.getTeleportManager().teleportToHome(onlineUser, onlineUser, homeName)); + () -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, onlineUser, homeName)); } default -> plugin.getLocales().getLocale("error_invalid_syntax", "/home [name]") .ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java index 5e802b95..eefa1a0b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java @@ -38,7 +38,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse( homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()) .thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse( - userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), homeIdentifier.homeName()), + userData -> plugin.getTeleportManager().teleportToHomeByName(onlineUser, userData.user(), homeIdentifier.homeName()), () -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()) .ifPresent(onlineUser::sendMessage))), () -> plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> { diff --git a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java index ad4ba3a8..05f6d219 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java @@ -22,7 +22,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - OnlineUser userToTeleport = onlineUser; + String teleportingUserName = onlineUser.username; TeleportCommandTarget targetPosition; // Validate argument length @@ -40,13 +40,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe int coordinatesIndex = ((args.length > 3 && (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3]))) || (args.length == 2)) ? 1 : 0; if (coordinatesIndex == 1) { - userToTeleport = plugin.getOnlinePlayers().stream().filter(user -> user.username.equalsIgnoreCase(args[0])) - .findFirst().orElse(plugin.getOnlinePlayers().stream().filter(user -> user.username.startsWith(args[0])) - .findFirst().orElse(null)); - if (userToTeleport == null) { - plugin.getLocales().getLocale("error_player_not_found", args[0]).ifPresent(onlineUser::sendMessage); - return; - } + teleportingUserName = args[0]; } // Determine the target position (player or coordinates) @@ -73,15 +67,25 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe } // Execute the teleport - final OnlineUser teleportingUser = userToTeleport; + final String playerToTeleportName = teleportingUserName; if (targetPosition.targetType == TeleportCommandTarget.TargetType.PLAYER) { + // Teleport players by usernames assert targetPosition.targetPlayer != null; - CompletableFuture.runAsync(() -> plugin.getTeleportManager().teleportToPlayer(teleportingUser, targetPosition.targetPlayer)); + CompletableFuture.runAsync(() -> plugin.getTeleportManager() + .teleportPlayerToPlayerByName(playerToTeleportName, targetPosition.targetPlayer, onlineUser) + .thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse( + result -> plugin.getTeleportManager().finishTeleport(onlineUser, result), + () -> plugin.getLocales().getLocale("error_player_not_found", playerToTeleportName) + .ifPresent(onlineUser::sendMessage)))); return; } else if (targetPosition.targetType == TeleportCommandTarget.TargetType.POSITION) { + // Teleport players by specified position assert targetPosition.targetPosition != null; - plugin.getTeleportManager().teleport(teleportingUser, targetPosition.targetPosition).thenAccept( - result -> plugin.getTeleportManager().finishTeleport(teleportingUser, result)); + plugin.getTeleportManager().teleportPlayerByName(playerToTeleportName, targetPosition.targetPosition, onlineUser) + .thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse( + result -> plugin.getTeleportManager().finishTeleport(onlineUser, result), + () -> plugin.getLocales().getLocale("error_player_not_found", playerToTeleportName) + .ifPresent(onlineUser::sendMessage))); return; } throw new HuskHomesException("Attempted to execute invalid teleport command operation"); diff --git a/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java new file mode 100644 index 00000000..c66ed08f --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java @@ -0,0 +1,34 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.player.OnlineUser; +import net.william278.huskhomes.util.Permission; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class TpHereCommand extends CommandBase implements TabCompletable { + + protected TpHereCommand(@NotNull HuskHomes implementor) { + super("tphere", Permission.COMMAND_TPHERE, implementor, "tpohere"); + } + + @Override + public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + if (args.length != 1) { + plugin.getLocales().getLocale("error_invalid_syntax", "/tphere ") + .ifPresent(onlineUser::sendMessage); + return; + } + plugin.getTeleportManager().teleportPlayerByName(args[0], onlineUser.getPosition().join(), onlineUser); + } + + @Override + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + return args.length <= 1 ? plugin.getCache().players.stream() + .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) + .sorted().collect(Collectors.toList()) : Collections.emptyList(); + } +} diff --git a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java index 193f3033..42f3cc92 100644 --- a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java @@ -27,7 +27,7 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE }); case 1 -> { final String warpName = args[0]; - plugin.getTeleportManager().teleportToWarp(onlineUser, warpName); + plugin.getTeleportManager().teleportToWarpByName(onlineUser, warpName); } default -> plugin.getLocales().getLocale("error_invalid_syntax", "/warp [name]") .ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/messenger/Message.java b/common/src/main/java/net/william278/huskhomes/messenger/Message.java index 33be0566..7fe468cd 100644 --- a/common/src/main/java/net/william278/huskhomes/messenger/Message.java +++ b/common/src/main/java/net/william278/huskhomes/messenger/Message.java @@ -82,6 +82,7 @@ public class Message { */ public enum MessageType { TP_REQUEST, + TP_TO_POSITION_REQUEST, POSITION_REQUEST } diff --git a/common/src/main/java/net/william278/huskhomes/messenger/MessagePayload.java b/common/src/main/java/net/william278/huskhomes/messenger/MessagePayload.java index 28412f14..9614aeb5 100644 --- a/common/src/main/java/net/william278/huskhomes/messenger/MessagePayload.java +++ b/common/src/main/java/net/william278/huskhomes/messenger/MessagePayload.java @@ -1,6 +1,8 @@ package net.william278.huskhomes.messenger; +import com.google.gson.annotations.SerializedName; import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.teleport.TeleportResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,6 +17,13 @@ public class MessagePayload { @Nullable public Position position; + /** + * A teleport result field + */ + @Nullable + @SerializedName("teleport_result") + public TeleportResult teleportResult; + /** * Returns an empty cross-server message payload * @@ -38,6 +47,19 @@ public class MessagePayload { return payload; } + /** + * Returns a payload containing a {@link TeleportResult} + * + * @param teleportResult the teleport to send + * @return a payload containing the teleport result + */ + @NotNull + public static MessagePayload withTeleportResult(@NotNull TeleportResult teleportResult) { + final MessagePayload payload = new MessagePayload(); + payload.teleportResult = teleportResult; + return payload; + } + private MessagePayload() { } diff --git a/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java b/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java index 19d2bf14..9f9fe8f7 100644 --- a/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java +++ b/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java @@ -42,6 +42,11 @@ public abstract class NetworkMessenger { */ protected String clusterId; + /** + * The implementing HuskHomes plugin instance + */ + private HuskHomes plugin; + /** * Initialize the network messenger * @@ -50,6 +55,7 @@ public abstract class NetworkMessenger { public void initialize(@NotNull HuskHomes implementor) { this.processingMessages = new HashMap<>(); this.clusterId = implementor.getSettings().clusterId; + this.plugin = implementor; } /** @@ -97,9 +103,8 @@ public abstract class NetworkMessenger { * Send a reply to a received {@link Message} * * @param reply The reply {@link Message} to send - * @return A future completing when the message has been sent */ - protected abstract CompletableFuture sendReply(@NotNull OnlineUser replier, @NotNull Message reply); + protected abstract void sendReply(@NotNull OnlineUser replier, @NotNull Message reply); /** * Handle and action received network {@link Message}s @@ -128,6 +133,14 @@ public abstract class NetworkMessenger { case TP_REQUEST -> { //todo } + case TP_TO_POSITION_REQUEST -> { + if (message.payload.position != null) { + message.payload = MessagePayload.withTeleportResult(plugin.getTeleportManager() + .teleport(receiver, message.payload.position).join()); + } else { + message.payload = MessagePayload.empty(); + } + } case POSITION_REQUEST -> message.payload = MessagePayload.withPosition(receiver.getPosition().join()); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java index 29efee2e..c2bcf31f 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java @@ -48,7 +48,7 @@ public class TeleportManager { * @param homeOwner the {@link User} who owns the home * @param homeName the name of the home */ - public void teleportToHome(@NotNull OnlineUser onlineUser, @NotNull User homeOwner, @NotNull String homeName) { + public void teleportToHomeByName(@NotNull OnlineUser onlineUser, @NotNull User homeOwner, @NotNull String homeName) { plugin.getDatabase().getHome(homeOwner, homeName).thenAccept(optionalHome -> optionalHome.ifPresentOrElse(home -> teleportToHome(onlineUser, home), () -> { if (homeOwner.uuid.equals(onlineUser.uuid)) { @@ -73,7 +73,7 @@ public class TeleportManager { return; } } - teleport(onlineUser, home).thenAccept(result -> finishTeleport(onlineUser, result)); + timedTeleport(onlineUser, home).thenAccept(result -> finishTeleport(onlineUser, result)); } /** @@ -82,7 +82,7 @@ public class TeleportManager { * @param onlineUser the {@link OnlineUser} to teleport * @param warpName the name of the warp */ - public void teleportToWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) { + public void teleportToWarpByName(@NotNull OnlineUser onlineUser, @NotNull String warpName) { plugin.getDatabase().getWarp(warpName).thenAccept(optionalWarp -> optionalWarp.ifPresentOrElse(warp -> //todo permission restricted warps teleportToWarp(onlineUser, warp), () -> @@ -97,26 +97,85 @@ public class TeleportManager { * @param warp the {@link Warp} to teleport to */ public void teleportToWarp(@NotNull OnlineUser onlineUser, @NotNull Warp warp) { - teleport(onlineUser, warp).thenAccept(result -> finishTeleport(onlineUser, result)); + timedTeleport(onlineUser, warp).thenAccept(result -> finishTeleport(onlineUser, result)); } /** - * Teleport a {@link OnlineUser} to another player by given input name + * Teleport a {@link OnlineUser} to another player by username * * @param onlineUser the {@link OnlineUser} to teleport * @param targetPlayer the name of the target player */ - public void teleportToPlayer(@NotNull OnlineUser onlineUser, @NotNull String targetPlayer) { + public void teleportToPlayerByName(@NotNull OnlineUser onlineUser, @NotNull String targetPlayer) { MatcherUtil.matchPlayerName(targetPlayer, plugin).ifPresentOrElse(playerName -> - getPlayerPosition(onlineUser, playerName).thenAccept(optionalPosition -> + getPlayerPositionByName(onlineUser, playerName).thenAccept(optionalPosition -> optionalPosition.ifPresentOrElse(targetPosition -> - teleport(onlineUser, targetPosition).thenAccept(result -> + timedTeleport(onlineUser, targetPosition).thenAccept(result -> finishTeleport(onlineUser, result)), () -> plugin.getLocales().getLocale("error_invalid_player"). ifPresent(onlineUser::sendMessage))), () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage)); } + /** + * Immediately teleport a player by username to a {@link Position} by name + * + * @param playerName username of the target player to teleport + * @param position the {@link Position} to teleport to + * @param requester the {@link OnlineUser} performing the teleport action + * @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult}, + * if it was processed, otherwise an empty {@link Optional} if the player was not found + */ + public CompletableFuture> teleportPlayerByName(@NotNull String playerName, @NotNull Position position, + @NotNull OnlineUser requester) { + final Optional localPlayer = plugin.getOnlinePlayers().stream().filter(player -> + player.username.equalsIgnoreCase(playerName)).findFirst(); + if (localPlayer.isPresent()) { + return teleport(localPlayer.get(), position).thenApply(Optional::of); + } + if (plugin.getSettings().crossServer) { + assert plugin.getNetworkMessenger() != null; + return plugin.getNetworkMessenger().sendMessage(requester, + new Message(Message.MessageType.TP_TO_POSITION_REQUEST, + requester.username, + playerName, + MessagePayload.withPosition(position), + Message.RelayType.MESSAGE, + plugin.getSettings().clusterId)) + .thenApply(result -> { + if (result.payload.teleportResult == null) { + return Optional.empty(); + } + return Optional.of(result.payload.teleportResult); + }); + } + return CompletableFuture.supplyAsync(Optional::empty); + } + + /** + * Teleport two players by username + * + * @param playerName the name of the player to teleport + * @param targetPlayer the name of the target player + * @param requester the {@link OnlineUser} performing the teleport action + * @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult}, + */ + public CompletableFuture> teleportPlayerToPlayerByName(@NotNull String playerName, + @NotNull String targetPlayer, + @NotNull OnlineUser requester) { + final Optional localPositionTarget = plugin.getOnlinePlayers().stream().filter(player -> + player.username.equalsIgnoreCase(targetPlayer)).findFirst().map(user -> user.getPosition().join()); + if (localPositionTarget.isPresent()) { + return teleportPlayerByName(playerName, localPositionTarget.get(), requester); + } + return getPlayerPositionByName(requester, targetPlayer).thenApply(position -> { + if (position.isEmpty()) { + return Optional.empty(); + } + return teleportPlayerByName(playerName, position.get(), requester).join(); + }); + } + /** * Gets the position of a player by their username, including players on other servers * @@ -124,7 +183,7 @@ public class TeleportManager { * @param playerName the username of the player being requested * @return future optionally supplying the player's position, if the player could be found */ - private CompletableFuture> getPlayerPosition(@NotNull OnlineUser requester, @NotNull String playerName) { + private CompletableFuture> getPlayerPositionByName(@NotNull OnlineUser requester, @NotNull String playerName) { final Optional localPlayer = plugin.getOnlinePlayers().stream().filter(player -> player.username.equalsIgnoreCase(playerName)).findFirst(); if (localPlayer.isPresent()) { @@ -145,12 +204,12 @@ public class TeleportManager { } /** - * Teleport a {@link OnlineUser} to a specified {@link Position}. Respects timed teleport. + * Teleport a {@link OnlineUser} to a specified {@link Position} after a warmup period * * @param onlineUser the {@link OnlineUser} to teleport * @param position the target {@link Position} to teleport to */ - public CompletableFuture teleport(@NotNull OnlineUser onlineUser, @NotNull Position position) { + public CompletableFuture timedTeleport(@NotNull OnlineUser onlineUser, @NotNull Position position) { final int teleportWarmupTime = plugin.getSettings().teleportWarmupTime; if (!onlineUser.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node) && teleportWarmupTime > 0) { if (currentlyOnWarmup.contains(onlineUser.uuid)) { @@ -159,20 +218,20 @@ public class TeleportManager { return CompletableFuture.supplyAsync(() -> processTeleportWarmup(new TimedTeleport(onlineUser, position, teleportWarmupTime)) .thenApply(teleport -> { if (!teleport.cancelled) { - return teleportNow(onlineUser, position).join(); + return teleport(onlineUser, position).join(); } else { return TeleportResult.CANCELLED; } }).join()); } else { - return teleportNow(onlineUser, position); + return teleport(onlineUser, position); } } /** * Handles a completed {@link OnlineUser}'s {@link TeleportResult} with the appropriate message * - * @param onlineUser the {@link OnlineUser} who just completed a teleport + * @param onlineUser the {@link OnlineUser} to send the teleport completion message to * @param teleportResult the {@link TeleportResult} to handle */ public void finishTeleport(@NotNull OnlineUser onlineUser, @NotNull TeleportResult teleportResult) { @@ -194,12 +253,14 @@ public class TeleportManager { } /** - * Executes a teleport now, teleporting a {@link OnlineUser} to a specified {@link Position} + * Carries out a teleport, teleporting a {@link OnlineUser} to a specified {@link Position} and returning + * a future that will return a {@link TeleportResult} * * @param onlineUser the {@link OnlineUser} to teleport - * @param position the target {@link Position} to teleport to + * @param position the target {@link Position} to teleport to# + * @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult} */ - private CompletableFuture teleportNow(@NotNull OnlineUser onlineUser, @NotNull Position position) { + public CompletableFuture teleport(@NotNull OnlineUser onlineUser, @NotNull Position position) { final Teleport teleport = new Teleport(onlineUser, position); return onlineUser.getPosition().thenApply(preTeleportPosition -> plugin.getDatabase() .setLastPosition(onlineUser, preTeleportPosition) // Update the player's last position @@ -213,7 +274,17 @@ public class TeleportManager { }).join()).join()); } - private CompletableFuture teleportCrossServer(OnlineUser onlineUser, Teleport teleport) { + /** + * Handles a cross-server teleport, setting database parameters and dispatching a player across the network + * + * @param onlineUser the {@link OnlineUser} to teleport + * @param teleport the {@link Teleport} to carry out + * @return future completing when the teleport is complete with a {@link TeleportResult}. + * Successful cross-server teleports will return {@link TeleportResult#COMPLETED_CROSS_SERVER}. + *

Note that cross-server teleports will return with a {@link TeleportResult#FAILED_INVALID_SERVER} result if the + * target server is not online + */ + private CompletableFuture teleportCrossServer(@NotNull OnlineUser onlineUser, @NotNull Teleport teleport) { assert plugin.getNetworkMessenger() != null; return plugin.getDatabase().setCurrentTeleport(teleport.player, teleport) .thenApply(ignored -> plugin.getNetworkMessenger().sendPlayer(onlineUser, teleport.target.server) diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index 8dc41fb9..c98a37f1 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -113,10 +113,10 @@ error_warp_description_length: '[Error:](#ff3300) [Warp descriptions must be les error_warp_description_characters: '[Error:](#ff3300) [Warp descriptions may only contain alphanumeric (A-Z, 0-9) characters, spaces, hyphens (-) and underscores (_)](#ff7e5e)' error_no_permission: '[Error:](#ff3300) [You do not have permission to execute that command.](#ff7e5e)' -error_already_teleporting: '[Error:](#ff3300) [Please wait for your current teleport to finish!](#ff7e5e)' +error_already_teleporting: '[Error:](#ff3300) [Please wait for the current teleport to finish!](#ff7e5e)' error_no_last_position: '[Error:](#ff3300) [You have no last position to return to!](#ff7e5e)' error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' -error_invalid_server: '[Error:](#ff3300) [Failed to finish your teleportation as the target server could not be found or was offline.](#ff7e5e)' +error_invalid_server: '[Error:](#ff3300) [Failed to finish teleportation as the target server could not be found or was offline.](#ff7e5e)' error_home_invalid: '[Error:](#ff3300) [You do not have a home named "%1%"](#ff7e5e)' error_warp_invalid: '[Error:](#ff3300) [There is no warp set named "%1%"](#ff7e5e)' error_invalid_syntax: '[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)' @@ -142,14 +142,14 @@ error_tp_invalid_world: '[Error:](#ff3300) [Please specify a valid server world. error_rtp_randomization_timeout: '[Error:](#ff3300) [Failed to find a safe random location to teleport you.](#ff7e5e)' error_permission_restricted_warp: '[Error:](#ff3300) [You do not have permission to warp to %1%!](#ff7e5e)' error_invalid_page_number: '[Error:](#ff3300) [Please specify a valid page number.](#ff7e5e)' -error_invalid_on_arrival: '[Error:](#ff3300) [Failed to finish your teleportation as the target world could not be found.](#ff7e5e)' +error_invalid_on_arrival: '[Error:](#ff3300) [Failed to finish teleportation as the target world could not be found.](#ff7e5e)' error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out.](#ff7e5e)' error_invalid_player: '[Error:](#ff3300) [Please specify the name of a valid player!](#ff7e5e)' error_no_homes_set_other: '[Error:](#ff3300) [%1% has not set any homes!](#ff7e5e)' error_home_invalid_other: '[Error:](#ff3300) [%1% does not have a home set named "%2%"](#ff7e5e)' error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a maximum of %1% homes public.](#ff7e5e)' -error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)' +error_illegal_target_coordinates: '[Error:](#ff3300) [Cancelled teleport as it exceeds the possible game world limits.](#ff7e5e)' error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)' home_command_description: 'Teleport to one of your homes' diff --git a/images/edit-home-menu.png b/images/edit-home-menu.png new file mode 100644 index 00000000..3dd7ca5e Binary files /dev/null and b/images/edit-home-menu.png differ diff --git a/images/home-list.png b/images/home-list.png new file mode 100644 index 00000000..8047f5c3 Binary files /dev/null and b/images/home-list.png differ