Skip to content

Commit 6ad737d

Browse files
authored
Fix various TPR issues (#6205)
Fixes various issues from the TPR improvements PR Fixes #6035
1 parent 8d44d1a commit 6ad737d

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpr.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,51 @@ protected void run(final Server server, final User user, final String commandLab
2525
final Trade charge = new Trade(this.getName(), ess);
2626
charge.isAffordableFor(user);
2727
final RandomTeleport randomTeleport = ess.getRandomTeleport();
28-
final String defaultLocation = randomTeleport.getDefaultLocation().replace("{world}", user.getLocation().getWorld().getName());
29-
final String name = args.length > 0 ? args[0] : defaultLocation;
30-
final User userToTeleport = args.length > 1 && user.isAuthorized("essentials.tpr.others") ? getPlayer(server, user, args, 1) : user;
31-
if (randomTeleport.isPerLocationPermission() && !user.isAuthorized("essentials.tpr.location." + name)) {
32-
throw new TranslatableException("warpUsePermission");
28+
29+
final String randomLocationName;
30+
final User target;
31+
if (args.length == 0) {
32+
// No arguments provided, use the default random teleport location
33+
randomLocationName = randomTeleport.getDefaultLocation().replace("{world}", user.getLocation().getWorld().getName());
34+
target = user;
35+
} else {
36+
// Use the first argument as the location name
37+
randomLocationName = args[0];
38+
if (!randomTeleport.hasLocation(randomLocationName)) {
39+
throw new TranslatableException("tprNotExist");
40+
}
41+
42+
if (randomTeleport.isPerLocationPermission() && !user.isAuthorized("essentials.tpr.location." + randomLocationName)) {
43+
throw new TranslatableException("tprNoPermission");
44+
}
45+
46+
if (args.length > 1 && user.isAuthorized("essentials.tpr.others")) {
47+
target = getPlayer(server, user, args, 1);
48+
} else {
49+
target = user;
50+
}
3351
}
34-
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name));
52+
53+
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(target, randomLocationName, randomTeleport.getCenter(randomLocationName), randomTeleport.getMinRange(randomLocationName), randomTeleport.getMaxRange(randomLocationName));
3554
server.getPluginManager().callEvent(event);
3655
if (event.isCancelled()) {
3756
return;
3857
}
39-
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name))
58+
59+
target.sendTl("tprSuccess");
60+
if (target != user) {
61+
user.sendTl("tprOtherUser", target.getDisplayName());
62+
}
63+
64+
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(randomLocationName))
4065
.thenAccept(location -> {
4166
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
4267
future.thenAccept(success -> {
4368
if (success) {
44-
userToTeleport.sendTl("tprSuccess");
69+
target.sendTl("tprSuccessDone");
4570
}
4671
});
47-
userToTeleport.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future);
72+
target.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future);
4873
});
4974
throw new NoChargeException();
5075
}
@@ -56,18 +81,27 @@ protected void run(final Server server, final CommandSource sender, final String
5681
}
5782
final RandomTeleport randomTeleport = ess.getRandomTeleport();
5883
final User userToTeleport = getPlayer(server, sender, args, 1);
59-
final String name = args[0];
60-
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name));
84+
85+
// Validate the location name - only use if it exists and sender has permission
86+
final String potentialLocation = args[0];
87+
if (!randomTeleport.hasLocation(potentialLocation)) {
88+
throw new TranslatableException("tprNotExist");
89+
}
90+
91+
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, potentialLocation, randomTeleport.getCenter(potentialLocation), randomTeleport.getMinRange(potentialLocation), randomTeleport.getMaxRange(potentialLocation));
6192
server.getPluginManager().callEvent(event);
6293
if (event.isCancelled()) {
6394
return;
6495
}
65-
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name))
96+
97+
userToTeleport.sendTl("tprSuccess");
98+
sender.sendTl("tprOtherUser", userToTeleport.getDisplayName());
99+
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(potentialLocation))
66100
.thenAccept(location -> {
67101
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
68102
future.thenAccept(success -> {
69103
if (success) {
70-
userToTeleport.sendTl("tprSuccess");
104+
userToTeleport.sendTl("tprSuccessDone");
71105
}
72106
});
73107
userToTeleport.getAsyncTeleport().now(location, false, PlayerTeleportEvent.TeleportCause.COMMAND, future);

Essentials/src/main/resources/messages.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,15 @@ tprCommandDescription=Teleport randomly.
14161416
tprCommandUsage=/<command>
14171417
tprCommandUsage1=/<command>
14181418
tprCommandUsage1Description=Teleports you to a random location
1419+
tprCommandUsage2=/<command> <world>
1420+
tprCommandUsage2Description=Teleports you to a random location in the specified world
1421+
tprCommandUsage3=/<command> <world> <player>
1422+
tprCommandUsage3Description=Teleports the specified player to a random location in the specified world
1423+
tprOtherUser=<primary>Teleporting<secondary> {0}<primary> to a random location.
14191424
tprSuccess=<primary>Teleporting to a random location...
1425+
tprSuccessDone=<primary>You have been teleported to a random location.
1426+
tprNoPermission=<dark_red>You do not have permission to use that location.
1427+
tprNotExist=<dark_red>That random teleport location does not exist.
14201428
tps=<primary>Current TPS \= {0}
14211429
tptoggleCommandDescription=Blocks all forms of teleportation.
14221430
tptoggleCommandUsage=/<command> [player] [on|off]

0 commit comments

Comments
 (0)