Skip to content

Commit eee18f4

Browse files
committed
Pass optional location parameters to teleport TL keys.
1 parent 4084445 commit eee18f4

File tree

11 files changed

+63
-51
lines changed

11 files changed

+63
-51
lines changed

Essentials/src/com/earth2me/essentials/Teleport.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public void now(Location loc, boolean cooldown, TeleportCause cause) throws Exce
7979
{
8080
cooldown(false);
8181
}
82-
now(teleportOwner, new LocationTarget(loc), cause);
82+
final ITarget target = new LocationTarget(loc);
83+
now(teleportOwner, target, cause);
8384
}
8485

8586
@Override
@@ -89,29 +90,31 @@ public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exc
8990
{
9091
cooldown(false);
9192
}
92-
now(teleportOwner, new PlayerTarget(entity), cause);
93+
final ITarget target = new PlayerTarget(entity);
94+
now(teleportOwner, target, cause);
95+
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
9396
}
9497

9598
protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception
9699
{
97100
cancel(false);
98101
teleportee.setLastLocation();
99-
final Location location = target.getLocation();
102+
final Location loc = target.getLocation();
100103

101-
if (LocationUtil.isBlockUnsafe(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()))
104+
if (LocationUtil.isBlockUnsafe(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
102105
{
103106
if (ess.getSettings().isTeleportSafetyEnabled())
104107
{
105-
teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, location));
108+
teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, loc));
106109
}
107110
else
108111
{
109-
throw new Exception(_("unsafeTeleportDestination"));
112+
throw new Exception(_("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
110113
}
111114
}
112115
else
113116
{
114-
teleportee.getBase().teleport(location);
117+
teleportee.getBase().teleport(loc);
115118
}
116119
}
117120

@@ -130,22 +133,30 @@ public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws
130133
teleport(teleportOwner, new LocationTarget(loc), chargeFor, cause);
131134
}
132135

136+
//This is used when teleporting to a player
133137
@Override
134138
public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception
135139
{
136-
teleport(teleportOwner, new PlayerTarget(entity), chargeFor, cause);
140+
ITarget target = new PlayerTarget(entity);
141+
teleport(teleportOwner, target, chargeFor, cause);
142+
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
137143
}
138144

145+
//This is used when teleporting to stored location
139146
@Override
140147
public void teleportPlayer(IUser teleportee, Location loc, Trade chargeFor, TeleportCause cause) throws Exception
141148
{
142149
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
143150
}
144151

152+
//This is used on /tphere
145153
@Override
146154
public void teleportPlayer(IUser teleportee, Player entity, Trade chargeFor, TeleportCause cause) throws Exception
147155
{
148-
teleport(teleportee, new PlayerTarget(entity), chargeFor, cause);
156+
ITarget target = new PlayerTarget(entity);
157+
teleport(teleportee, target, chargeFor, cause);
158+
teleportee.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
159+
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
149160
}
150161

151162
private void teleport(IUser teleportee, ITarget target, Trade chargeFor, TeleportCause cause) throws Exception
@@ -228,15 +239,17 @@ protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exceptio
228239
public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception
229240
{
230241
Location loc = ess.getWarps().getWarp(warp);
231-
teleportee.sendMessage(_("warpingTo", warp));
242+
teleportee.sendMessage(_("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
232243
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
233244
}
234245

235246
//The back function is a wrapper used to teleportPlayer a player /back to their previous location.
236247
@Override
237248
public void back(Trade chargeFor) throws Exception
238249
{
239-
teleport(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), chargeFor, TeleportCause.COMMAND);
250+
final Location loc = teleportOwner.getLastLocation();
251+
teleportOwner.sendMessage(_("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
252+
teleport(teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND);
240253
}
241254

242255
//This function is used to throw a user back after a jail sentence

Essentials/src/com/earth2me/essentials/commands/Commandback.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ protected void run(final Server server, final User user, final String commandLab
2727
}
2828
final Trade charge = new Trade(this.getName(), ess);
2929
charge.isAffordableFor(user);
30-
user.sendMessage(_("backUsageMsg"));
3130
user.getTeleport().back(charge);
3231
throw new NoChargeException();
3332
}

Essentials/src/com/earth2me/essentials/commands/Commandtop.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void run(final Server server, final User user, final String commandLabel,
2323
final int topZ = user.getLocation().getBlockZ();
2424
final float pitch = user.getLocation().getPitch();
2525
final float yaw = user.getLocation().getYaw();
26-
final Location location = LocationUtil.getSafeDestination(new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch));
27-
user.getTeleport().teleport(location, new Trade(this.getName(), ess), TeleportCause.COMMAND);
28-
user.sendMessage(_("teleportTop"));
26+
final Location loc = LocationUtil.getSafeDestination(new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch));
27+
user.getTeleport().teleport(loc, new Trade(this.getName(), ess), TeleportCause.COMMAND);
28+
user.sendMessage(_("teleportTop", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
29+
2930
}
3031
}

Essentials/src/com/earth2me/essentials/commands/Commandtp.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public void run(final Server server, final User user, final String commandLabel,
3636
{
3737
throw new Exception(_("noPerm", "essentials.worlds." + player.getWorld().getName()));
3838
}
39-
user.sendMessage(_("teleporting"));
4039
final Trade charge = new Trade(this.getName(), ess);
4140
charge.isAffordableFor(user);
4241
user.getTeleport().teleport(player.getBase(), charge, TeleportCause.COMMAND);
@@ -54,14 +53,14 @@ public void run(final Server server, final User user, final String commandLabel,
5453
{
5554
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
5655
}
57-
final Location location = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch());
56+
final Location loc = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch());
5857
if (!target2.isTeleportEnabled())
5958
{
6059
throw new Exception(_("teleportDisabled", target2.getDisplayName()));
6160
}
62-
target2.getTeleport().now(location, false, TeleportCause.COMMAND);
63-
user.sendMessage(_("teleporting"));
64-
target2.sendMessage(_("teleporting"));
61+
target2.getTeleport().now(loc, false, TeleportCause.COMMAND);
62+
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
63+
target2.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
6564
break;
6665
case 2:
6766
default:
@@ -85,7 +84,6 @@ public void run(final Server server, final User user, final String commandLabel,
8584
throw new Exception(_("noPerm", "essentials.worlds." + toPlayer.getWorld().getName()));
8685
}
8786
target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND);
88-
user.sendMessage(_("teleporting"));
8987
target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
9088
break;
9189
}
@@ -115,12 +113,14 @@ else if (args.length > 3)
115113
{
116114
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
117115
}
118-
final Location location = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
119-
target.getTeleport().now(location, false, TeleportCause.COMMAND);
120-
target.sendMessage(_("teleporting"));
121-
} else {
116+
final Location loc = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
117+
target.getTeleport().now(loc, false, TeleportCause.COMMAND);
118+
target.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
119+
sender.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
120+
}
121+
else
122+
{
122123
throw new NotEnoughArgumentsException();
123124
}
124-
sender.sendMessage(_("teleporting"));
125125
}
126126
}

Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.earth2me.essentials.I18n._;
44
import com.earth2me.essentials.Trade;
55
import com.earth2me.essentials.User;
6+
import org.bukkit.Location;
67
import org.bukkit.Server;
78
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
89

@@ -59,7 +60,9 @@ public void run(final Server server, final User user, final String commandLabel,
5960
{
6061
if (user.isTpRequestHere())
6162
{
63+
final Location loc = user.getTpRequestLocation();
6264
requester.getTeleport().teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
65+
requester.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
6366
}
6467
else
6568
{
@@ -70,7 +73,7 @@ public void run(final Server server, final User user, final String commandLabel,
7073
{
7174
user.sendMessage(_("pendingTeleportCancelled"));
7275
ess.showError(requester.getSource(), ex, commandLabel);
73-
}
76+
}
7477
user.requestTeleport(null, false);
7578
throw new NoChargeException();
7679
}

Essentials/src/com/earth2me/essentials/commands/Commandtpall.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.earth2me.essentials.CommandSource;
44
import static com.earth2me.essentials.I18n._;
55
import com.earth2me.essentials.User;
6+
import org.bukkit.Location;
67
import org.bukkit.Server;
78
import org.bukkit.entity.Player;
89
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -35,6 +36,7 @@ public void run(final Server server, final CommandSource sender, final String co
3536
private void teleportAllPlayers(Server server, CommandSource sender, User target)
3637
{
3738
sender.sendMessage(_("teleportAll"));
39+
final Location loc = target.getLocation();
3840
for (Player onlinePlayer : server.getOnlinePlayers())
3941
{
4042
final User player = ess.getUser(onlinePlayer);
@@ -50,7 +52,7 @@ private void teleportAllPlayers(Server server, CommandSource sender, User target
5052
}
5153
try
5254
{
53-
player.getTeleport().now(target.getBase(), false, TeleportCause.COMMAND);
55+
player.getTeleport().now(loc, false, TeleportCause.COMMAND);
5456
}
5557
catch (Exception ex)
5658
{

Essentials/src/com/earth2me/essentials/commands/Commandtphere.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public void run(final Server server, final User user, final String commandLabel,
2828
throw new Exception(_("noPerm", "essentials.worlds." + user.getWorld().getName()));
2929
}
3030
user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
31-
user.sendMessage(_("teleporting"));
32-
player.sendMessage(_("teleporting"));
3331
throw new NoChargeException();
3432
}
3533
}

Essentials/src/com/earth2me/essentials/commands/Commandtpo.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void run(final Server server, final User user, final String commandLabel,
2828
{
2929
throw new Exception(_("noPerm", "essentials.worlds." + player.getWorld().getName()));
3030
}
31-
user.sendMessage(_("teleporting"));
3231
user.getTeleport().now(player.getBase(), false, TeleportCause.COMMAND);
3332
break;
3433

@@ -37,7 +36,6 @@ public void run(final Server server, final User user, final String commandLabel,
3736
{
3837
throw new Exception(_("noPerm", "essentials.tp.others"));
3938
}
40-
user.sendMessage(_("teleporting"));
4139
final User target = getPlayer(server, user, args, 0);
4240
final User toPlayer = getPlayer(server, user, args, 1);
4341

Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,5 @@ public void run(final Server server, final User user, final String commandLabel,
3232

3333
// Verify permission
3434
player.getTeleport().now(user.getBase(), false, TeleportCause.COMMAND);
35-
user.sendMessage(_("teleporting"));
36-
3735
}
3836
}

Essentials/src/com/earth2me/essentials/commands/Commandtppos.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ public void run(final Server server, final User user, final String commandLabel,
2727
final double x = args[0].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[0].substring(1)) : Integer.parseInt(args[0]);
2828
final double y = args[1].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
2929
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
30-
final Location location = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
30+
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
3131
if (args.length > 3)
3232
{
33-
location.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
33+
loc.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
3434
}
3535
if (args.length > 4)
3636
{
37-
location.setPitch(Float.parseFloat(args[4]));
37+
loc.setPitch(Float.parseFloat(args[4]));
3838
}
3939
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
4040
{
4141
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
4242
}
4343
final Trade charge = new Trade(this.getName(), ess);
4444
charge.isAffordableFor(user);
45-
user.sendMessage(_("teleporting"));
46-
user.getTeleport().teleport(location, charge, TeleportCause.COMMAND);
45+
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
46+
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
4747
throw new NoChargeException();
4848
}
4949

@@ -59,22 +59,22 @@ public void run(final Server server, final CommandSource sender, final String co
5959
final double x = args[1].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
6060
final double y = args[2].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
6161
final double z = args[3].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
62-
final Location location = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
62+
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
6363
if (args.length > 4)
6464
{
65-
location.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
65+
loc.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
6666
}
6767
if (args.length > 5)
6868
{
69-
location.setPitch(Float.parseFloat(args[5]));
69+
loc.setPitch(Float.parseFloat(args[5]));
7070
}
7171
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
7272
{
7373
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
7474
}
75-
sender.sendMessage(_("teleporting"));
76-
user.sendMessage(_("teleporting"));
77-
user.getTeleport().teleport(location, null, TeleportCause.COMMAND);
75+
sender.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
76+
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
77+
user.getTeleport().teleport(loc, null, TeleportCause.COMMAND);
7878

7979
}
8080
}

0 commit comments

Comments
 (0)