mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Prevent sending teleport requests to self, send message on /tpall
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user