From e43a4c74e1f75bf50914dabea70ce8a699d0e359 Mon Sep 17 00:00:00 2001 From: JRoy <10731363+JRoy@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:22:24 -0700 Subject: [PATCH 1/2] Fix behavior of tpr command --- .../essentials/commands/Commandtpr.java | 49 ++++++++++++++----- .../src/main/resources/messages.properties | 6 +++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java index 589a7f7c6f4..95668e1990c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java @@ -25,26 +25,45 @@ protected void run(final Server server, final User user, final String commandLab final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); final RandomTeleport randomTeleport = ess.getRandomTeleport(); - final String defaultLocation = randomTeleport.getDefaultLocation().replace("{world}", user.getLocation().getWorld().getName()); - final String name = args.length > 0 ? args[0] : defaultLocation; - final User userToTeleport = args.length > 1 && user.isAuthorized("essentials.tpr.others") ? getPlayer(server, user, args, 1) : user; - if (randomTeleport.isPerLocationPermission() && !user.isAuthorized("essentials.tpr.location." + name)) { - throw new TranslatableException("warpUsePermission"); + + final String randomLocationName; + final User target; + if (args.length == 0) { + // No arguments provided, use the default random teleport location + randomLocationName = randomTeleport.getDefaultLocation().replace("{world}", user.getLocation().getWorld().getName()); + target = user; + } else { + // Use the first argument as the location name + randomLocationName = args[0]; + if (!randomTeleport.hasLocation(randomLocationName)) { + throw new TranslatableException("tprNotExist"); + } + + if (randomTeleport.isPerLocationPermission() && !user.isAuthorized("essentials.tpr.location." + randomLocationName)) { + throw new TranslatableException("tprNoPermission"); + } + + if (args.length > 1 && user.isAuthorized("essentials.tpr.others")) { + target = getPlayer(server, user, args, 1); + } else { + target = user; + } } - final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name)); + + final UserRandomTeleportEvent event = new UserRandomTeleportEvent(target, randomLocationName, randomTeleport.getCenter(randomLocationName), randomTeleport.getMinRange(randomLocationName), randomTeleport.getMaxRange(randomLocationName)); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name)) + (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(randomLocationName)) .thenAccept(location -> { final CompletableFuture future = getNewExceptionFuture(user.getSource(), commandLabel); future.thenAccept(success -> { if (success) { - userToTeleport.sendTl("tprSuccess"); + target.sendTl("tprSuccess"); } }); - userToTeleport.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future); + target.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future); }); throw new NoChargeException(); } @@ -56,13 +75,19 @@ protected void run(final Server server, final CommandSource sender, final String } final RandomTeleport randomTeleport = ess.getRandomTeleport(); final User userToTeleport = getPlayer(server, sender, args, 1); - final String name = args[0]; - final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name)); + + // Validate the location name - only use if it exists and sender has permission + final String potentialLocation = args[0]; + if (!randomTeleport.hasLocation(potentialLocation)) { + throw new TranslatableException("tprNotExist"); + } + + final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, potentialLocation, randomTeleport.getCenter(potentialLocation), randomTeleport.getMinRange(potentialLocation), randomTeleport.getMaxRange(potentialLocation)); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name)) + (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(potentialLocation)) .thenAccept(location -> { final CompletableFuture future = getNewExceptionFuture(sender, commandLabel); future.thenAccept(success -> { diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 491bead5899..57a0b940f30 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1416,7 +1416,13 @@ tprCommandDescription=Teleport randomly. tprCommandUsage=/ tprCommandUsage1=/ tprCommandUsage1Description=Teleports you to a random location +tprCommandUsage2=/ +tprCommandUsage2Description=Teleports you to a random location in the specified world +tprCommandUsage3=/ +tprCommandUsage3Description=Teleports the specified player to a random location in the specified world tprSuccess=Teleporting to a random location... +tprNoPermission=You do not have permission to use that location. +tprNotExist=That random teleport location does not exist. tps=Current TPS \= {0} tptoggleCommandDescription=Blocks all forms of teleportation. tptoggleCommandUsage=/ [player] [on|off] From 81f320e377bde60ceffef2247dcb76d4bc2d9718 Mon Sep 17 00:00:00 2001 From: JRoy <10731363+JRoy@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:28:07 -0700 Subject: [PATCH 2/2] Send message before tpr These can take a while on machines with bad i/o, so send a message so they know something is happening --- .../earth2me/essentials/commands/Commandtpr.java | 13 +++++++++++-- Essentials/src/main/resources/messages.properties | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java index 95668e1990c..fd524bb99c9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java @@ -55,12 +55,18 @@ protected void run(final Server server, final User user, final String commandLab if (event.isCancelled()) { return; } + + target.sendTl("tprSuccess"); + if (target != user) { + user.sendTl("tprOtherUser", target.getDisplayName()); + } + (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(randomLocationName)) .thenAccept(location -> { final CompletableFuture future = getNewExceptionFuture(user.getSource(), commandLabel); future.thenAccept(success -> { if (success) { - target.sendTl("tprSuccess"); + target.sendTl("tprSuccessDone"); } }); target.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future); @@ -87,12 +93,15 @@ protected void run(final Server server, final CommandSource sender, final String if (event.isCancelled()) { return; } + + userToTeleport.sendTl("tprSuccess"); + sender.sendTl("tprOtherUser", userToTeleport.getDisplayName()); (event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(potentialLocation)) .thenAccept(location -> { final CompletableFuture future = getNewExceptionFuture(sender, commandLabel); future.thenAccept(success -> { if (success) { - userToTeleport.sendTl("tprSuccess"); + userToTeleport.sendTl("tprSuccessDone"); } }); userToTeleport.getAsyncTeleport().now(location, false, PlayerTeleportEvent.TeleportCause.COMMAND, future); diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 57a0b940f30..f37586d6dc3 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1420,7 +1420,9 @@ tprCommandUsage2=/ tprCommandUsage2Description=Teleports you to a random location in the specified world tprCommandUsage3=/ tprCommandUsage3Description=Teleports the specified player to a random location in the specified world +tprOtherUser=Teleporting {0} to a random location. tprSuccess=Teleporting to a random location... +tprSuccessDone=You have been teleported to a random location. tprNoPermission=You do not have permission to use that location. tprNotExist=That random teleport location does not exist. tps=Current TPS \= {0}