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>")