Prevent sending teleport requests to self, send message on /tpall

This commit is contained in:
William committed 2022-08-24 22:24:35 +01:00
1 parent 312bff2efc
commit 98931c1900
7 files changed
+41 -18

No files matched your search

@@ -32,6 +32,10 @@ public class TpAllCommand extends CommandBase {
return;
}
// Send a message
plugin.getLocales().getLocale("teleporting_all_players", Integer.toString(players.size()))
.ifPresent(onlineUser::sendMessage);
// Teleport every player
players.forEach(playerName -> plugin.getTeleportManager()
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser));
@@ -130,10 +130,11 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
@Override
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
final boolean serveCoordinateCompletions = user != null && user.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node);
switch (args.length) {
case 0, 1 -> {
final ArrayList<String> completions = new ArrayList<>();
completions.addAll(user != null
completions.addAll(serveCoordinateCompletions
? List.of("~", "~ ~", "~ ~ ~",
Integer.toString((int) user.getPosition().x),
((int) user.getPosition().x + " " + (int) user.getPosition().y),
@@ -153,7 +154,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
completions.addAll(List.of("~", Integer.toString((int) user.getPosition().y)));
completions.addAll(List.of("~ ~", (int) user.getPosition().y + " " + (int) user.getPosition().z));
} else {
completions.addAll(user != null
completions.addAll(serveCoordinateCompletions
? List.of("~", "~ ~", "~ ~ ~",
Integer.toString((int) user.getPosition().x),
((int) user.getPosition().x + " " + (int) user.getPosition().y),
@@ -168,12 +169,12 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
case 3 -> {
final ArrayList<String> completions = new ArrayList<>();
if (isCoordinate(args[0]) && isCoordinate(args[1])) {
if (user == null) {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) user.getPosition().z)));
} else if (isCoordinate(args[1])) {
if (user == null) {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) user.getPosition().y)));
@@ -186,7 +187,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
case 4 -> {
final ArrayList<String> completions = new ArrayList<>();
if (isCoordinate(args[1]) && isCoordinate(args[2]) && !isCoordinate(args[0])) {
if (user == null) {
if (!serveCoordinateCompletions) {
return completions;
}
completions.addAll(List.of("~", Integer.toString((int) user.getPosition().z)));
@@ -22,10 +22,17 @@ public class TpaCommand extends CommandBase implements TabCompletable {
if (args.length == 1) {
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA).thenAccept(sent -> {
if (!sent) {
plugin.getLocales().getLocale("error_player_not_found", args[0]).ifPresent(onlineUser::sendMessage);
if (plugin.findPlayer(args[0]).isPresent()) {
plugin.getLocales().getLocale("error_teleport_request_self")
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getLocales().getLocale("error_player_not_found", args[0])
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getLocales().getLocale("tpa_request_sent", args[0]).ifPresent(onlineUser::sendMessage);
plugin.getLocales().getLocale("tpa_request_sent", args[0])
.ifPresent(onlineUser::sendMessage);
});
} else {
plugin.getLocales().getLocale("error_invalid_syntax", "/tpa <player>")
@@ -22,10 +22,17 @@ public class TpaHereCommand extends CommandBase implements TabCompletable {
if (args.length == 1) {
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA_HERE).thenAccept(sent -> {
if (!sent) {
plugin.getLocales().getLocale("error_player_not_found", args[0]).ifPresent(onlineUser::sendMessage);
if (plugin.findPlayer(args[0]).isPresent()) {
plugin.getLocales().getLocale("error_teleport_request_self")
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getLocales().getLocale("error_player_not_found", args[0])
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getLocales().getLocale("tpahere_request_sent", args[0]).ifPresent(onlineUser::sendMessage);
plugin.getLocales().getLocale("tpahere_request_sent", args[0])
.ifPresent(onlineUser::sendMessage);
});
} else {
plugin.getLocales().getLocale("error_invalid_syntax", "/tpahere <player>")
@@ -83,6 +83,9 @@ public class RequestManager {
Instant.now().getEpochSecond() + plugin.getSettings().teleportRequestExpiryTime);
final Optional<OnlineUser> localTarget = plugin.findPlayer(targetUser);
if (localTarget.isPresent()) {
if (localTarget.get().uuid.equals(requester.uuid)) {
return CompletableFuture.completedFuture(false);
}
request.recipientName = localTarget.get().username;
return CompletableFuture.supplyAsync(() -> sendLocalTeleportRequest(request, localTarget.get()));
}
@@ -186,7 +186,8 @@ public class TeleportManager {
public CompletableFuture<Optional<TeleportResult>> teleportPlayerToPlayerByName(@NotNull String playerName,
@NotNull String targetPlayer,
@NotNull OnlineUser requester) {
final Optional<Position> localPositionTarget = plugin.findPlayer(targetPlayer).map(OnlineUser::getPosition);
final Optional<OnlineUser> localPlayer = plugin.findPlayer(playerName);
final Optional<Position> localPositionTarget = localPlayer.map(OnlineUser::getPosition);
if (localPositionTarget.isPresent()) {
return teleportPlayerByName(playerName, localPositionTarget.get(), requester);
}
+8 -8
View File
@@ -8,6 +8,7 @@ teleporting_action_bar_processing: '[Teleporting…](#00fb9a)'
teleporting_action_bar_cancelled: '[Teleportation cancelled!](#ff7e5e)'
teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)'
teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
teleporting_all_players: '[Teleporting %1% players to your position…](#00fb9a)'
edit_home_menu_title: '[Viewing details for your home,](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)'
edit_home_menu_title_other: '[Viewing details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)'
@@ -83,6 +84,12 @@ teleport_request_declined_confirmation: '[You declined %1%''s teleport request.]
teleport_request_accepted: '[%1% has accepted your teleport request!](#00fb9a)'
teleport_request_declined: '[%1% has declined your teleport request.](#ff7e5e)'
tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) %1%'
tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to incoming teleport requests.](#00fb9a) %1%'
tpignore_on_notification: '[You are currently ignoring incoming teleport requests!](gray) %1%'
tpignore_toggle_button: '[[🔔 Toggle…]](#ffc43b show_text=&#ffc43b&Click to toggle:\n&7Toggle ignoring/listening to incoming teleport requests run_command=/huskhomes:tpignore)'
set_home_used_free_slots: '[You''ve used all of your free set home slots (%1%); setting additional homes will cost %2% each.](gray)'
set_home_success: '[Successfully set a new home called](#00fb9a) [%1%](#00fb9a bold)'
set_warp_success: '[Successfully set a new warp called](#00fb9a) [%1%](#00fb9a bold)'
@@ -97,13 +104,6 @@ teleporting_complete_console: '[Console teleported you to %1%.](gray)'
spawn_warp_default_description: 'The /spawn position of the server'
item_no_description: '(No description)'
tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) %1%'
tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to incoming teleport requests.](#00fb9a) %1%'
tpignore_on_notification: '[You are currently ignoring incoming teleport requests!](gray) %1%'
tpignore_toggle_button: '[[🔔 Toggle…]](#ffc43b show_text=&#ffc43b&Click to toggle:\n&7Toggle ignoring/listening to incoming teleport requests run_command=/huskhomes:tpignore)'
teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)'
economy_action_additional_home_slot: '[ℹ Spent %1% to set an additional home.](gray)'
economy_action_make_home_public: '[ℹ Spent %1% to make your home public.](gray)'
economy_action_random_teleport: '[ℹ Spent %1% to randomly teleport.](gray)'
@@ -144,8 +144,8 @@ error_teleport_request_expired: '[Error:](#ff3300) [Your pending teleport reques
error_teleport_request_sender_not_online: '[Error:](#ff3300) [The sender of your pending teleport request is no longer online.](#ff7e5e)'
error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests.](#ff7e5e) [[Stop Ignoring…]](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'
error_invalid_teleport_request: '[Error:](#ff3300) [You do not have a pending teleport request from %1%.](#ff7e5e)'
error_teleport_request_self: '[Error:](#ff3300) [You cannot send a teleport request to yourself.](#ff7e5e)'
error_player_not_found: '[Error:](#ff3300) [Could not find the player %1%.](#ff7e5e)'
error_teleport_to_self: '[Error:](#ff3300) [You cannot teleport to yourself!](#ff7e5e)' # todo
error_rtp_restricted_world: '[Error:](#ff3300) [You cannot randomly teleport in this world.](#ff7e5e)'
error_rtp_cooldown: '[Error:](#ff3300) [You must wait %1% minutes before randomly teleporting again.](#ff7e5e)'
error_command_disabled: '[Error:](#ff3300) [That command is disabled!](#ff7e5e)'