mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Fix /tp command with players, remove unhelpful TAB completion
This commit is contained in:
1 parent
9bdf67c250
commit
5faab57d8e
7 files changed
+150
-140
No files matched your search
@@ -1,13 +0,0 @@
|
|||||||
tp {
|
|
||||||
x|player brigadier:string single_word {
|
|
||||||
y|x|player brigadier:string single_word {
|
|
||||||
z|y brigadier:string single_word {
|
|
||||||
world|z brigadier:string single_word {
|
|
||||||
server|world brigadier:string single_word {
|
|
||||||
server brigadier:string single_word;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -61,13 +61,14 @@ public interface HuskHomes {
|
|||||||
* @param playerName the name of the player to find
|
* @param playerName the name of the player to find
|
||||||
* @return an {@link Optional} containing the {@link OnlineUser} if found, or an empty {@link Optional} if not found
|
* @return an {@link Optional} containing the {@link OnlineUser} if found, or an empty {@link Optional} if not found
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
default Optional<OnlineUser> findPlayer(@NotNull String playerName) {
|
default Optional<OnlineUser> findPlayer(@NotNull String playerName) {
|
||||||
return Optional.ofNullable(getOnlinePlayers().stream()
|
return getOnlinePlayers().stream()
|
||||||
.filter(user -> user.username.equalsIgnoreCase(playerName))
|
.filter(user -> user.username.equalsIgnoreCase(playerName))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(getOnlinePlayers().stream()
|
.or(() -> getOnlinePlayers().stream()
|
||||||
.filter(user -> user.username.toLowerCase().startsWith(playerName.toLowerCase()))
|
.filter(user -> user.username.toLowerCase().startsWith(playerName.toLowerCase()))
|
||||||
.findFirst().orElse(null)));
|
.findFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.william278.huskhomes.command;
|
package net.william278.huskhomes.command;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesException;
|
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.Server;
|
import net.william278.huskhomes.position.Server;
|
||||||
@@ -24,99 +23,119 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
|||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
String teleportingUserName = onlineUser.username;
|
// Ensure a valid target was found
|
||||||
TeleportCommandTarget targetPosition;
|
final Optional<TeleportTarget> teleportTarget = getTeleportTarget(args, onlineUser);
|
||||||
|
if (teleportTarget.isEmpty()) {
|
||||||
// Validate argument length
|
|
||||||
if (args.length > 6 || args.length < 1) {
|
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tp <target> [destination]")
|
plugin.getLocales().getLocale("error_invalid_syntax", "/tp <target> [destination]")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the first argument is a player target
|
// Determine the player to teleport
|
||||||
if (args.length == 1) {
|
final String targetPlayerToTeleport = ((teleportTarget.get() instanceof TargetPlayer) && args.length == 2)
|
||||||
targetPosition = new TeleportCommandTarget(args[0]);
|
? args[0] : ((teleportTarget.get() instanceof TargetPosition)
|
||||||
} else {
|
? (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3]) ? args[0] : onlineUser.username)
|
||||||
// Determine if a player argument has been passed before the destination argument
|
: onlineUser.username);
|
||||||
int coordinatesIndex = ((args.length > 3 && (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3])))
|
|
||||||
|| (args.length == 2)) ? 1 : 0;
|
// Find the online user to teleport
|
||||||
if (coordinatesIndex == 1) {
|
plugin.getCache().fetchAndCacheGlobalPlayerList(plugin, onlineUser).join();
|
||||||
teleportingUserName = args[0];
|
final String playerToTeleport = plugin.getCache().players.stream()
|
||||||
|
.filter(user -> user.equalsIgnoreCase(targetPlayerToTeleport)).findFirst()
|
||||||
|
.or(() -> plugin.getCache().players.stream()
|
||||||
|
.filter(user -> user.toLowerCase().startsWith(targetPlayerToTeleport)).findFirst())
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
// Ensure the player to teleport exists
|
||||||
|
if (playerToTeleport == null) {
|
||||||
|
plugin.getLocales().getLocale("error_player_not_found", targetPlayerToTeleport)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the target position (player or coordinates)
|
// Ensure the user has permission to teleport the player to teleport
|
||||||
if (args.length == 2) {
|
if (!playerToTeleport.equals(onlineUser.username)) {
|
||||||
targetPosition = new TeleportCommandTarget(args[1]);
|
if (!onlineUser.hasPermission(Permission.COMMAND_TP_OTHER.node)) {
|
||||||
} else {
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
// Coordinate teleportation requires a permission node
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the teleport
|
||||||
|
if (teleportTarget.get() instanceof TargetPlayer targetPlayer) {
|
||||||
|
// Handle player teleport targets
|
||||||
|
plugin.getTeleportManager()
|
||||||
|
.teleportNamedPlayers(playerToTeleport, targetPlayer.playerName, onlineUser, false)
|
||||||
|
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
||||||
|
result -> {
|
||||||
|
if (!result.successful) {
|
||||||
|
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||||
|
playerToTeleport, targetPlayer.playerName)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
},
|
||||||
|
() -> plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName)
|
||||||
|
.ifPresent(onlineUser::sendMessage)));
|
||||||
|
} else if (teleportTarget.get() instanceof TargetPosition targetPosition) {
|
||||||
|
// Handle coordinate teleport targets
|
||||||
if (!onlineUser.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node)) {
|
if (!onlineUser.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node)) {
|
||||||
plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage);
|
plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the coordinates and set the target position
|
|
||||||
final Position userPosition = onlineUser.getPosition();
|
|
||||||
final Optional<Position> parsedPosition = Position.parse(userPosition,
|
|
||||||
Arrays.copyOfRange(args, coordinatesIndex, args.length));
|
|
||||||
if (parsedPosition.isEmpty()) {
|
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
|
||||||
"/tp <target> <x> <y> <z> [world] [server]")
|
|
||||||
.ifPresent(onlineUser::sendMessage);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
targetPosition = new TeleportCommandTarget(parsedPosition.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the teleport
|
|
||||||
final String playerToTeleportName = teleportingUserName;
|
|
||||||
if (targetPosition.targetType == TeleportCommandTarget.TargetType.PLAYER) {
|
|
||||||
// Teleport players by usernames
|
|
||||||
assert targetPosition.targetPlayer != null;
|
|
||||||
plugin.getTeleportManager()
|
plugin.getTeleportManager()
|
||||||
.teleportPlayerToPlayerByName(playerToTeleportName, targetPosition.targetPlayer, onlineUser, false)
|
.teleportPlayerByName(playerToTeleport, targetPosition.position, onlineUser, false)
|
||||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresent(
|
||||||
result -> {
|
result -> {
|
||||||
if (result.successful) {
|
if (!result.successful || playerToTeleport.equalsIgnoreCase(onlineUser.username)) {
|
||||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
||||||
playerToTeleportName, targetPosition.targetPlayer)
|
|
||||||
.ifPresent(onlineUser::sendMessage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
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().teleportPlayerByName(playerToTeleportName, targetPosition.targetPosition, onlineUser, false)
|
|
||||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
|
||||||
result -> {
|
|
||||||
if (result.successful && !playerToTeleportName.equalsIgnoreCase(onlineUser.username)) {
|
|
||||||
plugin.getLocales().getLocale("teleporting_other_complete_position",
|
plugin.getLocales().getLocale("teleporting_other_complete_position",
|
||||||
playerToTeleportName,
|
playerToTeleport,
|
||||||
Integer.toString((int) targetPosition.targetPosition.x),
|
Integer.toString((int) targetPosition.position.x),
|
||||||
Integer.toString((int) targetPosition.targetPosition.y),
|
Integer.toString((int) targetPosition.position.y),
|
||||||
Integer.toString((int) targetPosition.targetPosition.z))
|
Integer.toString((int) targetPosition.position.z))
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
}));
|
||||||
}
|
}
|
||||||
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");
|
|
||||||
}).exceptionally(throwable -> {
|
}).exceptionally(throwable -> {
|
||||||
plugin.getLoggingAdapter().log(Level.SEVERE, "An error occurred whilst executing a teleport command", throwable);
|
plugin.getLoggingAdapter().log(Level.SEVERE, "An error occurred whilst executing a teleport command", throwable);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the teleport target from a set of arguments, which may be comprised of usernames and/or position
|
||||||
|
* coordinates with a world and server.
|
||||||
|
*
|
||||||
|
* @param args The arguments to parse.
|
||||||
|
* @param relativeTo The position to use as a relative reference. This is used for relative coordinate handling
|
||||||
|
* (e.g. {@code ~-10 ~ ~20})
|
||||||
|
* @return The teleport target, if it could be parsed, otherwise and empty {@link Optional}.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Optional<TeleportTarget> getTeleportTarget(@NotNull String[] args, @NotNull OnlineUser relativeTo) {
|
||||||
|
if (args.length == 1 || args.length == 2) {
|
||||||
|
return Optional.of(new TargetPlayer(args[args.length - 1]));
|
||||||
|
}
|
||||||
|
if (args.length > 2 && args.length < 7) {
|
||||||
|
final Optional<TeleportTarget> targetPosition = Position.parse(args, relativeTo.getPosition())
|
||||||
|
.map(TargetPosition::new);
|
||||||
|
return targetPosition.or(() -> Position.parse(Arrays.copyOfRange(args, 1, args.length),
|
||||||
|
relativeTo.getPosition()).map(TargetPosition::new));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a string is a valid (relative) position coordinate double target.
|
||||||
|
*
|
||||||
|
* @param coordinate The string to check.
|
||||||
|
* @return {@code true} if the string is a valid coordinate, otherwise {@code false}.
|
||||||
|
*/
|
||||||
private boolean isCoordinate(@NotNull String coordinate) {
|
private boolean isCoordinate(@NotNull String coordinate) {
|
||||||
try {
|
try {
|
||||||
if (coordinate.startsWith("~")) {
|
if (coordinate.startsWith("~")) {
|
||||||
@@ -143,12 +162,12 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
|||||||
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
|
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final TeleportCommandTarget teleportCommandTarget;
|
final TeleportTarget teleportTarget;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
teleportCommandTarget = new TeleportCommandTarget(args[1]);
|
teleportTarget = new TargetPlayer(args[1]);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
teleportCommandTarget = new TeleportCommandTarget(new Position(
|
teleportTarget = new TargetPosition(new Position(
|
||||||
Double.parseDouble(args[1]),
|
Double.parseDouble(args[1]),
|
||||||
Double.parseDouble(args[2]),
|
Double.parseDouble(args[2]),
|
||||||
Double.parseDouble(args[3]),
|
Double.parseDouble(args[3]),
|
||||||
@@ -162,14 +181,13 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute the console teleport
|
// Execute the console teleport
|
||||||
if (teleportCommandTarget.targetType == TeleportCommandTarget.TargetType.PLAYER) {
|
if (teleportTarget instanceof TargetPlayer targetPlayer) {
|
||||||
assert teleportCommandTarget.targetPlayer != null;
|
|
||||||
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username
|
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username
|
||||||
+ " to " + teleportCommandTarget.targetPlayer);
|
+ " to " + targetPlayer.playerName);
|
||||||
plugin.getTeleportManager().teleportToPlayerByName(playerToTeleport, teleportCommandTarget.targetPlayer, false);
|
plugin.getTeleportManager().teleportToPlayerByName(playerToTeleport, targetPlayer.playerName, false);
|
||||||
} else {
|
} else {
|
||||||
assert teleportCommandTarget.targetPosition != null;
|
final TargetPosition targetPosition = (TargetPosition) teleportTarget;
|
||||||
plugin.getTeleportManager().teleport(playerToTeleport, teleportCommandTarget.targetPosition)
|
plugin.getTeleportManager().teleport(playerToTeleport, targetPosition.position)
|
||||||
.thenAccept(teleportResult -> {
|
.thenAccept(teleportResult -> {
|
||||||
if (teleportResult.successful) {
|
if (teleportResult.successful) {
|
||||||
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
|
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.username);
|
||||||
@@ -256,31 +274,38 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a target position to teleport to
|
||||||
|
*/
|
||||||
|
private static final class TargetPosition extends TeleportTarget {
|
||||||
|
/**
|
||||||
|
* The target {@link Position}
|
||||||
|
*/
|
||||||
|
private final Position position;
|
||||||
|
|
||||||
|
private TargetPosition(@NotNull Position position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a target player to teleport to
|
||||||
|
*/
|
||||||
|
private static final class TargetPlayer extends TeleportTarget {
|
||||||
|
/**
|
||||||
|
* Name of the target player
|
||||||
|
*/
|
||||||
|
private final String playerName;
|
||||||
|
|
||||||
|
private TargetPlayer(@NotNull String playerName) {
|
||||||
|
this.playerName = playerName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies the target of a teleport command operation
|
* Identifies the target of a teleport command operation
|
||||||
*/
|
*/
|
||||||
private static class TeleportCommandTarget {
|
private static abstract class TeleportTarget {
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final TargetType targetType;
|
|
||||||
@Nullable
|
|
||||||
private String targetPlayer;
|
|
||||||
@Nullable
|
|
||||||
private Position targetPosition;
|
|
||||||
|
|
||||||
public TeleportCommandTarget(@NotNull String targetPlayer) {
|
|
||||||
this.targetPlayer = targetPlayer;
|
|
||||||
this.targetType = TargetType.PLAYER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TeleportCommandTarget(@NotNull Position targetPosition) {
|
|
||||||
this.targetPosition = targetPosition;
|
|
||||||
this.targetType = TargetType.POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TargetType {
|
|
||||||
PLAYER,
|
|
||||||
POSITION
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,12 +75,12 @@ public abstract class NetworkMessenger {
|
|||||||
*/
|
*/
|
||||||
public final CompletableFuture<Optional<String>> findPlayer(@NotNull OnlineUser requester, @NotNull String playerName) {
|
public final CompletableFuture<Optional<String>> findPlayer(@NotNull OnlineUser requester, @NotNull String playerName) {
|
||||||
return getOnlinePlayerNames(requester).thenApply(networkedPlayers ->
|
return getOnlinePlayerNames(requester).thenApply(networkedPlayers ->
|
||||||
Optional.ofNullable(Arrays.stream(networkedPlayers)
|
Arrays.stream(networkedPlayers)
|
||||||
.filter(user -> user.equalsIgnoreCase(playerName))
|
.filter(user -> user.equalsIgnoreCase(playerName))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(Arrays.stream(networkedPlayers)
|
.or(() -> Arrays.stream(networkedPlayers)
|
||||||
.filter(user -> user.toLowerCase().startsWith(playerName))
|
.filter(user -> user.toLowerCase().startsWith(playerName))
|
||||||
.findFirst().orElse(null))));
|
.findFirst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,24 +33,24 @@ public class Position extends Location {
|
|||||||
/**
|
/**
|
||||||
* Parses the position from a set of values
|
* Parses the position from a set of values
|
||||||
*
|
*
|
||||||
* @param values The values to parse
|
* @param args The values to parse
|
||||||
|
* @param relativeTo The {@link Position} to use as a reference for relative coordinates
|
||||||
* @return The position if it could be parsed, otherwise an empty optional
|
* @return The position if it could be parsed, otherwise an empty optional
|
||||||
*/
|
*/
|
||||||
public static Optional<Position> parse(@NotNull Position currentPosition, @NotNull String... values) {
|
public static Optional<Position> parse(@NotNull String[] args, @NotNull Position relativeTo) {
|
||||||
// Validate argument length
|
// Validate argument length
|
||||||
if (values.length < 3 || values.length > 5) {
|
if (args.length < 3 || args.length > 5) {
|
||||||
System.out.println("Invalid syntax");
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse, handle relatives, and return, catching NumberFormatExceptions and returning an empty optional
|
// Parse, handle relatives, and return, catching NumberFormatExceptions and returning an empty optional
|
||||||
try {
|
try {
|
||||||
final double x = parseCoordinate(values[0], currentPosition.x);
|
final double x = parseCoordinate(args[0], relativeTo.x);
|
||||||
final double y = parseCoordinate(values[1], currentPosition.y);
|
final double y = parseCoordinate(args[1], relativeTo.y);
|
||||||
final double z = parseCoordinate(values[2], currentPosition.z);
|
final double z = parseCoordinate(args[2], relativeTo.z);
|
||||||
final World world = values.length > 3 ? new World(values[3], UUID.randomUUID()) : currentPosition.world;
|
final World world = args.length > 3 ? new World(args[3], UUID.randomUUID()) : relativeTo.world;
|
||||||
final Server server = values.length > 4 ? new Server(values[4]) : currentPosition.server;
|
final Server server = args.length > 4 ? new Server(args[4]) : relativeTo.server;
|
||||||
return Optional.of(new Position(x, y, z, currentPosition.yaw, currentPosition.pitch, world, server));
|
return Optional.of(new Position(x, y, z, relativeTo.yaw, relativeTo.pitch, world, server));
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,15 +195,8 @@ public class TeleportManager {
|
|||||||
* @param timed whether the teleport is timed ({@code true}), otherwise instant
|
* @param timed whether the teleport is timed ({@code true}), otherwise instant
|
||||||
* @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult},
|
* @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult},
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Optional<TeleportResult>> teleportPlayerToPlayerByName(@NotNull String playerName,
|
public CompletableFuture<Optional<TeleportResult>> teleportNamedPlayers(@NotNull String playerName, @NotNull String targetPlayer,
|
||||||
@NotNull String targetPlayer,
|
@NotNull OnlineUser requester, final boolean timed) {
|
||||||
@NotNull OnlineUser requester,
|
|
||||||
final boolean timed) {
|
|
||||||
final Optional<OnlineUser> localPlayer = plugin.findPlayer(playerName);
|
|
||||||
final Optional<Position> localPositionTarget = localPlayer.map(OnlineUser::getPosition);
|
|
||||||
if (localPositionTarget.isPresent()) {
|
|
||||||
return teleportPlayerByName(playerName, localPositionTarget.get(), requester, timed);
|
|
||||||
}
|
|
||||||
return getPlayerPositionByName(requester, targetPlayer).thenApply(position -> {
|
return getPlayerPositionByName(requester, targetPlayer).thenApply(position -> {
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public enum Permission {
|
|||||||
* Lets the user view the "disabled command" message for disabled commands
|
* Lets the user view the "disabled command" message for disabled commands
|
||||||
*/
|
*/
|
||||||
COMMAND_DISABLED_MESSAGE("huskhomes.disabled_command_message", DefaultAccess.EVERYONE),
|
COMMAND_DISABLED_MESSAGE("huskhomes.disabled_command_message", DefaultAccess.EVERYONE),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lets the user teleport to their homes ({@code /home [home_name]})
|
* Lets the user teleport to their homes ({@code /home [home_name]})
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +91,11 @@ public enum Permission {
|
|||||||
* Lets the user instantly tp to a set of coordinates ({@code /tp [x] [y] [z] [world] [server]})
|
* Lets the user instantly tp to a set of coordinates ({@code /tp [x] [y] [z] [world] [server]})
|
||||||
*/
|
*/
|
||||||
COMMAND_TP_TO_COORDINATES("huskhomes.command.tp.coordinates", DefaultAccess.OPERATORS),
|
COMMAND_TP_TO_COORDINATES("huskhomes.command.tp.coordinates", DefaultAccess.OPERATORS),
|
||||||
|
/**
|
||||||
|
* Lets the user instantly tp another user to a player (and, if they have the {@link Permission#COMMAND_TP_TO_COORDINATES}
|
||||||
|
* permission, to a set of coordinates) ({@code /tp [player_to_teleport] [target]})
|
||||||
|
*/
|
||||||
|
COMMAND_TP_OTHER("huskhomes.command.tp.other", DefaultAccess.OPERATORS),
|
||||||
/**
|
/**
|
||||||
* Lets the user instantly tp another player to them ({@code /tphere [player_name]})
|
* Lets the user instantly tp another player to them ({@code /tphere [player_name]})
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user